hydrated 2.0.1 copy "hydrated: ^2.0.1" to clipboard
hydrated: ^2.0.1 copied to clipboard

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,
    required String title,
  })  : _title = 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: [
              Text('You have pushed the button this many times:'),
              Text(
                '${snap.data}',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }

  void _incrementCounter() {
    _count.value++;
  }

  void dispose() {
    _count.close();
  }
}
28
likes
130
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.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, rxdart, shared_preferences

More

Packages that depend on hydrated