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 PHARMACY_LAST_VISITED_PRODUCTS = 'last-visited';
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) {
setState(() {
currentTab = tab;
if (tab != 0)
pageController.jumpToPage(tab);
else
this.triggerRobot();
if (tab != 0) pageController.jumpToPage(tab);
});
}

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

@ -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<int> changeIndex;
@ -24,7 +26,7 @@ class BottomNavBar extends StatefulWidget {
class _BottomNavBarState extends State<BottomNavBar> {
int _index = 0;
var event = RobotProvider();
_changeIndex(int index) {
_changeIndex(int index) async {
widget.changeIndex(index);
if (_index == 0) {
event.setValue({'isRobotVisible': 'true'});

@ -141,9 +141,7 @@ class _AppDrawerState extends State<AppDrawer> {
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 {

@ -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<RobotIcon> {
var event = RobotProvider();
bool isAnimation = true;
bool isAnimation = false;
@override
void initState() {
@ -253,6 +255,10 @@ class _RobotIcon extends State<RobotIcon> {
});
}
});
setState(() {
setAnimation();
});
super.initState();
}
@ -312,4 +318,14 @@ class _RobotIcon extends State<RobotIcon> {
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;
});
}
}

@ -101,7 +101,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
var sharedPref = new AppSharedPreferences();
bool _hasSpeech = false;
ProjectViewModel projectProvider;
bool isAnimationEnable = true;
bool isAnimationEnable = false;
AnimationController controller;
Animation<Offset> offset;
String networkImage;
@ -111,29 +111,37 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
AnimationController(vsync: this, duration: Duration(seconds: 1));
offset = Tween<Offset>(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<FloatingSearchButton>
: '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<FloatingSearchButton>
setState(() {
if (this.mounted) {
controller.forward();
//isShow = false;
sharedPref.setBool(IS_ROBOT_VISIBLE, false);
}
});
},
@ -220,26 +227,14 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
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<FloatingSearchButton>
);
}
speak() async {
speak({isInit}) async {
setState(() {
this.networkImage = results['AnimationURL'];
this.isAnimationEnable = true;
});
if (_currentLocaleId == 'en' && results['ReturnMessage'] != null) {
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']);
@ -815,7 +812,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
await flutterTts.speak(results['ReturnMessage_Ar']);
}
stopAnimation();
stopAnimation(isInit: isInit);
}
goToClinic(List ids) {
@ -847,25 +844,32 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
'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<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']);
if (await sharedPref.getBool(IS_ROBOT_INIT) == null) {
this.speak(isInit: true);
controller.reverse();
} else {
controller.forward();
}
// 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;
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()
]),
));
}),

Loading…
Cancel
Save