From bd3e48674b664ea11a45930a1f6cb6f943f63954 Mon Sep 17 00:00:00 2001 From: jaivsh Date: Wed, 9 Aug 2023 11:24:28 +0530 Subject: [PATCH] Added change language option dialog --- lib/main.dart | 25 ++--- lib/screens/home_screen.dart | 113 +++++--------------- lib/screens/settings_screen.dart | 176 +++++++++++++------------------ lib/widgets/build_classes.dart | 2 +- lib/widgets/recents_alerts.dart | 2 +- 5 files changed, 114 insertions(+), 204 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2d59da4410..7e7054288e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -51,6 +51,7 @@ class _MyAppState extends State { bool isFirstRun = false; int backButtonPressCounter = 0; + @override void initState() { super.initState(); @@ -131,10 +132,6 @@ class _MyAppState extends State { GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], - locale: Locale('hi'), - - - locale: Locale('en'), supportedLocales: [ Locale('ru'), @@ -156,16 +153,16 @@ class _MyAppState extends State { if (snapshot.connectionState == ConnectionState.waiting) { return SplashScreen(key: UniqueKey()); } else { - if (isFirstRun) { - return OnBoardingPage(); - } else { - WidgetsBinding.instance.addPostFrameCallback( - (_) => showRatingDialog(context), - ); - return AuthenticationService.handleEntryPoint(context); - - } - ), + if (isFirstRun) { + return OnBoardingPage(); + } else { + WidgetsBinding.instance.addPostFrameCallback( + (_) => showRatingDialog(context), + ); + return AuthenticationService.handleEntryPoint(context); + + }}} + ), routes: { '/feedback': (context) => FeedbackPage(), '/settings': (context) => SettingsScreen(), diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index d159e272de..7e33ee7a52 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -95,42 +95,38 @@ class _HomeScreenState extends State with WidgetsBindingObserver { children: [ Header(), - - - - Padding( - padding: EdgeInsets.symmetric(horizontal: 30.0), - child: GestureDetector( - onTap: () { - showSearch( - context: context, - delegate: DataSearch(), - ); - }, - child: TextField( - enabled: false, - style: TextStyle(color: kTextColor), - cursorColor: kTextColor, - decoration: InputDecoration( - contentPadding: EdgeInsets.all(8.0), - border: InputBorder.none, - fillColor: Theme.of(context).primaryColor, - filled: true, - hintText: AppLocalizations.of(context).search, - hintStyle: TextStyle(color: kTextColor), - prefixIcon: Icon(Icons.search, color: kTextColor, size: 26.0), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(30.0), - ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(30.0), - borderSide: BorderSide(width: 1, color: Colors.grey.shade600), - + Padding( + padding: EdgeInsets.symmetric(horizontal: 30.0), + child: GestureDetector( + onTap: () { + showSearch( + context: context, + delegate: DataSearch(), + ); + }, + child: TextField( + enabled: false, + style: TextStyle(color: kTextColor), + cursorColor: kTextColor, + decoration: InputDecoration( + contentPadding: EdgeInsets.all(8.0), + border: InputBorder.none, + fillColor: Theme.of(context).primaryColor, + filled: true, + hintText: AppLocalizations.of(context).search, + hintStyle: TextStyle(color: kTextColor), + prefixIcon: Icon(Icons.search, color: kTextColor, size: 26.0), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30.0), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(30.0), + borderSide: BorderSide(width: 1, color: Colors.grey.shade600), + ), ), ), ), ), - SizedBox(height: 10,), Center(child: TextButton(onPressed: () { Navigator.of(context).push(MaterialPageRoute(builder: (context) => FavouritesScreen())); @@ -154,59 +150,6 @@ class _HomeScreenState extends State with WidgetsBindingObserver { color: Colors.white, fontSize: 20.0, fontWeight: FontWeight.bold, - - ), - SizedBox(height: 10,), - Center(child: TextButton(onPressed: () { - Navigator.of(context).push(MaterialPageRoute(builder: (context) => FavouritesScreen())); - },child: Text( AppLocalizations.of(context).seefavourites, style: TextStyle(color: Theme.of(context).colorScheme.secondary),),),), - SizedBox(height: 15.0), - Container( - padding: EdgeInsets.all(35.0), - decoration: BoxDecoration( - color: Theme.of(context).primaryColor, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(50.0), - topRight: Radius.circular(50.0), - ), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - AppLocalizations.of(context).recentalerts, - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(height: 30.0), - RecentsAlerts(), - Center( - child: Text( - AppLocalizations.of(context).viewall, - style: TextStyle( - color: Theme.of(context).colorScheme.secondary, - fontSize: 15.0), - ), - ), - SizedBox(height: 20.0), - Text( - AppLocalizations.of(context).recenthomework, - style: TextStyle( - color: Colors.white, - fontSize: 20.0, - fontWeight: FontWeight.bold, - ), - ), - SizedBox(height: 30.0), - RecentHomeworks(), - Center( - child: TextButton( - style: TextButton.styleFrom( - padding: EdgeInsets.all(0), - ), ), SizedBox(height: 30.0), diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index c150e6e363..28d01df3db 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; +import 'package:friday/main.dart'; import 'package:friday/screens/faqs_screen.dart'; import 'package:friday/screens/help_screen.dart'; import 'package:friday/screens/themes.dart'; @@ -14,6 +15,32 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:shared_preferences/shared_preferences.dart'; +class MyApps extends StatefulWidget { + @override + _MyAppState createState() => _MyAppState(); + + static _MyAppState? of(BuildContext context) => context.findAncestorStateOfType<_MyAppState>(); +} + +class _MyAppState extends State { + late Locale _locale; + + void setLocale(Locale value) { + setState(() { + _locale = value; + }); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + locale: _locale, + home: MyApp(), + ); + } +} + + class SettingsScreen extends StatefulWidget { @override State createState() => _SettingsScreenState(); @@ -109,111 +136,52 @@ class _SettingsScreenState extends State { topRight: Radius.circular(40), ), ), + width: double.infinity, + child: - ), - width: double.infinity, - child: - - SizedBox(height: MediaQuery.of(context).size.height ,width: MediaQuery.of(context).size.width,child:SettingsList( - lightTheme: SettingsThemeData(settingsListBackground: Theme.of(context).primaryColor, titleTextColor: Theme.of(context).secondaryHeaderColor, - settingsTileTextColor: Colors.white, leadingIconsColor: Colors.white, dividerColor: Colors.white70, tileDescriptionTextColor: Theme.of(context).primaryColorDark) - - ,sections: [ - SettingsSection( - - title: Text(AppLocalizations.of(context).common), - tiles: [ - SettingsTile.navigation( - leading: Icon(Icons.language), - onPressed: (c) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text("Currently support is for Single language only. Stay tuned!"), - )); - }, - title: Text(AppLocalizations.of(context).language), - value: Text('English'), - ), - SettingsTile.switchTile(initialValue: ThemeMode.system == ThemeMode.light ? !modeval : modeval, onToggle: (s) { - setState(() { - modeval = s; - }); - if(modeval) { - setState(() { - _setTheme(lightTheme); - }); - } - else { - setState(() { - _setTheme(darkTheme); - }); - } - - }, title: Text(AppLocalizations.of(context).lightmode), enabled: true, leading: Icon(Icons.light_mode),), - - SettingsTile.navigation( - leading: Icon(Icons.notifications_active_outlined), - title: Text(AppLocalizations.of(context).notifications), - onPressed: (s) async { - - NotificationService().showNotification(title: 'olalalaaa', body: 'it works'); - - //if(notification!){ - //await FlutterLocalNotificationsPlugin().cancelAll(); - //ScaffoldMessenger.of(context).showSnackBar(SnackBar( - // content: Text("Notifications turned off!"), - //)); - //} - //else { - //notificationsInitialize(); - //ScaffoldMessenger.of(context).showSnackBar(SnackBar( - // content: Text("Notifications turned on!"), - //)); - //} - - - - //notificationsInitialize(); - }, - value: Text(AppLocalizations.of(context).notificationsdesc), - ), - - SettingsTile.navigation( - leading: Icon(Icons.help_outline), - title: Text(AppLocalizations.of(context).help), - onPressed: (s) { - Navigator.of(context).push(MaterialPageRoute(builder: (context) => HelpScreen())); - }, - value: Text(AppLocalizations.of(context).helpdesc), - ), - - - SettingsTile.navigation( - leading: Icon(Icons.info_outlined), - title: Text(AppLocalizations.of(context).faqs), - value: Text(AppLocalizations.of(context).faqsdesc), - onPressed: (s) { - Navigator.of(context).push(MaterialPageRoute(builder: (context) => FAQScreen())); - }, - ), - SettingsTile.navigation( - leading: Icon(Icons.support), - title: Text(AppLocalizations.of(context).supportdevelopment), - onPressed: (s) async { - //js.context.callMethod('open', ['https://github.com/avinashkranjan/Friday']); - final result = await openUrl('https://github.com/avinashkranjan/Friday'); - if (result.exitCode == 0) { - print('URL opened!'); - } else { - print('Something went wrong (exit code = ${result.exitCode}): ' - '${result.stderr}'); - } - - }, - value: Text(AppLocalizations.of(context).supportdevelopmentdesc), - ), - - ], + SizedBox(height: MediaQuery.of(context).size.height ,width: MediaQuery.of(context).size.width,child:SettingsList( + lightTheme: SettingsThemeData(settingsListBackground: Theme.of(context).primaryColor, titleTextColor: Theme.of(context).secondaryHeaderColor, + settingsTileTextColor: Colors.white, leadingIconsColor: Colors.white, dividerColor: Colors.white70, tileDescriptionTextColor: Theme.of(context).primaryColorDark) + ,sections: [ + SettingsSection( + title: Text(AppLocalizations.of(context).common), + tiles: [ + SettingsTile.navigation( + leading: Icon(Icons.language), + onPressed: (c) { + var languages = ['English','Russian','Hindi']; + showDialog(context: context, builder: (BuildContext context) { + return new AlertDialog( + backgroundColor: Colors.black, + actions: [TextButton(onPressed: () { + Navigator.pop(context); + }, child: Text('OK', style: TextStyle(color: Colors.deepPurpleAccent),))], + title: new Text('Select a Language', style: TextStyle(color: Colors.deepPurpleAccent),), + content: Container(height:200, width: MediaQuery.of(context).size.width ,child:ListView.builder( + itemCount: languages.length, + itemBuilder: (context, index) { + return ListTile( + title: Text(languages[index],style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),), + onTap: () { + if(index == 0) { + MyApps.of(context)!.setLocale(Locale.fromSubtags(languageCode: 'en')); + } + else if(index == 1) { + MyApps.of(context)!.setLocale(Locale.fromSubtags(languageCode: 'hi')); + } + else if(index == 2) { + MyApps.of(context)!.setLocale(Locale.fromSubtags(languageCode: 'ru')); + } + }, + ); + }, + ), + )); + }); + }, + title: Text(AppLocalizations.of(context).language), + value: Text('English'), ), SettingsTile.switchTile(initialValue: ThemeMode.system == ThemeMode.light ? !modeval : modeval, onToggle: (s) { setState(() { @@ -237,6 +205,8 @@ class _SettingsScreenState extends State { title: Text(AppLocalizations.of(context).notifications), onPressed: (s) async { + NotificationService().showNotification(title: 'olalalaaa', body: 'it works'); + //if(notification!){ //await FlutterLocalNotificationsPlugin().cancelAll(); //ScaffoldMessenger.of(context).showSnackBar(SnackBar( diff --git a/lib/widgets/build_classes.dart b/lib/widgets/build_classes.dart index e5334c8f91..0b73abc631 100644 --- a/lib/widgets/build_classes.dart +++ b/lib/widgets/build_classes.dart @@ -173,7 +173,7 @@ class _BuildClassesState extends State { ), ), - ), + classesList != null && classesList.isNotEmpty ? Padding( diff --git a/lib/widgets/recents_alerts.dart b/lib/widgets/recents_alerts.dart index e894a49607..ff411c3b4f 100644 --- a/lib/widgets/recents_alerts.dart +++ b/lib/widgets/recents_alerts.dart @@ -230,5 +230,5 @@ class _RecentsAlertsState extends State with WidgetsBindingObserv } } -} +