flutter_redux_hooks 0.1.0 copy "flutter_redux_hooks: ^0.1.0" to clipboard
flutter_redux_hooks: ^0.1.0 copied to clipboard

outdated

A hook-based alternative to flutter_redux

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart' show HookWidget;
import 'package:flutter_redux_hooks/flutter_redux_hooks.dart';
import 'package:redux/redux.dart';

enum Actions { Increment }

int counterReducer(int state, dynamic action) {
  if (action == Actions.Increment) {
    return state + 1;
  }

  return state;
}

void main() {
  final store = Store<int>(counterReducer, initialState: 0);

  runApp(
    StoreProvider<int>(
      store: store,
      child: FlutterReduxApp(
        title: 'Flutter Redux Demo',
      ),
    ),
  );
}

class FlutterReduxApp extends HookWidget {
  final String title;

  FlutterReduxApp({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final dispatch = useDispatch<int>();
    final count = useSelector<int, String>((state) => state.toString());

    return MaterialApp(
      theme: ThemeData.dark(),
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'You have pushed the button this many times:',
              ),
              Text(
                count,
                style: TextStyle(color: Colors.white, fontSize: 36),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => dispatch(Actions.Increment),
          child: Icon(Icons.add),
        ),
      ),
    );
  }
}
8
likes
0
pub points
63%
popularity

Publisher

unverified uploader

A hook-based alternative to flutter_redux

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_hooks, meta, redux

More

Packages that depend on flutter_redux_hooks