Skip to content

Commit

Permalink
Merge pull request #403 from jaivsh/master
Browse files Browse the repository at this point in the history
Added Change Language option in Settings
  • Loading branch information
avinashkranjan authored Aug 9, 2023
2 parents 5f28877 + bd3e486 commit 25f1843
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 204 deletions.
25 changes: 11 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class _MyAppState extends State<MyApp> {
bool isFirstRun = false;
int backButtonPressCounter = 0;


@override
void initState() {
super.initState();
Expand Down Expand Up @@ -131,10 +132,6 @@ class _MyAppState extends State<MyApp> {
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
locale: Locale('hi'),



locale: Locale('en'),
supportedLocales: [
Locale('ru'),
Expand All @@ -156,16 +153,16 @@ class _MyAppState extends State<MyApp> {
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(),
Expand Down
113 changes: 28 additions & 85 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,38 @@ class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
children: <Widget>[
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()));
Expand All @@ -154,59 +150,6 @@ class _HomeScreenState extends State<HomeScreen> 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: <Widget>[
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),
Expand Down
176 changes: 73 additions & 103 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<MyApps> {
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<SettingsScreen> createState() => _SettingsScreenState();
Expand Down Expand Up @@ -109,111 +136,52 @@ class _SettingsScreenState extends State<SettingsScreen> {
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>[
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>[
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(() {
Expand All @@ -237,6 +205,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
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(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/build_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class _BuildClassesState extends State<BuildClasses> {
),
),

),


classesList != null && classesList.isNotEmpty
? Padding(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/recents_alerts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ class _RecentsAlertsState extends State<RecentsAlerts> with WidgetsBindingObserv

}
}
}


0 comments on commit 25f1843

Please sign in to comment.