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

A Flutter Plugin for multilanguage

Multilanguage #

Installation #

Put this line in your pubspec.yaml:

multilanguage: ^1.0.0

Import #

import 'package:multilanguage/multilanguage.dart';

Usage #

import 'package:multilanguage/multilanguage.dart';

...

Widget build(BuildContext context) {
    ...
    Multilanguage.setLanguage(path: Languages.en, context: context);
    ...
    return ...
    ...
    Text(multilang.get('title'))
    ...
}

The class languages and its constants is just a kind of enum for the paths of the jsons. The jsons should follow the next structure, but with your own keys:

{
    'title':'Title'
}

Each language should have it's own file and has to be added to a json folder inside a assets folder in the root of the project:

  assets:
   - assets/json/

Example #

This example is wrapped in a utils Bloc defined to reset the current screen, but you can implement your own:

import 'package:multilanguage/multilanguage.dart';

...

Widget build(BuildContext context) {
    Multilanguage.setLanguage(path: Languages.en, context: context);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: StreamBuilder(
              stream: multilangBloc.stream
              initialData: multilang.get('title'),
              builder: (context, snapshot) {
            return Text(multilang.get('title'));
          }),
        ),
        body: Center(
          child: MaterialButton(
            onPressed: () {
              multilangBloc.changeLanguage(context, path)
            },
            child: Text('Change Language'),
          ),
        ),
      ),
    );
  }

License #

MIT

3
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A Flutter Plugin for multilanguage

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, shared_preferences

More

Packages that depend on multilanguage