flutter_provider 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

flutter_provider #

Author: Petrus Nguyễn Thái Học

Pub Build Status License: MIT

Flutter generic provider using InheritedWidget. An helper to easily exposes a value using InheritedWidget without having to write one.

Getting Started #

In your flutter project, add the dependency to your pubspec.yaml

dependencies:
  ...
  flutter_provider: ^1.1.1

Usage #

1. Provide #

Providers(
  providers: <Provider>[
    const Provider<Bar1>(value: bar1),
    const Provider<Bar2>(value: bar2),
  ],
  child: const Provider<Foo>(
    value: foo,
    child: MyApp(),
  ),
);

2. Consume #

Consumer3<Foo, Bar1, Bar2>(
  builder: (context, Foo a, Bar1 b, Bar2 c) {
    return Container(
      constraints: BoxConstraints.expand(),
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(a.foo()),
            Text(b.bar1()),
            Text(c.bar2()),
          ],
        ),
      ),
    );
  },
);

License #

MIT License

Copyright (c) 2019 Petrus Nguyễn Thái Học

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1.1.1 - April 14, 2019 #

  • Remove deprecated method in flutter

1.1.0+3 - April 14, 2019 #

  • No change

1.1.0+2 - April 14, 2019 #

  • No change

1.1.0+1 - April 14, 2019 #

  • Refactor

1.1.0 - April 7, 2019 #

  • Add Providers, Consumer2, Consumer3, Consumer4, Consumer5, Consumer6, Consumer7, Consumer8, Consumer9.

1.0.0 - March 31, 2019 #

  • Initial package

example/lib/main.dart

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

class Foo {
  const Foo();

  String foo() => 'Hello';
}

class Bar1 {
  const Bar1();

  String bar1() => 'Hello everyone';
}

class Bar2 {
  const Bar2();

  String bar2() => 'Fall in love with Flutter';
}

void main() {
  const Foo foo = Foo();
  const Bar1 bar1 = Bar1();
  const Bar2 bar2 = Bar2();

  runApp(
    Providers(
      providers: <Provider>[
        const Provider<Bar1>(value: bar1),
        const Provider<Bar2>(value: bar2),
      ],
      child: const Provider<Foo>(
        value: foo,
        child: MyApp(),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Provider example',
      theme: ThemeData.dark(),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter provider example'),
      ),
      body: Consumer3<Foo, Bar1, Bar2>(
        builder: (BuildContext context, Foo a, Bar1 b, Bar2 c) {
          return Container(
            constraints: BoxConstraints.expand(),
            child: Center(
              child: Column(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(a.foo()),
                  Text(b.bar1()),
                  Text(c.bar2()),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_provider: ^1.1.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:flutter_provider/flutter_provider.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
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]
91
Learn more about scoring.

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

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
meta >=1.1.1 <2.0.0 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
matcher ^0.12.6