-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(#43): refactor to implement change language.
- Loading branch information
Showing
9 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
lib/app/features/parent_side/language/language_notififier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
class LanguageNotifier extends ChangeNotifier { | ||
late String _selectedLanguage = '🇺🇸 English'; | ||
late Locale _locale = const Locale('en'); | ||
|
||
String get selectedLanguage => _selectedLanguage; | ||
Locale get locale => _locale; | ||
|
||
List<String> languages = [ | ||
'🇫🇷 Français', | ||
'🇪🇸 Español', | ||
'🇹🇷 Turkish', | ||
'🇩🇪 Deutsch', | ||
]; | ||
|
||
void selectLanguage(String language) { | ||
languages.insert(languages.indexOf(language), _selectedLanguage); | ||
_selectedLanguage = language; | ||
languages.removeWhere((element) => element == _selectedLanguage); | ||
_locale = setLocale(_selectedLanguage); | ||
HapticFeedback.heavyImpact(); | ||
notifyListeners(); | ||
} | ||
|
||
Locale setLocale(String selectedLanguage) { | ||
switch (selectedLanguage) { | ||
case '🇫🇷 Français': | ||
return const Locale('fr'); | ||
case '🇺🇸 English': | ||
return const Locale('en'); | ||
case '🇪🇸 Español': | ||
return const Locale('es'); | ||
case '🇹🇷 Turkish': | ||
return const Locale('tr'); | ||
case '🇩🇪 Deutsch': | ||
return const Locale('de'); | ||
default: | ||
return const Locale('en'); | ||
} | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
lib/app/features/parent_side/language/language_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// ignore_for_file: library_private_types_in_public_api | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:times_up_flutter/app/features/parent_side/language/language_notififier.dart'; | ||
import 'package:times_up_flutter/services/auth.dart'; | ||
import 'package:times_up_flutter/theme/theme.dart'; | ||
import 'package:times_up_flutter/widgets/jh_display_text.dart'; | ||
|
||
class LanguagePage extends StatefulWidget { | ||
const LanguagePage({ | ||
required this.auth, | ||
required this.languageModel, | ||
Key? key, | ||
}) : super(key: key); | ||
final AuthBase auth; | ||
final LanguageNotifier languageModel; | ||
|
||
static Widget create( | ||
BuildContext context, | ||
AuthBase auth, | ||
) { | ||
return Consumer<LanguageNotifier>( | ||
builder: (BuildContext context, value, Widget? child) => LanguagePage( | ||
auth: auth, | ||
languageModel: value, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
_LanguagePageState createState() => _LanguagePageState(); | ||
} | ||
|
||
class _LanguagePageState extends State<LanguagePage> { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final color = Theme.of(context).brightness == Brightness.dark | ||
? Colors.white | ||
: CustomColors.indigoDark; | ||
|
||
return Scaffold( | ||
body: NestedScrollView( | ||
headerSliverBuilder: (BuildContext context, value) { | ||
return [ | ||
SliverAppBar( | ||
elevation: 0.5, | ||
shadowColor: CustomColors.indigoLight, | ||
iconTheme: IconThemeData(color: color), | ||
backgroundColor: Theme.of(context).scaffoldBackgroundColor, | ||
expandedHeight: 50, | ||
pinned: true, | ||
floating: true, | ||
) | ||
]; | ||
}, | ||
body: ScrollConfiguration( | ||
behavior: const ScrollBehavior().copyWith(overscroll: false), | ||
child: CustomScrollView( | ||
slivers: <Widget>[ | ||
SliverToBoxAdapter( | ||
child: JHDisplayText( | ||
text: 'Languages', | ||
style: TextStyle( | ||
color: color, | ||
fontWeight: FontWeight.w700, | ||
), | ||
fontSize: 32, | ||
maxFontSize: 34, | ||
).hP16, | ||
), | ||
const SliverPadding(padding: EdgeInsets.only(top: 50)), | ||
SliverToBoxAdapter( | ||
child: Card( | ||
margin: const EdgeInsets.symmetric(horizontal: 50), | ||
color: CustomColors.indigoLight, | ||
child: Center( | ||
child: SizedBox( | ||
height: 60, | ||
child: Center( | ||
child: JHDisplayText( | ||
text: widget.languageModel.selectedLanguage, | ||
style: TextStyles.title, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
SliverList( | ||
delegate: SliverChildListDelegate([ | ||
SingleChildScrollView( | ||
child: SizedBox( | ||
height: 2000, | ||
child: ListView.separated( | ||
itemCount: 4, | ||
itemBuilder: (builder, index) => GestureDetector( | ||
onTap: () => widget.languageModel.selectLanguage( | ||
widget.languageModel.languages[index], | ||
), | ||
child: JHDisplayText( | ||
text: widget.languageModel.languages[index], | ||
style: TextStyles.title, | ||
).p(8), | ||
), | ||
separatorBuilder: (BuildContext context, int index) => | ||
const Divider( | ||
thickness: 1, | ||
indent: 20, | ||
endIndent: 20, | ||
color: Colors.grey, | ||
).p4, | ||
), | ||
), | ||
), | ||
]), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:times_up_flutter/utils/app_strings.dart'; | ||
|
||
class Keys { | ||
|