fast_localization 2.1.0 copy "fast_localization: ^2.1.0" to clipboard
fast_localization: ^2.1.0 copied to clipboard

Fast localization solution for flutter apps using Dart's `Map`

example/fast_localization.dart

// 1. import material
import 'package:material_ui/material_ui.dart';

// 2. import fast localization
import 'package:fast_localization/fast_localization.dart';

// 3. add async to main function
void main() async {
  // 4. declare locales as you like, either as follows or import them
  final locales = {
    Locale('en'): {"title": "Demo", "welcome": "Hello World!"},
    Locale('ar'): {"title": "عرض", "welcome": "أهلاً بالعالم!"},
  };

  // 5. load fast localization
  await Localization.load(locales);

  // 6. use LocalizationApp
  runApp(
    LocalizationApp(
      // MaterialApp(title) | required with home: only
      title: () => Localization.translate('title'),
      home: () => HomeScreen(), // MaterialApp(home) | required with home: only
      theme: ThemeData.light(), // MaterialApp(theme) | optional
    ),
  );
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(Localization.translate('title'))),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('😉', style: TextStyle(fontSize: 50)),
            Text(
              Localization.translate('title'),
              style: TextStyle(fontSize: 25),
            ),
            SizedBox(height: 60),
            TextButton(
              child: Text('English'),
              onPressed: () {
                Localization.changeLocale(Locale('en'));
              },
            ),
            TextButton(
              child: Text('عربي'),
              onPressed: () {
                Localization.changeLocale(Locale('ar'));
              },
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
150
points
195
downloads

Documentation

API reference

Publisher

verified publisherhighestweb.com

Weekly Downloads

Fast localization solution for flutter apps using Dart's `Map`

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

collection, flutter, material_ui, shared_preferences

More

Packages that depend on fast_localization