eazy_state 0.1.0+1 eazy_state: ^0.1.0+1 copied to clipboard
A lightweight and straightforward state management solution for Flutter applications, designed to manage and update UI state efficiently without the overhead of more complex state management tools.
import 'package:eazy_state/eazy_state.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MySimplePage(),
);
}
}
final counterState = EazyState(10.0);
class MySimplePage extends StatelessWidget {
const MySimplePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("Flutter Demo Home Page"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
EazyBuilder(
state: counterState,
builder: (context, count) {
return Text(
'$count',
style: Theme.of(context).textTheme.headlineMedium,
);
}),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => const MySimplePageSecond(),
),
);
},
child: const Text("Move"),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counterState.value += 1,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class MySimplePageSecond extends StatelessWidget {
const MySimplePageSecond({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'2 Page',
),
EazyBuilder(
state: counterState,
builder: (context, count) {
return Text(
'$count',
style: Theme.of(context).textTheme.headlineMedium,
);
}),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counterState.value += 1,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}