diff --git a/lib/config/shared_pref_kay.dart b/lib/config/shared_pref_kay.dart index e64e7ef4..39e2649d 100644 --- a/lib/config/shared_pref_kay.dart +++ b/lib/config/shared_pref_kay.dart @@ -22,3 +22,5 @@ const MAIN_USER = 'main-user'; const WEATHER = 'weather'; const PHARMACY_LAST_VISITED_PRODUCTS = 'last-visited'; const PHARMACY_CUSTOMER_ID = 'costumer-id'; +const IS_ROBOT_VISIBLE = 'robot-visible'; +const IS_ROBOT_INIT = 'robot-init'; diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index 43d345e0..2773aac3 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -77,10 +77,7 @@ class _LandingPageState extends State with WidgetsBindingObserver { _changeCurrentTab(int tab) { setState(() { currentTab = tab; - if (tab != 0) - pageController.jumpToPage(tab); - else - this.triggerRobot(); + if (tab != 0) pageController.jumpToPage(tab); }); } diff --git a/lib/pages/medical/medical_profile_page.dart b/lib/pages/medical/medical_profile_page.dart index ff2d4587..73e60ce6 100644 --- a/lib/pages/medical/medical_profile_page.dart +++ b/lib/pages/medical/medical_profile_page.dart @@ -65,6 +65,7 @@ class _MedicalProfilePageState extends State { builder: (_, model, widget) => AppScaffold( isShowDecPage: false, baseViewModel: model, + isHelp: true, body: Container( child: SingleChildScrollView( child: Column( diff --git a/lib/widgets/bottom_navigation/bottom_nav_bar.dart b/lib/widgets/bottom_navigation/bottom_nav_bar.dart index 3bc7d0f1..a6b61717 100644 --- a/lib/widgets/bottom_navigation/bottom_nav_bar.dart +++ b/lib/widgets/bottom_navigation/bottom_nav_bar.dart @@ -11,6 +11,8 @@ import 'package:provider/provider.dart'; import '../../d_q_icons_icons.dart'; import 'bottom_navigation_item.dart'; +import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; class BottomNavBar extends StatefulWidget { final ValueChanged changeIndex; @@ -24,7 +26,7 @@ class BottomNavBar extends StatefulWidget { class _BottomNavBarState extends State { int _index = 0; var event = RobotProvider(); - _changeIndex(int index) { + _changeIndex(int index) async { widget.changeIndex(index); if (_index == 0) { event.setValue({'isRobotVisible': 'true'}); diff --git a/lib/widgets/drawer/app_drawer_widget.dart b/lib/widgets/drawer/app_drawer_widget.dart index 9a4e3d1f..379c4cc8 100644 --- a/lib/widgets/drawer/app_drawer_widget.dart +++ b/lib/widgets/drawer/app_drawer_widget.dart @@ -141,9 +141,7 @@ class _AppDrawerState extends State { TranslationBase.of(context).arabicChange, Icons.translate), onTap: () { - // Navigator.of(context).pushNamed( - // WELCOME_LOGIN, - // ); + sharedPref.setBool(IS_ROBOT_INIT, null); if (projectProvider.isArabic) { projectProvider.changeLanguage('en'); } else { diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 228407b5..4f94baa4 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -26,6 +26,8 @@ import '../progress_indicator/app_loader_widget.dart'; import 'arrow_back.dart'; import 'network_base_view.dart'; import 'not_auh_page.dart'; +import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; class AppScaffold extends StatelessWidget { final String appBarTitle; @@ -240,7 +242,7 @@ class RobotIcon extends StatefulWidget { class _RobotIcon extends State { var event = RobotProvider(); - bool isAnimation = true; + bool isAnimation = false; @override void initState() { @@ -253,6 +255,10 @@ class _RobotIcon extends State { }); } }); + + setState(() { + setAnimation(); + }); super.initState(); } @@ -312,4 +318,14 @@ class _RobotIcon extends State { right: -30, bottom: 50); } + + setAnimation() async { + //await sharedPref.getBool(IS_ROBOT_VISIBLE) || + var animation = + await sharedPref.getBool(IS_ROBOT_INIT) == null ? true : false; + + setState(() { + this.isAnimation = animation; + }); + } } diff --git a/lib/widgets/others/floating_button_search.dart b/lib/widgets/others/floating_button_search.dart index f2ffb2d2..b954069f 100644 --- a/lib/widgets/others/floating_button_search.dart +++ b/lib/widgets/others/floating_button_search.dart @@ -101,7 +101,7 @@ class _FloatingSearchButton extends State var sharedPref = new AppSharedPreferences(); bool _hasSpeech = false; ProjectViewModel projectProvider; - bool isAnimationEnable = true; + bool isAnimationEnable = false; AnimationController controller; Animation offset; String networkImage; @@ -111,29 +111,37 @@ class _FloatingSearchButton extends State AnimationController(vsync: this, duration: Duration(seconds: 1)); offset = Tween(begin: Offset.zero, end: Offset(0.0, 1.0)) .animate(controller); - controller.reverse(); initialSpeak(); Future.delayed(const Duration(seconds: 2), () { requestPermissions(); getUserData(); }); - controller.reverse(); + event.controller.stream.listen((p) { if (p['isRobotVisible'] == 'true') { if (this.mounted) { setState(() { + sharedPref.setBool(IS_ROBOT_VISIBLE, true); controller.reverse(); }); } } }); + event.controller.stream.listen((p) { + if (p['startPopUp'] == 'true') { + if (this.mounted) { + new RoboSearch(context: context).showAlertDialog(context); + initSpeechState().then((value) => {startVoiceSearch()}); + } + } + }); super.initState(); } @override void didUpdateWidget(FloatingSearchButton oldWidget) { - // super.didUpdateWidget(oldWidget); + // super.didUpdateWidget(oldWidget); // event.controller.stream.listen((p) { // if (p['animationEnable'] != 'false') { // initialSpeak(); @@ -171,7 +179,6 @@ class _FloatingSearchButton extends State : 'assets/images/gif/robot-idle.gif'), ), onTap: () { - new RoboSearch(context: context).showAlertDialog(context); initSpeechState().then((value) => {startVoiceSearch()}); }, @@ -184,7 +191,7 @@ class _FloatingSearchButton extends State setState(() { if (this.mounted) { controller.forward(); - //isShow = false; + sharedPref.setBool(IS_ROBOT_VISIBLE, false); } }); }, @@ -220,26 +227,14 @@ class _FloatingSearchButton extends State reconizedWord = result.recognizedWords; event.setValue({"searchText": reconizedWord}); if (result.finalResult == true) { - - - - // setState(() { - - // setState(() { - // searchText = reconizedWord; - // }); Future.delayed(const Duration(seconds: 1), () { _speak(reconizedWord); RoboSearch.closeAlertDialog(context); }); } - //}); } Future _speak(reconizedWord) async { - // Navigator.of(AppGlobal.context).pop(); - //await flutterTts.speak(reconizedWord); - //RoboSearch.closeAlertDialog(context); getPages(reconizedWord); } @@ -799,13 +794,15 @@ class _FloatingSearchButton extends State ); } - speak() async { + speak({isInit}) async { setState(() { this.networkImage = results['AnimationURL']; this.isAnimationEnable = true; }); - if (_currentLocaleId == 'en' && results['ReturnMessage'] != null) { + if (Provider.of(context, listen: false).isArabic == + false && + results['ReturnMessage'] != null) { await flutterTts .setVoice({"name": "en-au-x-aub-network", "locale": "en-AU"}); await flutterTts.speak(results['ReturnMessage']); @@ -815,7 +812,7 @@ class _FloatingSearchButton extends State await flutterTts.speak(results['ReturnMessage_Ar']); } - stopAnimation(); + stopAnimation(isInit: isInit); } goToClinic(List ids) { @@ -847,25 +844,32 @@ class _FloatingSearchButton extends State 'ReturnMessage': "Through this service, you will be able to link your family medical files to your medical file so that you can manage their records by login to your medical file." }; - this.speak(); - - if (Provider.of(context, listen: false).isArabic == - false && - results['ReturnMessage'] != null) { - await flutterTts - .setVoice({"name": "en-au-x-aub-network", "locale": "en-AU"}); - await flutterTts.speak(results['ReturnMessage']); - } else if (results['ReturnMessage_Ar'] != null) { - await flutterTts - .setVoice({"name": "ar-xa-x-ard-network", "locale": "ar"}); - await flutterTts.speak(results['ReturnMessage_Ar']); + if (await sharedPref.getBool(IS_ROBOT_INIT) == null) { + this.speak(isInit: true); + controller.reverse(); + } else { + controller.forward(); } + // if (Provider.of(context, listen: false).isArabic == + // false && + // results['ReturnMessage'] != null) { + // await flutterTts + // .setVoice({"name": "en-au-x-aub-network", "locale": "en-AU"}); + // await flutterTts.speak(results['ReturnMessage']); + // } else if (results['ReturnMessage_Ar'] != null) { + // await flutterTts + // .setVoice({"name": "ar-xa-x-ard-network", "locale": "ar"}); + // await flutterTts.speak(results['ReturnMessage_Ar']); + // } - this.isAnimationEnable = true; - stopAnimation(); + //this.isAnimationEnable = true; + //stopAnimation(); } - stopAnimation() { + stopAnimation({isInit}) async { + if (isInit && (await sharedPref.getBool(IS_ROBOT_INIT) == null)) { + sharedPref.setBool(IS_ROBOT_INIT, isInit); + } flutterTts.setCompletionHandler(() => { event.setValue({"animationEnable": 'false'}), setState(() { @@ -946,11 +950,16 @@ class RoboSearch { child: Text(searchText != null && searchText != 'null' ? searchText : 'Try saying something'))), - - // searchText == 'null' ? Center(child:RaisedButton(child: Text('Retry'), onPressed: (){ - // //RoboSearch.closeAlertDialog(context); - // new FloatingSearchButton().createState().startVoiceSearch(); - // }, )) :SizedBox() + searchText == 'null' + ? Center( + child: RaisedButton( + child: Text('Retry'), + onPressed: () { + RoboSearch.closeAlertDialog(context); + event.setValue({'startPopUp': 'true'}); + }, + )) + : SizedBox() ]), )); }),