easy 2.0.0 easy: ^2.0.0 copied to clipboard
An easy Flutter state managegement that allows minimal rebuild of widgets and improves performance.
import 'package:easy/easy.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class AppWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: Get.key,
home: EasyManager(
view: HomeModule(),
bloc: counterBloc,
));
}
}
class HomeModule extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton:
FloatingActionButton(onPressed: () => counterBloc.exec()),
appBar: AppBar(
title: Text("test easy"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Store(rebuild: (_) => Text("${counterBloc.count}")),
FlatButton(
onPressed: () => Get.to(HomeModule2()),
child: Text("Next"),
color: Colors.amber,
)
],
),
),
);
}
}
class HomeModule2 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton:
FloatingActionButton(onPressed: () => counterBloc.exec()),
appBar: AppBar(
title: Text("test easy 2"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Store(rebuild: (_) => Text(counterBloc.count.toString())),
FlatButton(
onPressed: () => Get.back(),
child: Text("done"),
color: Colors.amber,
),
FlatButton(
onPressed: () => counterBloc.dispose(),
child: Text("dispose"),
color: Colors.amber,
),
],
),
),
);
}
}
final HomeBloc counterBloc = HomeBloc();
class HomeBloc extends EasyBloc {
int count = 0;
@override
void exec() {
count++;
super.exec();
}
}