computed_flutter 0.1.0 computed_flutter: ^0.1.0 copied to clipboard
Straightforward, reliable, performant and testable reactive state management for Flutter
import 'package:computed_flutter/computed_flutter.dart';
import 'package:flutter/material.dart';
final count = ValueNotifier(0);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Computed Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
// Note that unlike the vanilla counter app, this widget is stateless
class MyHomePage extends ComputedWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Computed Flutter Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text('${count.use}',
style: Theme.of(context).textTheme.headlineMedium)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => count.value++,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}