Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/ilteoood/flutter_i18n/issues/17 #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_i18n/flutter_i18n_delegate.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(new MyApp());
Future main() async {
FlutterI18n flutterI18n=FlutterI18n(false,"",'assets/i18n');
await flutterI18n.load();
runApp(new MyApp(flutterI18n: flutterI18n,));
}

class MyApp extends StatelessWidget {
final FlutterI18n flutterI18n;
MyApp({this.flutterI18n});
@override
Widget build(BuildContext context) {
return new MaterialApp(
Expand All @@ -15,7 +21,7 @@ class MyApp extends StatelessWidget {
),
home: new MyHomePage(),
localizationsDelegates: [
FlutterI18nDelegate(path: 'assets/i18n'),
FlutterI18nDelegate(flutterI18n: flutterI18n),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
Expand Down
7 changes: 2 additions & 5 deletions lib/flutter_i18n_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class FlutterI18nDelegate extends LocalizationsDelegate<FlutterI18n> {
final bool useCountryCode;
final String fallbackFile;
final String path;

final FlutterI18n flutterI18n ;
FlutterI18nDelegate(
{this.useCountryCode = false,
this.fallbackFile,
this.path = "assets/flutter_i18n"});
this.path = "assets/flutter_i18n",this.flutterI18n});

@override
bool isSupported(final Locale locale) {
Expand All @@ -23,9 +23,6 @@ class FlutterI18nDelegate extends LocalizationsDelegate<FlutterI18n> {

@override
Future<FlutterI18n> load(final Locale locale) async {
final FlutterI18n flutterI18n =
FlutterI18n(useCountryCode, fallbackFile, path);
await flutterI18n.load();
return flutterI18n;
}

Expand Down