global_state 0.1.2 global_state: ^0.1.2 copied to clipboard
Simplistic state management paradigm. Global State automatically refresh Widgets on data changes.
import 'package:flutter/material.dart';
import 'package:global_state/global_state.dart';
/// This example exists to satisfy dart publishing requirements.
/// More complete examples are available at the root of the project on Github.
/// https://github.com/icatalud/floop
void main() {
store['clicks'] = 0;
runApp(MaterialApp(
title: 'Clicker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Clicker()));
}
class Clicker extends StatelessWidgetGS {
@override
Widget buildGS(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
store['clicks'].toString(),
style: TextStyle(
color: Colors.red,
fontSize: 100,
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => store['clicks']++),
);
}
}
// The following are alternative implementations.
class ClickerStateful extends StatefulWidget {
@override
State<ClickerStateful> createState() => ClickerState();
}
class ClickerState extends StateGS<ClickerStateful> {
@override
Widget buildGS(BuildContext context) {
return Scaffold(
body: Center(
child: Text(store['clicks'].toString(),
style: TextStyle(
color: Colors.red,
fontSize: 100,
))),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => store['clicks']++),
);
}
}
// Simplest example.
class SimpleClicker extends StatelessWidgetGS {
@override
Widget buildGS(BuildContext context) {
return Scaffold(
body: Center(child: Text(store['clicks'].toString())),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => store['clicks']++),
);
}
}