flow 0.1.0 flow: ^0.1.0 copied to clipboard
Functional listener/observable widgets (FLOWs). Propagate your state changes using stream controller broadcasts.
import 'package:flutter/material.dart';
import 'package:flow/flow.dart';
final Map flows = {
'tapCount': FLOW().stream(0),
};
final FLOW myHomePage = FLOW(
ctl: flows['tapCount'],
cnd: (val) => val % 2 == 0,
builder: ({ctx, val}) => Scaffold(
appBar: AppBar(
title: Text(
val == 0 ? 'Hello world!' : 'The tap count is EVEN ($val)',
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FLOW(
ctl: flows['tapCount'],
builder: ({val, ctx}) => Text(
val == 0
? 'Press the plus button to begin!'
: 'Total Taps: $val',
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
flows['tapCount'].current(flows['tapCount'].val + 1);
},
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
final FLOW myApp = FLOW(
builder: ({ctx, val}) => MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: myHomePage,
),
);
void main() => runApp(myApp);