flutter_fx 0.1.4
flutter_fx: ^0.1.4 copied to clipboard
A set of state & navigation manager for flutter. It allows you to update wisely your states and to navigate easily.
import 'package:flutter/material.dart';
import 'package:flutter_fx/flutter_fx.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return FxApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
initialRoute: "/",
routeBuilder: (path) {
switch (path) {
case "/":
default:
return const MyHomePage(title: 'Flutter Demo Home Page');
}
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final FxInt _counter = 0.toFx;
void _incrementCounter() {
_counter.value++;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
FxBuilder(
builder: (fxContext) => Text(
'${_counter.listen(fxContext)}',
style: Theme.of(context).textTheme.headlineMedium,
)),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}