floop 0.2.2 floop: ^0.2.2 copied to clipboard
Flutter state management library. Automatically refresh Widgets on data changes. Extremely easy to use.
import 'package:flutter/material.dart';
import 'package:floop/floop.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() {
floop['clicks'] = 0;
runApp(MaterialApp(
title: 'Clicker',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Clicker()));
}
class Clicker extends StatelessWidget with Floop {
@override
Widget buildWithFloop(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
floop['clicks'].toString(),
style: TextStyle(
color: Colors.red,
fontSize: 100,
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => floop['clicks']++),
);
}
}
// The following are alternative implementations.
class ClickerStateful extends StatefulWidget {
@override
State<StatefulWidget> createState() => ClickerState();
}
class ClickerState extends State<ClickerStateful> with FloopStateMixin {
@override
Widget buildWithFloop(BuildContext context) {
return Scaffold(
body: Center(
child: Text(floop['clicks'].toString(),
style: TextStyle(
color: Colors.red,
fontSize: 100,
))),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => floop['clicks']++),
);
}
}
// Simplest example.
class SimpleClicker extends StatelessWidget with Floop {
@override
Widget buildWithFloop(BuildContext context) {
return Scaffold(
body: Center(child: Text(floop['clicks'].toString())),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add), onPressed: () => floop['clicks']++),
);
}
}