provider 1.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 86

Build Status pub package

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

This is especially useful with patterns such as BLoC or when storing our state inside InheritedWidget. As having to manually write a StatefulWidget AND an InheritedWidget can be tedious.

Usage

Provider usage:

import 'package:provider/provider.dart';

main() {
  runApp(
    Provider(
      value: 42,
      child: Builder(
        builder: (context) => {
          // explicitly pass the generic type
          final value = Provider.of<int>(context);

          // type inference works too:
          int value2;
          value2 = Provider.of(context);

          // do something with it
        }
      )
    )
  );
}

StatefulProvider usage

class Model {}

class Stateless extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StatefulProvider<Model>(
      // we voluntary reuse the previous value
      valueBuilder: (_, old) =>  old ?? Model(),
      // child: ...,
    );
  }
}

Release 1.1.0

  • onDispose has been added to StatefulProvider
  • BuildContext is now passed to valueBuilder callback

Release 1.1.1

  • add didChangeDependencies callback to allow updating the value based on an InheritedWidget
  • add updateShouldNotify method to both Provider and StatefulProvider

example/provider.dart

import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provider(
      value: 42,
      child: Example(),
    );
  }
}

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text(Provider.of<int>(context).toString());
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  provider: ^1.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:provider/provider.dart';
  
Version Uploaded Documentation Archive
1.1.1 Oct 22, 2018 Go to the documentation of provider 1.1.1 Download provider 1.1.1 archive
1.1.0 Oct 21, 2018 Go to the documentation of provider 1.1.0 Download provider 1.1.0 archive
1.0.0 Oct 19, 2018 Go to the documentation of provider 1.0.0 Download provider 1.0.0 archive
0.0.1 Oct 19, 2018 Go to the documentation of provider 0.0.1 Download provider 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
73
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]
86
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6
  • Flutter: 0.11.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test