floca 0.1.6+16 copy "floca: ^0.1.6+16" to clipboard
floca: ^0.1.6+16 copied to clipboard

Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'generated_i18n.dart'; // file generated by floca

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // the [localeIndex] will determine what to pass as the [locale]
  // argument to the [MaterialApp] constructor. It will allow us to switch
  // between supported locales manually.
  int localeIndex = -1; // -1 for default locale

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        localizationsDelegates: localizationsDelegates,
        supportedLocales: supportedLocales,
        locale: localeIndex < 0 ? null : supportedLocales[localeIndex],

        // the current [context] was made before we created the MaterialApp
        // with localization. To use a localized context, we need a new builder

        home: Builder(builder: (BuildContext context) {
          // ok, this [context] knows the locale

          return Scaffold(
              appBar: AppBar(
                  title: Text(localeIndex < 0
                      ? 'Default locale'
                      : 'Locale $localeIndex')),
              body: Center(
                  child: Text(
                      context.i18n
                          .hello, // 'hello', or 'hola', or 'привет' depending on locale
                      style: Theme.of(context).textTheme.headline3)),
              floatingActionButton: FloatingActionButton(
                onPressed: () => setState(() {
                  // increase localeIndex and rebuild MaterialApp with
                  // other [locale] argument
                  if (++localeIndex >= supportedLocales.length) {
                    localeIndex = -1;
                  }
                }),
                child: Icon(Icons.g_translate),
              ));
        }));
  }
}
2
likes
50
pub points
0%
popularity

Publisher

verified publisherrevercode.com

Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

csv, flutter, flutter_lints, flutter_localizations, intl

More

Packages that depend on floca