stream_language 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new66

Stream Language #

Check it out at Pub.Dev

A simple way to support your Flutter application, which from firebase with realtime database supports multiple languages!

ezgif com-video-to-gif (1)

Getting Started #

You must first create an object with the following attributes:

var language = LanguageBloc(
  child: 'languages',      
  defaultLanguage: 'pt_BR',
  defaultRoute: 'default'
);

LanguageBloc is a singleton, after the first start, it will have the same attributes.

Child: #

The child in your realtime database that contains the app language. In app example its likes this:

Captura de Tela (101)

Each child of this node must be named in the language and iso-code of the country as shown in the screenshot.

DefaultLanguage #

Here will be informed the default home language when connecting the language of the user device does not have in the database.

DefaultRoute #

Here you enter the node within the language that contains words that can be used on more than one screen as in the example below:

Captura de Tela (102)

The first time you use firebase language you should do this:

final language = LanguageBloc(
    child: 'languages',
    defaultLanguage: 'pt_BR',
    defaultRoute: 'default'
);

@override
Widget build(BuildContext context) {
  return FirstLanguageStart(
    future: language.init(),
    builder: (c) => StreamLanguage(
      screenRoute: ['screen-1'],
      builder: (data, route, def) => Scaffold(
        appBar: AppBar(
          title: Text(route['title']),
        ),
        body: Center(
          child: RaisedButton(
              child: Text(route['btn']),
              onPressed: () => language.showAlertChangeLanguage(
                  context: context,
                  title: def['change-language']['title'],
                  btnNegative: def['change-language']['btn-negative']
              )
          ),
        ),
      ),
    )
  );
}

From the next you start using only the StreamLanguage widget, the first one is needed because the first app should download all language and start the default language from the user's mobile language.

Widget StreamLanguage #

ScreenRoute #

This is where the magic happens, as a parameter it receives the screen route within the language node, see that in the code above is as: screenRoute: ['screen-1'], in firebase it looks like this:

Captura de Tela (103)

If the route were a node within 'screen-1' you would go something like this: screenRoute: ['screen-1', 'route_inside']

Builder #

The builder receives as parameter 3 fields: data, route and def

Data #

Data contains all node of current language.

Route #

Contains all node passed by ScreenRoute.

Def #

Contains all node passed as parameter in LanguageBloc constructor in DefaultRoute

Changing Language #

For this, every language node must have a child named config with the following attributes: Captura de Tela (104)

After that you can call the method:

language.showAlertChangeLanguage(
    context: context,
    title: def['change-language']['title'],
    btnNegative: def['change-language']['btn-negative']
)

This will show an alert dialog like this (Language and flag listing is done automatically from the data passed in the config node):

Captura de Tela (105)

To change the language programmatically, just call this method passing as the language prefix ex:

languageBloc.changeLanguage('pt_BR');

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

[0.1.0] - TODO: Add release date.

  • Fixing bugs

[0.1.2]

  • TODO: Added function "onChange" in StreamLanguage, it called when current language is changed

example/main.dart

import 'package:flutter/material.dart';
import 'package:stream_language/stream_language.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final language = LanguageBloc(
      child: 'languages',
      defaultLanguage: 'pt_BR',
      defaultRoute: 'default'
  );

  @override
  Widget build(BuildContext context) {
    return FirstLanguageStart(
      future: language.init(),
      builder: (c){
        return StreamLanguage(
          screenRoute: ['screen-1'],
          builder: (data, route, def) => Scaffold(
            appBar: AppBar(
              title: Text(route['title']),
            ),
            body: Center(
              child: RaisedButton(
                  child: Text(route['btn']),
                  onPressed: () => language.showAlertChangeLanguage(
                      context: context,
                      title: def['change-language']['title'],
                      btnNegative: def['change-language']['btn-negative']
                  )
              ),
            ), // This trailing comma makes auto-formatting nicer for build methods.
          ),
        );
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stream_language: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stream_language/stream_language.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/stream_language.dart.

Run flutter format to format lib/stream_language.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bloc_pattern ^2.3.2 2.4.0+2
country_pickers ^1.1.0 1.1.0
devicelocale ^0.2.0 0.2.0
firebase_database ^3.0.7 3.0.7
flutter 0.0.0
rxdart ^0.22.2 0.22.3
Transitive dependencies
collection 1.14.11 1.14.12
firebase_core 0.4.0+9
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test