voice command changes

merge-requests/251/head
Sultan Khan 5 years ago
parent d33918c932
commit b3e6c4efda

@ -94,6 +94,6 @@ dependencies {
implementation 'com.github.kittinunf.fuel:fuel:2.3.0' //for JVM implementation 'com.github.kittinunf.fuel:fuel:2.3.0' //for JVM
implementation 'com.github.kittinunf.fuel:fuel-android:2.3.0' implementation 'com.github.kittinunf.fuel:fuel-android:2.3.0'
implementation 'com.google.android.gms:play-services-location:17.1.0'//for Android implementation 'com.google.android.gms:play-services-location:17.1.0'//for Android
implementation 'com.google.android.gms:play-services-basement:17.5.0'
} }

@ -289,7 +289,7 @@ const GET_PATIENT_HEALTH_STATS =
const CHANNEL = 3; const CHANNEL = 3;
const GENERAL_ID = 'Cs2020@2016\$2958'; const GENERAL_ID = 'Cs2020@2016\$2958';
const IP_ADDRESS = '10.20.10.20'; const IP_ADDRESS = '10.20.10.20';
const VERSION_ID = 5.8; const VERSION_ID = 8.4;
const SETUP_ID = '91877'; const SETUP_ID = '91877';
const LANGUAGE = 2; const LANGUAGE = 2;
const PATIENT_OUT_SA = 0; const PATIENT_OUT_SA = 0;
@ -298,6 +298,8 @@ const IS_DENTAL_ALLOWED_BACKEND = false;
const PATIENT_TYPE = 1; const PATIENT_TYPE = 1;
const PATIENT_TYPE_ID = 1; const PATIENT_TYPE_ID = 1;
var DEVICE_TOKEN = ""; var DEVICE_TOKEN = "";
var IS_VOICE_COMMAND_CLOSED = false;
var IS_TEXT_COMPLETED = false;
var DeviceTypeID = Platform.isIOS ? 1 : 2; var DeviceTypeID = Platform.isIOS ? 1 : 2;
const LANGUAGE_ID = 1; const LANGUAGE_ID = 1;
const GET_PHARMCY_ITEMS = "Services/Lists.svc/REST/GetPharmcyItems_Region"; const GET_PHARMCY_ITEMS = "Services/Lists.svc/REST/GetPharmcyItems_Region";

@ -1784,5 +1784,6 @@ const Map localizedValues = {
"en": "Select the preferred unit", "en": "Select the preferred unit",
"ar": "اختر الوحدة المفضلة" "ar": "اختر الوحدة المفضلة"
}, },
"select-unit": {"en": "Select unit", "ar": "اختر وحدة القياس"} "select-unit": {"en": "Select unit", "ar": "اختر وحدة القياس"},
"try-saying": {"en": "Try saying something", "ar": 'حاول قول شيء ما'}
}; };

@ -86,7 +86,12 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
_changeCurrentTab(int tab) { _changeCurrentTab(int tab) {
setState(() { setState(() {
currentTab = tab; currentTab = tab;
if (tab != 0) pageController.jumpToPage(tab); if (tab != 0)
pageController.jumpToPage(tab);
else {
IS_VOICE_COMMAND_CLOSED = false;
pageController.jumpToPage(tab);
}
}); });
} }
@ -627,7 +632,7 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
authService authService
.selectDeviceImei(token) .selectDeviceImei(token)
.then((SelectDeviceIMEIRES value) => setUserValues(value)); .then((SelectDeviceIMEIRES value) => setUserValues(value));
if (await sharedPref.getObject(USER_PROFILE) != null) { if (projectViewModel.isLoading == true) {
var data = var data =
AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
if (data != null) { if (data != null) {
@ -636,9 +641,11 @@ class _LandingPageState extends State<LandingPage> with WidgetsBindingObserver {
.then((res) => {print(res)}); .then((res) => {print(res)});
authService.getDashboard().then((value) => { authService.getDashboard().then((value) => {
setState(() { setState(() {
notificationCount = value['List_PatientDashboard'][0] if (value != null) {
['UnreadPatientNotificationCount'] notificationCount = value['List_PatientDashboard'][0]
.toString(); ['UnreadPatientNotificationCount']
.toString();
}
}) })
}); });
} }

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

@ -20,10 +20,10 @@ class _GeneralSettings extends State<GeneralSettings>
with TickerProviderStateMixin { with TickerProviderStateMixin {
var themeNotifier; var themeNotifier;
int blindValue = 0; int blindValue = 0;
bool vibration =false; bool vibration = false;
bool accsibility =false; bool accsibility = false;
bool camera =false; bool camera = false;
bool location =false; bool location = false;
var sharedPref = new AppSharedPreferences(); var sharedPref = new AppSharedPreferences();
var permission = new PermissionService(); var permission = new PermissionService();
var mediaQueryData; var mediaQueryData;
@ -33,10 +33,9 @@ class _GeneralSettings extends State<GeneralSettings>
super.initState(); super.initState();
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
mediaQueryData = MediaQuery.of(context); mediaQueryData = MediaQuery.of(context);
themeNotifier = Provider.of<ThemeNotifier>(context); themeNotifier = Provider.of<ThemeNotifier>(context);
return Container( return Container(
child: ListView(scrollDirection: Axis.vertical, children: <Widget>[ child: ListView(scrollDirection: Axis.vertical, children: <Widget>[
Container( Container(
@ -59,7 +58,6 @@ class _GeneralSettings extends State<GeneralSettings>
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
vibration = value; vibration = value;
}); });
setVibration(value); setVibration(value);
}, },
@ -81,7 +79,7 @@ class _GeneralSettings extends State<GeneralSettings>
setState(() { setState(() {
accsibility = value; accsibility = value;
}); });
//setAccisibility(value); //setAccisibility(value);
}, },
activeTrackColor: Colors.lightGreenAccent, activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green, activeColor: Colors.green,
@ -228,7 +226,7 @@ class _GeneralSettings extends State<GeneralSettings>
])); ]));
} }
setTheme(value) async{ setTheme(value) async {
switch (value) { switch (value) {
case 0: case 0:
{ {
@ -239,7 +237,7 @@ class _GeneralSettings extends State<GeneralSettings>
case 1: case 1:
{ {
themeNotifier.setTheme(ThemeData( themeNotifier.setTheme(ThemeData(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans', //fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans',
primarySwatch: Colors.grey, primarySwatch: Colors.grey,
visualDensity: VisualDensity.adaptivePlatformDensity, visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light, brightness: Brightness.light,
@ -262,7 +260,8 @@ class _GeneralSettings extends State<GeneralSettings>
highlightColor: Colors.grey[100].withOpacity(0.4), highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent, splashColor: Colors.transparent,
primaryColor: Colors.grey, primaryColor: Colors.grey,
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)), bottomSheetTheme:
BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey, cursorColor: Colors.grey,
iconTheme: IconThemeData(), iconTheme: IconThemeData(),
@ -296,139 +295,142 @@ class _GeneralSettings extends State<GeneralSettings>
break; break;
} }
//permission.setTheme(value); //permission.setTheme(value);
} }
setVibration(value){
setVibration(value) {
permission.setVibrationPermission(value); permission.setVibrationPermission(value);
} }
setAccisibility(){ setAccisibility() {
if(!accsibility){ if (!accsibility) {}
// permission.setVibrationPermission(value);
}
// permission.setVibrationPermission(value);
} }
getValues() async{
blindValue= permission.isThemeEnabled() == null ? 0 : permission.isThemeEnabled();
vibration = permission.isVibrationEnabled() ==null ? false : permission.isVibrationEnabled();
accsibility =mediaQueryData.accessibleNavigation;
}
getTheme(value) async{
if(value ==1){
return ThemeData(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans',
primarySwatch: Colors.grey,
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
cardColor: Colors.black,
buttonColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Colors.grey,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.grey,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Colors.grey,
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Colors.grey,
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Colors.grey,
),
),
);
}else if(value ==3){ getValues() async {
return ThemeData( blindValue =
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans', permission.isThemeEnabled() == null ? 0 : permission.isThemeEnabled();
primarySwatch: Colors.grey, vibration = permission.isVibrationEnabled() == null
visualDensity: VisualDensity.adaptivePlatformDensity, ? false
brightness: Brightness.light, : permission.isVibrationEnabled();
pageTransitionsTheme: const PageTransitionsTheme( accsibility = mediaQueryData.accessibleNavigation;
builders: { }
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
cardColor: Colors.black,
buttonColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Colors.grey,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.grey,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Colors.grey,
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
iconTheme: IconThemeData(), getTheme(value) async {
appBarTheme: AppBarTheme( if (value == 1) {
color: Colors.black45, return ThemeData(
brightness: Brightness.dark, // fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans',
elevation: 10.0, primarySwatch: Colors.grey,
actionsIconTheme: IconThemeData( visualDensity: VisualDensity.adaptivePlatformDensity,
color: Colors.grey, brightness: Brightness.light,
), pageTransitionsTheme: const PageTransitionsTheme(
), builders: {
); TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
cardColor: Colors.black,
buttonColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Colors.grey,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.grey,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Colors.grey,
bottomSheetTheme:
BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
}else { iconTheme: IconThemeData(),
return ThemeData( appBarTheme: AppBarTheme(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans', color: Colors.grey,
primarySwatch: Colors.blue, brightness: Brightness.dark,
visualDensity: VisualDensity.adaptivePlatformDensity, elevation: 10.0,
brightness: Brightness.light, actionsIconTheme: IconThemeData(
pageTransitionsTheme: const PageTransitionsTheme( color: Colors.grey,
builders: { ),
TargetPlatform.android: ZoomPageTransitionsBuilder(), ),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), );
}, } else if (value == 3) {
), return ThemeData(
hintColor: Colors.grey[400], // fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans',
disabledColor: Colors.grey[300], primarySwatch: Colors.grey,
errorColor: Color.fromRGBO(235, 80, 60, 1.0), visualDensity: VisualDensity.adaptivePlatformDensity,
scaffoldBackgroundColor: Color(0xffEEEEEE), brightness: Brightness.light,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5), pageTransitionsTheme: const PageTransitionsTheme(
textSelectionHandleColor: Colors.grey, builders: {
canvasColor: Colors.white, TargetPlatform.android: ZoomPageTransitionsBuilder(),
backgroundColor: Colors.white, TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
highlightColor: Colors.grey[100].withOpacity(0.4), },
splashColor: Colors.transparent, ),
primaryColor: Color(0xff40ACC9), hintColor: Colors.grey[400],
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)), cardColor: Colors.black,
cursorColor: Colors.grey, buttonColor: Colors.grey[400],
cardColor: Colors.white, disabledColor: Colors.grey[300],
iconTheme: IconThemeData(), errorColor: Color.fromRGBO(235, 80, 60, 1.0),
appBarTheme: AppBarTheme( scaffoldBackgroundColor: Colors.grey,
color: Color(0xff40ACC9), textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
brightness: Brightness.dark, textSelectionHandleColor: Colors.grey,
elevation: 10.0, canvasColor: Colors.white,
actionsIconTheme: IconThemeData( backgroundColor: Colors.grey,
color: Color(0xff40ACC9), highlightColor: Colors.grey[100].withOpacity(0.4),
), splashColor: Colors.transparent,
), primaryColor: Colors.grey,
); bottomSheetTheme:
BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
} iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Colors.black45,
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Colors.grey,
),
),
);
} else {
return ThemeData(
//fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans',
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Color(0xffEEEEEE),
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.white,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Color(0xff40ACC9),
bottomSheetTheme:
BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
cardColor: Colors.white,
iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Color(0xff40ACC9),
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Color(0xff40ACC9),
),
),
);
}
} }
} }

@ -31,15 +31,14 @@ class _SplashScreenState extends State<SplashScreen> {
super.initState(); super.initState();
Timer( Timer(
Duration(seconds: 1, milliseconds: 500), Duration(seconds: 1, milliseconds: 500),
() { () {
loadPrivilege().then((value) { loadPrivilege().then((value) {
Navigator.of(context).pushReplacement( Navigator.of(context).pushReplacement(
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => LandingPage(), builder: (BuildContext context) => LandingPage(),
), ),
); );
}); });
}, },
); );
} }
@ -47,14 +46,19 @@ class _SplashScreenState extends State<SplashScreen> {
/// load the Privilege from service /// load the Privilege from service
Future loadPrivilege() async { Future loadPrivilege() async {
await _privilegeService.getPrivilege(); await _privilegeService.getPrivilege();
Provider.of<ProjectViewModel>(context, listen: false).setPrivilegeModelList(privilege: _privilegeService.privilegeModelList); Provider.of<ProjectViewModel>(context, listen: false)
.setPrivilegeModelList(privilege: _privilegeService.privilegeModelList);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
body: Image.asset('assets/images/powerd-by.jpg',fit: BoxFit.fitWidth,width: MediaQuery.of(context).size.width,), body: Image.asset(
'assets/images/powerd-by.jpg',
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
),
); );
} }
} }

@ -1468,6 +1468,7 @@ class TranslationBase {
String get areyousure => localizedValues["areyousure"][locale.languageCode]; String get areyousure => localizedValues["areyousure"][locale.languageCode];
String get preferredunit => String get preferredunit =>
localizedValues["preferredunit"][locale.languageCode]; localizedValues["preferredunit"][locale.languageCode];
String get trySaying => localizedValues["try-saying"][locale.languageCode];
} }
class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> { class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> {

@ -51,7 +51,6 @@ class AppScaffold extends StatelessWidget {
final List<Widget> appBarIcons; final List<Widget> appBarIcons;
final List<ImagesInfo> imagesInfo; final List<ImagesInfo> imagesInfo;
final bool isHelp; final bool isHelp;
bool isAnimation = false;
AuthenticatedUserObject authenticatedUserObject = AuthenticatedUserObject authenticatedUserObject =
locator<AuthenticatedUserObject>(); locator<AuthenticatedUserObject>();
@ -206,17 +205,20 @@ class _RobotIcon extends State<RobotIcon> {
void initState() { void initState() {
event.controller.stream.listen((p) { event.controller.stream.listen((p) {
if (p['animationEnable'] == 'false') { if (p['animationEnable'] == 'false') {
//setState(() { if (this.mounted) {
// if (this.mounted) { setState(() {
this.isAnimation = false; this.isAnimation = false;
//} });
// }); }
} else if (p['animationEnable'] == 'true') {
if (this.mounted) {
setState(() {
this.isAnimation = true;
});
}
} }
}); });
setState(() {
setAnimation();
});
super.initState(); super.initState();
} }
@ -277,13 +279,10 @@ class _RobotIcon extends State<RobotIcon> {
bottom: 50); bottom: 50);
} }
setAnimation() async { // setAnimation() async {
//await sharedPref.getBool(IS_ROBOT_VISIBLE) || // /// await sharedPref.getBool(IS_ROBOT_VISIBLE) ||
var animation = // // var animation =
await sharedPref.getBool(IS_ROBOT_INIT) == null ? true : false; // // IS_TEXT_COMPLETED == ? true : false;
setState(() { // }
this.isAnimation = animation;
});
}
} }

@ -59,8 +59,7 @@ import 'package:flutter_tts/flutter_tts.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:speech_to_text/speech_recognition_error.dart'; import 'package:speech_to_text/speech_recognition_error.dart';
import 'package:speech_to_text/speech_recognition_result.dart'; import 'package:speech_to_text/speech_to_text.dart' as stt;
import 'package:speech_to_text/speech_to_text.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/DoctorProfile.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/DoctorProfile.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/Search.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/Search.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -82,7 +81,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
RobotProvider eventProvider = RobotProvider(); RobotProvider eventProvider = RobotProvider();
bool isLoading = false; bool isLoading = false;
bool isError = false; bool isError = false;
final SpeechToText speech = SpeechToText(); stt.SpeechToText speech = stt.SpeechToText();
String error = ''; String error = '';
String _currentLocaleId = ""; String _currentLocaleId = "";
String lastError; String lastError;
@ -102,28 +101,40 @@ 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 = false; bool isAnimationEnable = true;
AnimationController controller; AnimationController controller;
Animation<Offset> offset; Animation<Offset> offset;
String networkImage; String networkImage;
bool isArabic;
@override @override
void initState() { void initState() {
controller = controller =
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(0.0, 1.0), end: Offset(0.0, 0.0))
.animate(controller); .animate(controller);
initialSpeak(); if (IS_VOICE_COMMAND_CLOSED == true) {
Future.delayed(const Duration(seconds: 2), () { controller.reverse(from: -1);
}
if (mounted) {
//Future.delayed(const Duration(seconds: 2), () {
isArabic = Provider.of<ProjectViewModel>(context, listen: false).isArabic;
requestPermissions(); requestPermissions();
getUserData(); getUserData();
}); initialSpeak();
setState(() {
if (IS_TEXT_COMPLETED) {
isAnimationEnable = false;
}
});
}
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); if (IS_VOICE_COMMAND_CLOSED == false) {
controller.reverse(); controller.forward();
}
}); });
} }
} }
@ -141,21 +152,25 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
} }
@override @override
void didUpdateWidget(FloatingSearchButton oldWidget) { void dispose() {
// super.didUpdateWidget(oldWidget); controller.dispose();
// event.controller.stream.listen((p) { super.dispose();
// if (p['animationEnable'] != 'false') {
// initialSpeak();
// }
// });
} }
// @override
// void didUpdateWidget(FloatingSearchButton oldWidget) {
// // super.didUpdateWidget(oldWidget);
// // event.controller.stream.listen((p) {
// // if (p['animationEnable'] != 'false') {
// // initialSpeak();
// // }
// // });
// }
AuthenticatedUserObject authenticatedUserObject = AuthenticatedUserObject authenticatedUserObject =
locator<AuthenticatedUserObject>(); locator<AuthenticatedUserObject>();
VitalSignService _vitalSignService = locator<VitalSignService>(); VitalSignService _vitalSignService = locator<VitalSignService>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
projectProvider = Provider.of(context);
return Container( return Container(
child: SlideTransition(position: offset, child: getStack())); child: SlideTransition(position: offset, child: getStack()));
} }
@ -180,7 +195,6 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
: 'assets/images/gif/robot-idle.gif'), : 'assets/images/gif/robot-idle.gif'),
), ),
onTap: () { onTap: () {
RoboSearch.isClosed = false;
new RoboSearch(context: context).showAlertDialog(context); new RoboSearch(context: context).showAlertDialog(context);
initSpeechState().then((value) => {startVoiceSearch()}); initSpeechState().then((value) => {startVoiceSearch()});
}, },
@ -192,8 +206,8 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
onTap: () { onTap: () {
setState(() { setState(() {
if (this.mounted) { if (this.mounted) {
controller.forward(); controller.reverse();
sharedPref.setBool(IS_ROBOT_VISIBLE, false); IS_VOICE_COMMAND_CLOSED = true;
} }
}); });
}, },
@ -213,25 +227,38 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
startVoiceSearch() async { startVoiceSearch() async {
_currentLocaleId = _currentLocaleId =
TranslationBase.of(AppGlobal.context).locale.languageCode; TranslationBase.of(AppGlobal.context).locale.languageCode;
speech.listen( bool available = await speech.initialize(
onStatus: statusListener, onError: errorListener);
if (available) {
speech.listen(
onResult: resultListener, onResult: resultListener,
listenFor: Duration(seconds: 10), // listenMode: ListenMode.confirmation,
localeId: _currentLocaleId == 'en' ? 'en-US' : 'ar-SA', localeId: _currentLocaleId == 'en' ? 'en-US' : 'ar-SA',
onSoundLevelChange: soundLevelListener, );
cancelOnError: true, } else {
partialResults: true, print("The user has denied the use of speech recognition.");
onDevice: true, }
listenMode: ListenMode.deviceDefault); // some time later...
//speech.stop();
// speech.listen(
// onResult: resultListener,
// listenFor: Duration(seconds: 10),
// localeId: _currentLocaleId == 'en' ? 'en-US' : 'ar-SA',
// onSoundLevelChange: soundLevelListener,
// cancelOnError: true,
// partialResults: true,
// onDevice: true,
// listenMode: ListenMode.deviceDefault);
} }
void resultListener(SpeechRecognitionResult result) { void resultListener(result) {
// lastWords = "${result.recognizedWords} - ${result.finalResult}";
reconizedWord = result.recognizedWords; reconizedWord = result.recognizedWords;
event.setValue({"searchText": reconizedWord}); event.setValue({"searchText": reconizedWord});
if (result.finalResult == true) { if (result.finalResult == true) {
Future.delayed(const Duration(seconds: 1), () { Future.delayed(const Duration(seconds: 1), () {
_speak(reconizedWord); _speak(reconizedWord);
RoboSearch.closeAlertDialog(context); RoboSearch.closeAlertDialog(context);
//Navigator.of(context).pop();
}); });
} }
} }
@ -250,9 +277,12 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
} }
void requestPermissions() async { void requestPermissions() async {
Map<Permission, PermissionStatus> statuses = await [ if (await Permission.microphone.isDenied ||
Permission.microphone, await Permission.microphone.isUndetermined) {
].request(); Map<Permission, PermissionStatus> statuses = await [
Permission.microphone,
].request();
}
} }
Future<void> initSpeechState() async { Future<void> initSpeechState() async {
@ -274,9 +304,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
void errorListener(SpeechRecognitionError error) { void errorListener(SpeechRecognitionError error) {
event.setValue({"searchText": 'null'}); event.setValue({"searchText": 'null'});
//setState(() { RoboSearch.closeAlertDialog(context);
// reconizedWord = "${error.errorMsg} - ${error.permanent}";
//});
} }
void statusListener(String status) { void statusListener(String status) {
@ -298,9 +326,7 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
} }
getCommands(result) async { getCommands(result) async {
print(result);
results = result; results = result;
switch (result["CommandNumber"]) { switch (result["CommandNumber"]) {
case '100': case '100':
{ {
@ -797,14 +823,16 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
} }
speak({isInit}) async { speak({isInit}) async {
//if (mounted) {
setState(() { setState(() {
this.networkImage = results['AnimationURL']; this.networkImage = results['AnimationURL'];
this.isAnimationEnable = true; this.isAnimationEnable = true;
}); });
//}
if (Provider.of<ProjectViewModel>(context, listen: false).isArabic == if (isInit == true) {
false && event.setValue({"animationEnable": 'true'});
results['ReturnMessage'] != null) { }
if (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']);
@ -840,45 +868,33 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
} }
initialSpeak() async { initialSpeak() async {
await flutterTts.awaitSpeakCompletion(true);
results = { results = {
'ReturnMessage_Ar': 'ReturnMessage_Ar':
"هذه الخدمة تم تصميمها لتتمكن من ربط الملفات الطبية للعائلة بملفك الطبي حتى تتمكن من إدارة سجلاتهم عن طريق تسجيل الدخول إلى ملفك الطبي.", "هذه الخدمة تم تصميمها لتتمكن من ربط الملفات الطبية للعائلة بملفك الطبي حتى تتمكن من إدارة سجلاتهم عن طريق تسجيل الدخول إلى ملفك الطبي.",
'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."
}; };
if (await sharedPref.getBool(IS_ROBOT_INIT) == null) { if (IS_VOICE_COMMAND_CLOSED == false) {
this.speak(isInit: true); if (IS_TEXT_COMPLETED == false) {
controller.reverse(); this.speak(isInit: true);
} else { }
controller.forward(); 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();
} }
stopAnimation({isInit}) async { stopAnimation({isInit}) async {
if (isInit && (await sharedPref.getBool(IS_ROBOT_INIT) == null)) { if (isInit == true) {
sharedPref.setBool(IS_ROBOT_INIT, isInit); IS_TEXT_COMPLETED = true;
} }
flutterTts.setCompletionHandler(() => { flutterTts.setCompletionHandler(() async {
event.setValue({"animationEnable": 'false'}), event.setValue({"animationEnable": 'false'});
setState(() { setState(() {
this.networkImage = null; this.networkImage = null;
this.isAnimationEnable = false; this.isAnimationEnable = false;
}) });
}); });
} }
signOut() async { signOut() async {
@ -895,91 +911,131 @@ class _FloatingSearchButton extends State<FloatingSearchButton>
class RoboSearch { class RoboSearch {
final BuildContext context; final BuildContext context;
var event = RobotProvider(); static var dialog;
var searchText;
static StreamSubscription<dynamic> streamSubscription;
static var isClosed = false;
RoboSearch({ RoboSearch({
@required this.context, @required this.context,
}); });
showAlertDialog(BuildContext context) { showAlertDialog(BuildContext context) {
AlertDialog alert = AlertDialog( //AlertDialog alert = AlertDialog
content: StatefulBuilder( // AlertDialog alert = AlertDialog(content: MyStatefulBuilder(dispose: () {
builder: (BuildContext context, StateSetter setState) { // print('dispose!!!!!!!!!!!!');
streamSubscription = event.controller.stream.listen((p) { // })
if (p['searchText'] != 'null' && // isClosed = true;
p['searchText'] != null && // streamSubscription.cancel();
p['searchText'] != "" && // }, builder: (BuildContext context, StateSetter setState) {
isClosed == false) { // //print(streamSubscription);
setState(() { // }),
searchText = p['searchText']; // );
});
}
});
print(streamSubscription);
return Container(
color: Colors.white,
height: SizeConfig.realScreenHeight * 0.5,
width: SizeConfig.realScreenWidth * 0.8,
child: Container(
child: Column(children: [
Expanded(
flex: 1,
child: Center(
child: Image.asset(
'assets/images/habib-logo.png',
height: 75,
width: 75,
))),
Expanded(
flex: 3,
child: Center(
child: Container(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(width: 2, color: Colors.red)),
child: Icon(
Icons.mic,
color: Colors.blue,
size: 48,
),
))),
Expanded(
flex: 1,
child: Center(
child: Text(searchText != null && searchText != 'null'
? searchText
: 'Try saying something'))),
searchText == 'null'
? Center(
child: RaisedButton(
child: Text('Retry'),
onPressed: () {
RoboSearch.closeAlertDialog(context);
event.setValue({'startPopUp': 'true'});
},
))
: SizedBox()
]),
));
}),
);
// show the dialog // show the dialog
showDialog( showDialog(
context: context, context: context,
barrierDismissible: true,
builder: (BuildContext context) { builder: (BuildContext context) {
return alert; dialog = context;
return MyStatefulBuilder(
dispose: () {},
);
}, },
).then((value) => {}); );
print(dialog);
} }
static closeAlertDialog(BuildContext context) { static closeAlertDialog(BuildContext context) {
isClosed = true; Navigator.of(dialog).pop();
streamSubscription.cancel(); }
Navigator.of(context).pop(); }
typedef Disposer = void Function();
class MyStatefulBuilder extends StatefulWidget {
const MyStatefulBuilder({
// @required this.builder,
@required this.dispose,
});
//final StatefulWidgetBuilder builder;
final Disposer dispose;
@override
_MyStatefulBuilderState createState() => _MyStatefulBuilderState();
}
class _MyStatefulBuilderState extends State<MyStatefulBuilder> {
var event = RobotProvider();
var searchText;
static StreamSubscription<dynamic> streamSubscription;
static var isClosed = false;
@override
void initState() {
streamSubscription = event.controller.stream.listen((p) {
if ((p['searchText'] != 'null' &&
p['searchText'] != null &&
p['searchText'] != "" &&
isClosed == false) &&
mounted) {
setState(() {
searchText = p['searchText'];
});
}
});
super.initState();
}
@override
Widget build(BuildContext context) => AlertDialog(
content: Container(
color: Colors.white,
height: SizeConfig.realScreenHeight * 0.5,
width: SizeConfig.realScreenWidth * 0.8,
child: Container(
child: Column(children: [
Expanded(
flex: 1,
child: Center(
child: Image.asset(
'assets/images/habib-logo.png',
height: 75,
width: 75,
))),
Expanded(
flex: 3,
child: Center(
child: Container(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(width: 2, color: Colors.red)),
child: Icon(
Icons.mic,
color: Colors.blue,
size: 48,
),
))),
Expanded(
flex: 1,
child: Center(
child: Text(searchText != null && searchText != 'null'
? searchText
: TranslationBase.of(context).trySaying))),
searchText == 'null'
? Center(
child: RaisedButton(
child: Text('Retry'),
onPressed: () {
RoboSearch.closeAlertDialog(context);
event.setValue({'startPopUp': 'true'});
},
))
: SizedBox()
]),
)));
@override
void dispose() {
super.dispose();
widget.dispose();
} }
} }

@ -15,7 +15,7 @@ class _TyperState extends State<TyperAnimatedTextKit>
int _stringIndex; int _stringIndex;
@override @override
void initState() { void initState() {
_controller = new AnimationController( _controller = new AnimationController(
duration: const Duration(seconds: 7), duration: const Duration(seconds: 7),
vsync: this, vsync: this,
); );
@ -24,8 +24,8 @@ class _TyperState extends State<TyperAnimatedTextKit>
setState(() { setState(() {
_stringIndex = _stringIndex == null ? 0 : _stringIndex + 1; _stringIndex = _stringIndex == null ? 0 : _stringIndex + 1;
_characterCount = new StepTween(begin: 0, end: widget.textLength) _characterCount = new StepTween(begin: 0, end: widget.textLength)
.animate(new CurvedAnimation(parent: _controller, curve: Curves.easeIn)); .animate(
new CurvedAnimation(parent: _controller, curve: Curves.easeIn));
}); });
_controller.forward(); _controller.forward();
}); });
@ -43,9 +43,8 @@ class _TyperState extends State<TyperAnimatedTextKit>
setState(() { setState(() {
_stringIndex = _stringIndex == null ? 0 : _stringIndex + 1; _stringIndex = _stringIndex == null ? 0 : _stringIndex + 1;
_characterCount = new StepTween(begin: 0, end: widget.textLength) _characterCount = new StepTween(begin: 0, end: widget.textLength).animate(
.animate(new CurvedAnimation(parent: _controller, curve: Curves.easeIn)); new CurvedAnimation(parent: _controller, curve: Curves.easeIn));
}); });
_controller.forward(); _controller.forward();
} }
@ -55,18 +54,22 @@ class _TyperState extends State<TyperAnimatedTextKit>
_controller.dispose(); _controller.dispose();
super.dispose(); super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container(
return Container( child: _characterCount == null
child: _characterCount == null ? null : new AnimatedBuilder( ? null
animation: _characterCount, : new AnimatedBuilder(
builder: (BuildContext context, Widget child) { animation: _characterCount,
String text = widget.text.substring(0, _characterCount.value); builder: (BuildContext context, Widget child) {
return Text(text, style: TextStyle(color:Colors.black, fontSize: 12), textAlign: TextAlign.start, String text = widget.text.substring(0, _characterCount.value);
return Text(
); text,
}, style: TextStyle(color: Colors.black, fontSize: 12),
)); textAlign: TextAlign.start,
);
},
));
} }
} }

@ -21,7 +21,7 @@ dependencies:
# http client # http client
http: ^0.12.1 http: ^0.12.1
connectivity: ^0.4.9+3 connectivity: ^0.4.9+3
audio_wave: ^0.0.3
# State Management # State Management
provider: ^4.3.2+2 provider: ^4.3.2+2

Loading…
Cancel
Save