provider 2.0.0-dev copy "provider: ^2.0.0-dev" to clipboard
provider: ^2.0.0-dev copied to clipboard

outdated

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

example/provider.dart

import 'dart:async';

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

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

class Bloc {
  final StreamController<int> _streamController = StreamController();
  Stream<int> stream;

  Bloc() {
    stream = _streamController.stream.asBroadcastStream();
  }

  void dispose() {
    _streamController.close();
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provider<Bloc>(
      builder: (_) => Bloc(),
      dispose: (_, value) => value.dispose(),
      child: Example(),
    );
  }
}

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<int>(
      stream: Provider.of<Bloc>(context).stream,
      builder: (context, snapshot) {
        return Text(snapshot.data?.toString() ?? 'Foo');
      },
    );
  }
}
10.5k
likes
0
points
3.6M
downloads

Publisher

verified publisherdash-overflow.net

Weekly Downloads

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on provider