notifier_builder 0.4.0-beta notifier_builder: ^0.4.0-beta copied to clipboard
A Flutter library that provides an alternative to AnimatedBuilder for building widgets that depend on any Listenable notifier/controller
import 'package:flutter/material.dart';
import 'package:notifier_builder/notifier_builder.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
class MyHomePage extends StatelessWidget {
const MyHomePage({
required this.title,
super.key,
});
final String title;
@override
Widget build(BuildContext context) => NotifierBuilder(
notifier: () => ValueNotifier<int>(0),
builder: (context, child, counterNotifier) => Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'${counterNotifier.value}',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counterNotifier.value++,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
),
);
}