From a3e01ff9387ad8a61ce9d14f4fd078e2f6fa8df3 Mon Sep 17 00:00:00 2001 From: Sultan Khan Date: Fri, 4 Dec 2020 12:12:52 +0300 Subject: [PATCH] flutter tts --- lib/pages/DrawerPages/family/my-family.dart | 398 +++++++++--------- .../others/floating_button_search.dart | 18 +- 2 files changed, 218 insertions(+), 198 deletions(-) diff --git a/lib/pages/DrawerPages/family/my-family.dart b/lib/pages/DrawerPages/family/my-family.dart index 80de8ecd..57632c46 100644 --- a/lib/pages/DrawerPages/family/my-family.dart +++ b/lib/pages/DrawerPages/family/my-family.dart @@ -7,7 +7,8 @@ import 'package:diplomaticquarterapp/core/viewModels/appointment_rate_view_model import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/locator.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; -import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart' as list; +import 'package:diplomaticquarterapp/models/Authentication/check_activation_code_response.dart' + as list; import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart'; import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/BranchView.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; @@ -29,9 +30,10 @@ import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/routes.dart'; import 'package:provider/provider.dart'; + class MyFamily extends StatefulWidget { final bool isAppbarVisible; - MyFamily({this.isAppbarVisible =true}); + MyFamily({this.isAppbarVisible = true}); @override _MyFamily createState() => _MyFamily(); } @@ -44,9 +46,9 @@ class _MyFamily extends State with TickerProviderStateMixin { TabController _tabController; int _tabIndex = 0; AuthenticatedUserObject authenticatedUserObject = - locator(); + locator(); AppointmentRateViewModel appointmentRateViewModel = - locator(); + locator(); ProjectViewModel projectViewModel; AuthenticatedUser user; @override @@ -59,118 +61,118 @@ class _MyFamily extends State with TickerProviderStateMixin { bool expandFlag = false; Widget build(BuildContext context) { - imagesInfo.add(ImagesInfo( - imageEn: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png', - imageAr: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'), + imagesInfo.add( + ImagesInfo( + imageEn: + 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/0.png', + imageAr: + 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/0.png'), ); - imagesInfo.add(ImagesInfo( - imageEn: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png', - imageAr: - 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'), + imagesInfo.add( + ImagesInfo( + imageEn: + 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/en/1.png', + imageAr: + 'https://hmgwebservices.com/Images/MobileApp/images-info-home/family-file/ar/1.png'), ); projectViewModel = Provider.of(context); - return AppScaffold( - appBarTitle: TranslationBase.of(context).myFamilyFiles, - isShowAppBar: widget.isAppbarVisible, - imagesInfo: imagesInfo, + return AppScaffold( + appBarTitle: TranslationBase.of(context).myFamilyFiles, + isShowAppBar: widget.isAppbarVisible, + // imagesInfo: imagesInfo, description: TranslationBase.of(context).familyInfo, - body: Scaffold( - extendBodyBehindAppBar: true, - appBar: PreferredSize( - preferredSize: Size.fromHeight(65.0), - child: Stack( - children: [ - Positioned( - bottom: 1, - left: 0, - right: 0, - child: BackdropFilter( - filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), - child: Container( - color: Theme.of(context) - .scaffoldBackgroundColor - .withOpacity(0.8), - height: 70.0, - ), + body: Scaffold( + extendBodyBehindAppBar: true, + appBar: PreferredSize( + preferredSize: Size.fromHeight(65.0), + child: Stack( + children: [ + Positioned( + bottom: 1, + left: 0, + right: 0, + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10), + child: Container( + color: Theme.of(context) + .scaffoldBackgroundColor + .withOpacity(0.8), + height: 70.0, ), ), - Center( - child: Container( - height: 60.0, - margin: EdgeInsets.only(top: 10.0), - width: MediaQuery.of(context).size.width * 0.92, // 0.9, - decoration: BoxDecoration( - border: Border( - bottom: BorderSide( - color: Theme.of(context).dividerColor, - width: 0.9), //width: 0.7 - ), - color: Colors.white), - child: Center( - child: TabBar( - isScrollable: true, - controller: _tabController, - indicatorWeight: 5.0, - //indicatorSize: TabBarIndicatorSize.label, - indicatorSize: TabBarIndicatorSize.tab, - - indicatorColor: Theme.of(context).primaryColor, - labelColor: Theme.of(context).primaryColor, - labelPadding: - EdgeInsets.only(top: 4.0, left: 35.0, right: 35.0), - unselectedLabelColor: Colors.grey[800], - tabs: [ + ), + Center( + child: Container( + height: 60.0, + margin: EdgeInsets.only(top: 10.0), + width: MediaQuery.of(context).size.width * 0.92, // 0.9, + decoration: BoxDecoration( + border: Border( + bottom: BorderSide( + color: Theme.of(context).dividerColor, + width: 0.9), //width: 0.7 + ), + color: Colors.white), + child: Center( + child: TabBar( + isScrollable: true, + controller: _tabController, + indicatorWeight: 5.0, + //indicatorSize: TabBarIndicatorSize.label, + indicatorSize: TabBarIndicatorSize.tab, - Container( - width: MediaQuery.of(context).size.width * 0.30, - child: Center( - child: AppText(TranslationBase.of(context).family), - ), + indicatorColor: Theme.of(context).primaryColor, + labelColor: Theme.of(context).primaryColor, + labelPadding: + EdgeInsets.only(top: 4.0, left: 35.0, right: 35.0), + unselectedLabelColor: Colors.grey[800], + tabs: [ + Container( + width: MediaQuery.of(context).size.width * 0.30, + child: Center( + child: AppText(TranslationBase.of(context).family), ), - Container( - width: MediaQuery.of(context).size.width * 0.30, - child: Center( - child: AppText(TranslationBase.of(context).request), - ), + ), + Container( + width: MediaQuery.of(context).size.width * 0.30, + child: Center( + child: AppText(TranslationBase.of(context).request), ), - ], - ), + ), + ], ), ), ), - ], - ), - ), - body: Column( - children: [ - Expanded( - child: (user != null && projectViewModel.isLogin) ? TabBarView( - physics: BouncingScrollPhysics(), - controller: _tabController, - children: [ - myFamilyDetails(context), - myFamilyRequest(context) - ], - ) : Container(child:AppText('Loading..')), - ) + ), ], ), ), - ); - - - + body: Column( + children: [ + Expanded( + child: (user != null && projectViewModel.isLogin) + ? TabBarView( + physics: BouncingScrollPhysics(), + controller: _tabController, + children: [ + myFamilyDetails(context), + myFamilyRequest(context) + ], + ) + : Container(child: AppText('Loading..')), + ) + ], + ), + ), + ); return AppScaffold( appBarTitle: TranslationBase.of(context).myFamilyFiles, isShowAppBar: widget.isAppbarVisible, body: SingleChildScrollView( child: Container( - height: SizeConfig.screenHeight *.9, + height: SizeConfig.screenHeight * .9, width: SizeConfig.realScreenWidth, padding: EdgeInsets.all(20), child: Stack( @@ -179,11 +181,13 @@ class _MyFamily extends State with TickerProviderStateMixin { controller: _tabController, indicatorColor: Colors.red, tabs: [ - Tab( // padding: EdgeInsets.all(6), - child:AppText(TranslationBase.of(context).family)), Tab( // padding: EdgeInsets.all(6), - child:AppText(TranslationBase.of(context).request)), + child: AppText(TranslationBase.of(context).family)), + Tab( + // padding: EdgeInsets.all(6), + child: + AppText(TranslationBase.of(context).request)), ], ), TabBarView( @@ -317,13 +321,13 @@ class _MyFamily extends State with TickerProviderStateMixin { Widget myFamilyRequest(context) { return //Padding( - // padding: const EdgeInsets.symmetric(horizontal: 10.0), - // child: - SingleChildScrollView( - child: Container( + // padding: const EdgeInsets.symmetric(horizontal: 10.0), + // child: + SingleChildScrollView( + child: Container( height: MediaQuery.of(context).size.height, - margin: EdgeInsets.only(top:65), - child: Column( + margin: EdgeInsets.only(top: 65), + child: Column( children: [ RoundedContainer( child: ExpansionTile( @@ -375,13 +379,21 @@ class _MyFamily extends State with TickerProviderStateMixin { // )), Column(children: [ Padding( - padding: EdgeInsets.only(left:10, right:10), child:Row(children: [ - Expanded(flex: 3, child: AppText('Name')), - Expanded(flex: 1, child: AppText('Allow')), - Expanded(flex: 1, child: AppText('Reject')), - ])), + padding: EdgeInsets.only( + left: 10, right: 10), + child: Row(children: [ + Expanded( + flex: 3, child: AppText('Name')), + Expanded( + flex: 1, child: AppText('Allow')), + Expanded( + flex: 1, + child: AppText('Reject')), + ])), Column( - children:familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList + children: familyFileProvider + .allSharedRecordsByStatusResponse + .getAllSharedRecordsByStatusList .map((result) { return Padding( padding: EdgeInsets.all(10), @@ -400,7 +412,9 @@ class _MyFamily extends State with TickerProviderStateMixin { ), onPressed: () { acceptRemoveRequest( - result.iD, 3, context); + result.iD, + 3, + context); }, )), Expanded( @@ -412,7 +426,9 @@ class _MyFamily extends State with TickerProviderStateMixin { ), onPressed: () { acceptRemoveRequest( - result.iD,4, context); + result.iD, + 4, + context); }, )) ], @@ -462,13 +478,15 @@ class _MyFamily extends State with TickerProviderStateMixin { children: [ Expanded( flex: 3, - child: - Text(result.patientName)), + child: Text( + result.patientName)), Expanded( flex: 2, child: AppText( result.statusDescription, - color: result.status==3 ? Colors.green: Colors.red, + color: result.status == 3 + ? Colors.green + : Colors.red, )), ], )); @@ -487,8 +505,8 @@ class _MyFamily extends State with TickerProviderStateMixin { children: [ FutureBuilder( future: getUserViewRequest(), // async work - builder: - (BuildContext context, AsyncSnapshot snapshot) { + builder: (BuildContext context, + AsyncSnapshot snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: return Padding( @@ -502,38 +520,43 @@ class _MyFamily extends State with TickerProviderStateMixin { else return Column( children: [ - // Padding( - // padding:EdgeInsets.only(left:10, right:10), - // child: Row( - // mainAxisAlignment: - // MainAxisAlignment.spaceBetween, - // children: [ - // Expanded( - // flex: 3, - // child: AppText( - // TranslationBase.of(context).request), - // ), - // Expanded( - // flex: 2, - // child: AppText( - // TranslationBase.of(context).switchUser, - // )), - // Expanded( - // flex: 1, - // child: AppText( - // TranslationBase.of(context).deleteView, - // )), - // ], - // )), + // Padding( + // padding:EdgeInsets.only(left:10, right:10), + // child: Row( + // mainAxisAlignment: + // MainAxisAlignment.spaceBetween, + // children: [ + // Expanded( + // flex: 3, + // child: AppText( + // TranslationBase.of(context).request), + // ), + // Expanded( + // flex: 2, + // child: AppText( + // TranslationBase.of(context).switchUser, + // )), + // Expanded( + // flex: 1, + // child: AppText( + // TranslationBase.of(context).deleteView, + // )), + // ], + // )), Column(children: [ - Padding( - padding:EdgeInsets.only(left:10, right:10), - child: Row(children: [ - Expanded(flex: 3, child: AppText('Name')), - Expanded(flex: 1, child: AppText('Delete')), - ])), + Padding( + padding: + EdgeInsets.only(left: 10, right: 10), + child: Row(children: [ + Expanded( + flex: 3, child: AppText('Name')), + Expanded( + flex: 1, child: AppText('Delete')), + ])), Column( - children: familyFileProvider.allSharedRecordsByStatusResponse.getAllSharedRecordsByStatusList + children: familyFileProvider + .allSharedRecordsByStatusResponse + .getAllSharedRecordsByStatusList .map((result) { return Padding( padding: EdgeInsets.all(10), @@ -541,7 +564,8 @@ class _MyFamily extends State with TickerProviderStateMixin { children: [ Expanded( flex: 3, - child: AppText(result.patientName)), + child: AppText( + result.patientName)), Expanded( flex: 1, child: IconButton( @@ -550,8 +574,8 @@ class _MyFamily extends State with TickerProviderStateMixin { color: Colors.black, ), onPressed: () { - deactivateRequest(result.iD, - 5, context); + deactivateRequest( + result.iD, 5, context); }, )), ], @@ -625,17 +649,17 @@ class _MyFamily extends State with TickerProviderStateMixin { } switchUser(user, context) { - GifLoaderDialogUtils.showMyDialog(context); + GifLoaderDialogUtils.showMyDialog(context); // this // .familyFileProvider // .silentLoggin(user) // .then((value) => loginAfter(value, context)); - // Utils.showProgressDialog(context); + // Utils.showProgressDialog(context); this .familyFileProvider .silentLoggin(user is AuthenticatedUser ? null : user, - mainUser: user is AuthenticatedUser) + mainUser: user is AuthenticatedUser) .then((value) => loginAfter(value, context)) .catchError((err) { print(err); @@ -644,26 +668,26 @@ class _MyFamily extends State with TickerProviderStateMixin { }); } - loginAfter(result, context) async{ + loginAfter(result, context) async { GifLoaderDialogUtils.hideDialog(context); - // var familyFile = await sharedPref.getObject(FAMILY_FILE); - // var mainUser = await sharedPref.getObject(MAIN_USER); - // result = CheckActivationCode.fromJson(result); - // this.sharedPref.clear(); - // this.sharedPref.setObject(FAMILY_FILE, familyFile); - // this.sharedPref.setObject(MAIN_USER, mainUser); - // result.list.isFamily = true; - // this.sharedPref.setObject(USER_PROFILE, result.list); - // this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); - // this.sharedPref.setString(TOKEN, result.authenticationTokenID); - // - // authenticatedUserObject.isLogin = true; - // appointmentRateViewModel.isLogin = true; - // projectViewModel.isLogin = true; - // //this.checkIfUserAgreedBefore(result), - // Navigator.of(context).pushNamed( - // HOME, - // ); + // var familyFile = await sharedPref.getObject(FAMILY_FILE); + // var mainUser = await sharedPref.getObject(MAIN_USER); + // result = CheckActivationCode.fromJson(result); + // this.sharedPref.clear(); + // this.sharedPref.setObject(FAMILY_FILE, familyFile); + // this.sharedPref.setObject(MAIN_USER, mainUser); + // result.list.isFamily = true; + // this.sharedPref.setObject(USER_PROFILE, result.list); + // this.sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID); + // this.sharedPref.setString(TOKEN, result.authenticationTokenID); + // + // authenticatedUserObject.isLogin = true; + // appointmentRateViewModel.isLogin = true; + // projectViewModel.isLogin = true; + // //this.checkIfUserAgreedBefore(result), + // Navigator.of(context).pushNamed( + // HOME, + // ); result = list.CheckActivationCode.fromJson(result); var familyFile = await sharedPref.getObject(FAMILY_FILE); var mainUser = await sharedPref.getObject(MAIN_USER); @@ -687,32 +711,30 @@ class _MyFamily extends State with TickerProviderStateMixin { Map request = {}; request["ID"] = ID; request["Status"] = status; - this.familyFileProvider.deactivateFamily(request).then((value) => { - GifLoaderDialogUtils.hideDialog(context), - refreshFamily(context) - }); + this.familyFileProvider.deactivateFamily(request).then((value) => + {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); } + acceptRemoveRequest(ID, status, context) { GifLoaderDialogUtils.showMyDialog(context); Map request = {}; request["ID"] = ID; request["Status"] = status; - this.familyFileProvider.acceptRejectFamily(request).then((value) => { - GifLoaderDialogUtils.hideDialog(context), - refreshFamily(context) - }); + this.familyFileProvider.acceptRejectFamily(request).then((value) => + {GifLoaderDialogUtils.hideDialog(context), refreshFamily(context)}); } - checkUserData() async{ + + checkUserData() async { if (await this.sharedPref.getObject(USER_PROFILE) != null) { - var data = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(USER_PROFILE)); + var data = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(USER_PROFILE)); - var data2 = AuthenticatedUser.fromJson( - await this.sharedPref.getObject(MAIN_USER)); - print(data2); - setState(() { - this.user = data; - }); + var data2 = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(MAIN_USER)); + print(data2); + setState(() { + this.user = data; + }); } } } diff --git a/lib/widgets/others/floating_button_search.dart b/lib/widgets/others/floating_button_search.dart index e8900040..b6f7e89d 100644 --- a/lib/widgets/others/floating_button_search.dart +++ b/lib/widgets/others/floating_button_search.dart @@ -107,7 +107,6 @@ class _FloatingSearchButton extends State // }); Future.delayed(const Duration(seconds: 2), () { - requestPermissions(); getUserData(); @@ -119,9 +118,8 @@ class _FloatingSearchButton extends State @override Widget build(BuildContext context) { projectProvider = Provider.of(context); - return Container(child: - isShow ? getStack() - : Stack(children: [Container()])); + return Container( + child: isShow ? getStack() : Stack(children: [Container()])); } Widget getStack() { @@ -134,7 +132,7 @@ class _FloatingSearchButton extends State // mainAxisSize: MainAxisSize.min, // crossAxisAlignment: CrossAxisAlignment.stretch, // children: [ - GestureDetector( + GestureDetector( child: Container( child: Image.asset('assets/images/gif/robot-idle.gif'), ), @@ -151,7 +149,7 @@ class _FloatingSearchButton extends State onTap: () { setState(() { if (this.mounted) { - isShow =false; + isShow = false; } }); }, @@ -780,14 +778,14 @@ class _FloatingSearchButton extends State speak() async { var voice = await flutterTts.getVoices; + await flutterTts.setVoice({"name": "es-us-x-sfb-local", "locale": "es-US"}); print(voice); if (_currentLocaleId == 'en' && results['ReturnMessage'] != null) { - await flutterTts.setVoice("en-us-x-sfg#male_1-local" ); - await flutterTts.setLanguage("en-US"); + //await flutterTts.setLanguage("en-US"); await flutterTts.speak(results['ReturnMessage']); } else if (results['ReturnMessage_Ar'] != null) { await flutterTts.setLanguage("ar-SA"); - await flutterTts.setVoice("ar-xa-x-arc-local"); + // await flutterTts.setVoice("ar-xa-x-arc-local"); await flutterTts.speak(results['ReturnMessage_Ar']); } // Future.delayed(const Duration(seconds: 10), () { @@ -815,6 +813,6 @@ class _FloatingSearchButton extends State user = AuthenticatedUser.fromJson( await this.sharedPref.getObject(USER_PROFILE)); } - await flutterTts.setVoice("en-us-x-sfg#male_1-local" ); + //await flutterTts.setVoice("en-us-x-sfg#male_1-local"); } }