ezi18n 1.0.0 copy "ezi18n: ^1.0.0" to clipboard
ezi18n: ^1.0.0 copied to clipboard

A simple internationalization package.

example/lib/main.dart

import 'package:example/messages.dart';
import 'package:ezi18n/ezi18n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'home_page.dart';

void main() {
  runApp(MyApp(
    messages: AppMessages(),
    supportedLocales: [
      Locale('en'),
      Locale('pt'),
      Locale('pt', 'BR'),
    ],
    locale: Locale('pt', 'BR'),
  ));
}

class MyApp extends StatefulWidget {
  final Locale locale;
  final EzMessages messages;
  final List<Locale> supportedLocales;

  MyApp(
      {required this.messages,
      required this.supportedLocales,
      required this.locale});

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Locale _currentLocale;

  _MyAppState() : _currentLocale = Locale('en');

  @override
  void initState() {
    _currentLocale = widget.locale;
    super.initState();
  }

  void _changeLanguage(Locale locale) {
    setState(() {
      _currentLocale = locale;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      locale: _currentLocale,
      debugShowCheckedModeBanner: false,
      localizationsDelegates: [
        EzI18nDelegate(
            widget.messages), // Add the EzI18nDelegate, for the custom messages
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: widget.supportedLocales,
      home: MyHomePage(
        onChangeLanguage: _changeLanguage,
        supportedLocales: widget.supportedLocales,
        currentLocale: _currentLocale,
      ),
    );
  }
}
0
likes
140
points
30
downloads

Publisher

unverified uploader

Weekly Downloads

A simple internationalization package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_test, intl

More

Packages that depend on ezi18n