-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e13ff73
commit 80d1be4
Showing
14 changed files
with
217 additions
and
35 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
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,22 +1,70 @@ | ||
import 'package:example/presentation/login_page/login_page.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:lucid_validation/lucid_validation.dart'; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
|
||
final globalLocale = ValueNotifier(Locale('en')); | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
useMaterial3: true, | ||
), | ||
home: const LoginPage(), | ||
return ValueListenableBuilder<Locale>( | ||
valueListenable: globalLocale, | ||
builder: (context, value, child) { | ||
return MaterialApp( | ||
debugShowCheckedModeBanner: false, | ||
title: 'Flutter Demo', | ||
locale: value, | ||
supportedLocales: const [ | ||
Locale('en', 'US'), | ||
Locale('pt', 'BR'), | ||
], | ||
localizationsDelegates: [ | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
LucidLocalizationDelegate.delegate, | ||
], | ||
theme: ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), | ||
useMaterial3: true, | ||
), | ||
home: const LoginPage(), | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class LucidLocalizationDelegate extends LocalizationsDelegate<Culture> { | ||
const LucidLocalizationDelegate(); | ||
|
||
static final delegate = LucidLocalizationDelegate(); | ||
|
||
@override | ||
bool isSupported(Locale locale) { | ||
return LucidValidation.global.languageManager.isSupported( | ||
locale.languageCode, | ||
locale.countryCode, | ||
); | ||
} | ||
|
||
@override | ||
Future<Culture> load(Locale locale) async { | ||
print(locale); | ||
final culture = Culture(locale.languageCode, locale.countryCode ?? ''); | ||
LucidValidation.global.culture = culture; | ||
return culture; | ||
} | ||
|
||
@override | ||
bool shouldReload(LocalizationsDelegate<Culture> old) { | ||
return true; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
class Culture { | ||
final String languageCode; | ||
final String countryCode; | ||
|
||
Culture(this.languageCode, [this.countryCode = '']); | ||
|
||
@override | ||
bool operator ==(covariant Culture other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other.languageCode == languageCode && other.countryCode == countryCode; | ||
} | ||
|
||
@override | ||
int get hashCode => languageCode.hashCode ^ countryCode.hashCode; | ||
} |
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,5 @@ | ||
import '../language.dart'; | ||
|
||
class EnglishLanguage extends Language { | ||
EnglishLanguage() : super('en'); | ||
EnglishLanguage(); | ||
} |
Oops, something went wrong.