stream_language 0.1.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

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');

Help Maintenance #

I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it.

Buy Me A Coffee

[0.1.2+1] - Fix dependencies. #

[0.1.2] #

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

[0.1.0] - TODO: Add release date. #

  • Fixing bugs

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.

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+1

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]
48
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]
74
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:stream_language/stream_language.dart, package:firebase_database/firebase_database.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:stream_language/stream_language.dart, package:firebase_database/firebase_database.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:stream_language/stream_language.dart, package:firebase_database/firebase_database.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:stream_language/stream_language.dart, package:firebase_database/firebase_database.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [stream_language] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bloc_pattern ^2.3.2 2.5.1
country_pickers ^1.1.0 1.3.0
devicelocale ^0.2.0 0.2.3
firebase_database ^3.0.7 3.1.6
flutter 0.0.0
rxdart ^0.24.0 0.24.1
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
firebase 7.3.0
firebase_core 0.4.5
firebase_core_platform_interface 1.0.4
firebase_core_web 0.1.1+2
flutter_web_plugins 0.0.0
http 0.12.1
http_parser 3.1.4
js 0.6.2
matcher 0.12.8
meta 1.1.8
path 1.7.0
pedantic 1.9.0 1.9.1
plugin_platform_interface 1.0.2
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test