simple_notifier 1.0.0 simple_notifier: ^1.0.0 copied to clipboard
A simple extension to simplify ValueNotifier usage
import 'package:flutter/material.dart';
import 'package:simple_notifier/simple_notifier.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final _counter = 0.notifier;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Simple Notifier Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_counter.listen(
builder: (context, value, child) {
return Text(
'Counter Value: $value',
style: const TextStyle(fontSize: 24),
);
},
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _incrementCounter,
child: const Text('Increment Counter'),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _resetCounter,
child: const Text('Reset Counter'),
),
],
),
),
),
);
}
void _incrementCounter() {
_counter.value++;
}
void _resetCounter() {
_counter.value = 0;
}
}