voice command

merge-update-with-lab-changes
Sultan Khan 5 years ago
parent 188b72bb90
commit 557b8e814f

@ -22,3 +22,5 @@ const MAIN_USER = 'main-user';
const WEATHER = 'weather'; const WEATHER = 'weather';
const PHARMACY_LAST_VISITED_PRODUCTS = 'last-visited'; const PHARMACY_LAST_VISITED_PRODUCTS = 'last-visited';
const PHARMACY_CUSTOMER_ID = 'costumer-id'; const PHARMACY_CUSTOMER_ID = 'costumer-id';
const IS_ROBOT_VISIBLE = 'robot-visible';
const IS_ROBOT_INIT = 'robot-init';

@ -77,10 +77,7 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
_changeCurrentTab(int tab) { _changeCurrentTab(int tab) {
setState(() { setState(() {
currentTab = tab; currentTab = tab;
if (tab != 0) if (tab != 0) pageController.jumpToPage(tab);
pageController.jumpToPage(tab);
else
this.triggerRobot();
}); });
} }

@ -65,6 +65,7 @@ class _MedicalProfilePageState extends State<MedicalProfilePage> {
builder: (_, model, widget) => AppScaffold( builder: (_, model, widget) => AppScaffold(
isShowDecPage: false, isShowDecPage: false,
baseViewModel: model, baseViewModel: model,
isHelp: true,
body: Container( body: Container(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(

@ -11,6 +11,8 @@ import 'package:provider/provider.dart';
import '../../d_q_icons_icons.dart'; import '../../d_q_icons_icons.dart';
import 'bottom_navigation_item.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 { class BottomNavBar extends StatefulWidget {
final ValueChanged<int> changeIndex; final ValueChanged<int> changeIndex;
@ -24,7 +26,7 @@ class BottomNavBar extends StatefulWidget {
class _BottomNavBarState extends State<BottomNavBar> { class _BottomNavBarState extends State<BottomNavBar> {
int _index = 0; int _index = 0;
var event = RobotProvider(); var event = RobotProvider();
_changeIndex(int index) { _changeIndex(int index) async {
widget.changeIndex(index); widget.changeIndex(index);
if (_index == 0) { if (_index == 0) {
event.setValue({'isRobotVisible': 'true'}); event.setValue({'isRobotVisible': 'true'});

@ -141,9 +141,7 @@ class _AppDrawerState extends State<AppDrawer> {
TranslationBase.of(context).arabicChange, TranslationBase.of(context).arabicChange,
Icons.translate), Icons.translate),
onTap: () { onTap: () {
// Navigator.of(context).pushNamed( sharedPref.setBool(IS_ROBOT_INIT, null);
// WELCOME_LOGIN,
// );
if (projectProvider.isArabic) { if (projectProvider.isArabic) {
projectProvider.changeLanguage('en'); projectProvider.changeLanguage('en');
} else { } else {

@ -26,6 +26,8 @@ import '../progress_indicator/app_loader_widget.dart';
import 'arrow_back.dart'; import 'arrow_back.dart';
import 'network_base_view.dart'; import 'network_base_view.dart';
import 'not_auh_page.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 { class AppScaffold extends StatelessWidget {
final String appBarTitle; final String appBarTitle;
@ -240,7 +242,7 @@ class RobotIcon extends StatefulWidget {
class _RobotIcon extends State<RobotIcon> { class _RobotIcon extends State<RobotIcon> {
var event = RobotProvider(); var event = RobotProvider();
bool isAnimation = true; bool isAnimation = false;
@override @override
void initState() { void initState() {
@ -253,6 +255,10 @@ class _RobotIcon extends State<RobotIcon> {
}); });
} }
}); });
setState(() {
setAnimation();
});
super.initState(); super.initState();
} }
@ -312,4 +318,14 @@ class _RobotIcon extends State<RobotIcon> {
right: -30, right: -30,
bottom: 50); 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;
});
}
} }

@ -101,7 +101,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
var sharedPref = new AppSharedPreferences(); var sharedPref = new AppSharedPreferences();
bool _hasSpeech = false; bool _hasSpeech = false;
ProjectViewModel projectProvider; ProjectViewModel projectProvider;
bool isAnimationEnable = true; bool isAnimationEnable = false;
AnimationController controller; AnimationController controller;
Animation<Offset> offset; Animation<Offset> offset;
String networkImage; String networkImage;
@ -111,29 +111,37 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
AnimationController(vsync: this, duration: Duration(seconds: 1)); AnimationController(vsync: this, duration: Duration(seconds: 1));
offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0)) offset = Tween<Offset>(begin: Offset.zero, end: Offset(0.0, 1.0))
.animate(controller); .animate(controller);
controller.reverse();
initialSpeak(); initialSpeak();
Future.delayed(const Duration(seconds: 2), () { Future.delayed(const Duration(seconds: 2), () {
requestPermissions(); requestPermissions();
getUserData(); getUserData();
}); });
controller.reverse();
event.controller.stream.listen((p) { event.controller.stream.listen((p) {
if (p['isRobotVisible'] == 'true') { if (p['isRobotVisible'] == 'true') {
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
sharedPref.setBool(IS_ROBOT_VISIBLE, true);
controller.reverse(); 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(); super.initState();
} }
@override @override
void didUpdateWidget(FloatingSearchButton oldWidget) { void didUpdateWidget(FloatingSearchButton oldWidget) {
// super.didUpdateWidget(oldWidget); // super.didUpdateWidget(oldWidget);
// event.controller.stream.listen((p) { // event.controller.stream.listen((p) {
// if (p['animationEnable'] != 'false') { // if (p['animationEnable'] != 'false') {
// initialSpeak(); // initialSpeak();
@ -171,7 +179,6 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
: 'assets/images/gif/robot-idle.gif'), : 'assets/images/gif/robot-idle.gif'),
), ),
onTap: () { onTap: () {
new RoboSearch(context: context).showAlertDialog(context); new RoboSearch(context: context).showAlertDialog(context);
initSpeechState().then((value) => {startVoiceSearch()}); initSpeechState().then((value) => {startVoiceSearch()});
}, },
@ -184,7 +191,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
setState(() { setState(() {
if (this.mounted) { if (this.mounted) {
controller.forward(); controller.forward();
//isShow = false; sharedPref.setBool(IS_ROBOT_VISIBLE, false);
} }
}); });
}, },
@ -220,26 +227,14 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
reconizedWord = result.recognizedWords; reconizedWord = result.recognizedWords;
event.setValue({"searchText": reconizedWord}); event.setValue({"searchText": reconizedWord});
if (result.finalResult == true) { if (result.finalResult == true) {
// setState(() {
// setState(() {
// searchText = reconizedWord;
// });
Future.delayed(const Duration(seconds: 1), () { Future.delayed(const Duration(seconds: 1), () {
_speak(reconizedWord); _speak(reconizedWord);
RoboSearch.closeAlertDialog(context); RoboSearch.closeAlertDialog(context);
}); });
} }
//});
} }
Future _speak(reconizedWord) async { Future _speak(reconizedWord) async {
// Navigator.of(AppGlobal.context).pop();
//await flutterTts.speak(reconizedWord);
//RoboSearch.closeAlertDialog(context);
getPages(reconizedWord); getPages(reconizedWord);
} }
@ -799,13 +794,15 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
); );
} }
speak() async { speak({isInit}) async {
setState(() { setState(() {
this.networkImage = results['AnimationURL']; this.networkImage = results['AnimationURL'];
this.isAnimationEnable = true; this.isAnimationEnable = true;
}); });
if (_currentLocaleId == 'en' && results['ReturnMessage'] != null) { if (Provider.of<ProjectViewModel>(context, listen: false).isArabic ==
false &&
results['ReturnMessage'] != null) {
await flutterTts await flutterTts
.setVoice({"name": "en-au-x-aub-network", "locale": "en-AU"}); .setVoice({"name": "en-au-x-aub-network", "locale": "en-AU"});
await flutterTts.speak(results['ReturnMessage']); await flutterTts.speak(results['ReturnMessage']);
@ -815,7 +812,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
await flutterTts.speak(results['ReturnMessage_Ar']); await flutterTts.speak(results['ReturnMessage_Ar']);
} }
stopAnimation(); stopAnimation(isInit: isInit);
} }
goToClinic(List ids) { goToClinic(List ids) {
@ -847,25 +844,32 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
'ReturnMessage': '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." "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 (await sharedPref.getBool(IS_ROBOT_INIT) == null) {
this.speak(isInit: true);
if (Provider.of<ProjectViewModel>(context, listen: false).isArabic == controller.reverse();
false && } else {
results['ReturnMessage'] != null) { controller.forward();
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 (Provider.of<ProjectViewModel>(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; //this.isAnimationEnable = true;
stopAnimation(); //stopAnimation();
} }
stopAnimation() { stopAnimation({isInit}) async {
if (isInit && (await sharedPref.getBool(IS_ROBOT_INIT) == null)) {
sharedPref.setBool(IS_ROBOT_INIT, isInit);
}
flutterTts.setCompletionHandler(() => { flutterTts.setCompletionHandler(() => {
event.setValue({"animationEnable": 'false'}), event.setValue({"animationEnable": 'false'}),
setState(() { setState(() {
@ -946,11 +950,16 @@ class RoboSearch {
child: Text(searchText != null && searchText != 'null' child: Text(searchText != null && searchText != 'null'
? searchText ? searchText
: 'Try saying something'))), : 'Try saying something'))),
searchText == 'null'
// searchText == 'null' ? Center(child:RaisedButton(child: Text('Retry'), onPressed: (){ ? Center(
// //RoboSearch.closeAlertDialog(context); child: RaisedButton(
// new FloatingSearchButton().createState().startVoiceSearch(); child: Text('Retry'),
// }, )) :SizedBox() onPressed: () {
RoboSearch.closeAlertDialog(context);
event.setValue({'startPopUp': 'true'});
},
))
: SizedBox()
]), ]),
)); ));
}), }),

Loading…
Cancel
Save