simple_notifier 1.0.0 copy "simple_notifier: ^1.0.0" to clipboard
simple_notifier: ^1.0.0 copied to clipboard

A simple extension to simplify ValueNotifier usage

example/lib/main.dart

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;
  }
}
1
likes
0
pub points
47%
popularity

Publisher

verified publisherkakzaki.dev

A simple extension to simplify ValueNotifier usage

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_notifier