hydrated 1.2.5+2 copy "hydrated: ^1.2.5+2" to clipboard
hydrated: ^1.2.5+2 copied to clipboard

outdated

An automatically persisted BehaviorSubject with simple hydration for Flutter. Intended to be used with the BLoC pattern.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Hydrated Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Hydrated Demo'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;
  final count$ = HydratedSubject<int>("count", seedValue: 0);

  MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(this.title),
      ),
      body: Center(
        child: StreamBuilder<int>(
          stream: count$,
          initialData: count$.value,
          builder: (context, snap) => Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'You have pushed the button this many times:',
                  ),
                  Text(
                    '${snap.data}',
                    style: Theme.of(context).textTheme.display1,
                  ),
                ],
              ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => count$.value++,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }

  void dispose() => count$.close();
}
28
likes
30
points
115
downloads

Publisher

verified publishersolid.software

Weekly Downloads

An automatically persisted BehaviorSubject with simple hydration for Flutter. Intended to be used with the BLoC pattern.

License

MIT (license)

Dependencies

flutter, rxdart, shared_preferences

More

Packages that depend on hydrated