collection_notifiers 1.0.2 copy "collection_notifiers: ^1.0.2" to clipboard
collection_notifiers: ^1.0.2 copied to clipboard

outdated

Collections with implementation of ValueListenable/ChangeNotifier for minimum rebuild and sugared syntax

example/lib/main.dart

import 'package:collection_notifiers/collection_notifiers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const ProviderScope(child: App()));
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: Home());
  }
}

final setNotifier =
ChangeNotifierProvider.autoDispose((ref) => SetNotifier<int>([1, 1, 1]));
final listProvider =
ChangeNotifierProvider((ref) => ListNotifier<int>([1, 2, 3]));
final mapProvider =
ChangeNotifierProvider((ref) => MapNotifier<String, int>({'a': 1}));

class Home extends ConsumerWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Scaffold(
      body: ListView(
        children: ListTile.divideTiles(
          context: context,
          tiles: List.generate(10, (index) => index).map((e) {
            return CheckboxListTile(
              title: Text(e.toString()),
              value: ref.watch(setNotifier).contains(e),
              onChanged: (value) {
                if (value == true) {
                  ref.read(setNotifier).add(e);
                } else {
                  ref.read(setNotifier).remove(e);
                }
              },
            );
          }),
        ).toList(),
      ),
    );
  }
}
5
likes
0
pub points
40%
popularity

Publisher

unverified uploader

Collections with implementation of ValueListenable/ChangeNotifier for minimum rebuild and sugared syntax

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

collection, flutter

More

Packages that depend on collection_notifiers