flutter_state_management 0.0.6 copy "flutter_state_management: ^0.0.6" to clipboard
flutter_state_management: ^0.0.6 copied to clipboard

A collection of helper classes to make the use of ChangeNotifier easier for state management

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_state_management/flutter_state_management.dart';
import 'package:isar_key_value/isar_key_value.dart';

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

class MyApp extends RStatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final counter = counterResolver();

    counter.watch(context,  selector: (model) => model.state);

    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text('You have pushed the button this many times:'),
              counter.builder(
                onLoaded: (context, data) => Text(
                  data.toString(),
                  style: Theme.of(context).textTheme.headlineMedium,
                ),
                onLoading: (_, __) => const CircularProgressIndicator(),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: counter.increment,
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

final counterResolver = Resolver((arg) => Counter());

class Counter extends PersistedStateNotifier<int, int> {
  Counter() : super(IsarKeyValue(), startState: 0);

  void increment() async {
    persistedState = Loading(data: data);
    await Future.delayed(const Duration(seconds: 2));
    persistedState = Loaded(data: data + 1);
  }
}
3
likes
0
pub points
70%
popularity

Publisher

verified publishermuha.dev

A collection of helper classes to make the use of ChangeNotifier easier for state management

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, isar_key_value

More

Packages that depend on flutter_state_management