iRyanBell

Let It FLOW

May 29, 2019

Let It FLOW

I created a new open-source package for Dart to encapsulate my functional listener/observable widget (FLOW) builder. This allows applications to apply state changes to stateless functional widgets using stream currents and conditional FLOW gates.

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);

This package is available on pub.dev at:
https://pub.dev/packages/flow

You can download the project here: 👇
https://github.com/iRyanBell/flutter-flow