main.dart 1.95 KB
Newer Older
1 2 3 4
library built_redux_sample;

import 'package:built_redux/built_redux.dart';
import 'package:built_redux_sample/containers/add_todo.dart';
5
import 'package:built_redux_sample/models/models.dart';
6
import 'package:built_redux_sample/localization.dart';
7 8 9
import 'package:built_redux_sample/actions/actions.dart';
import 'package:built_redux_sample/reducers/reducers.dart';
import 'package:built_redux_sample/middleware/store_todos_middleware.dart';
10
import 'package:built_redux_sample/presentation/home_screen.dart';
11 12 13 14 15 16 17 18
import 'package:flutter_built_redux/flutter_built_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter_architecture_samples/flutter_architecture_samples.dart';

void main() {
  runApp(new BuiltReduxApp());
}

19
class BuiltReduxApp extends StatefulWidget {
Brian Egan's avatar
Brian Egan committed
20 21 22 23 24 25 26 27 28
  final store = new Store<AppState, AppStateBuilder, AppActions>(
    reducerBuilder.build(),
    new AppState.loading(),
    new AppActions(),
    middleware: [
      createStoreTodosMiddleware(),
    ],
  );

29 30 31 32 33 34 35 36 37
  @override
  State<StatefulWidget> createState() {
    return new BuiltReduxAppState();
  }
}

class BuiltReduxAppState extends State<BuiltReduxApp> {
  Store<AppState, AppStateBuilder, AppActions> store;

Brian Egan's avatar
Brian Egan committed
38
  BuiltReduxApp() {}
39

40 41 42 43 44 45 46 47 48
  @override
  void initState() {
    store = widget.store;

    store.actions.fetchTodosAction();

    super.initState();
  }

49 50 51 52 53 54 55 56 57 58 59 60 61
  @override
  Widget build(BuildContext context) {
    return new ReduxProvider(
      store: store,
      child: new MaterialApp(
        title: new BuiltReduxLocalizations().appTitle,
        theme: ArchSampleTheme.theme,
        localizationsDelegates: [
          new ArchSampleLocalizationsDelegate(),
          new BuiltReduxLocalizationsDelegate(),
        ],
        routes: {
          ArchSampleRoutes.home: (context) {
62
            return new HomeScreen(key: ArchSampleKeys.homeScreen);
63 64 65 66 67 68 69 70 71
          },
          ArchSampleRoutes.addTodo: (context) {
            return new AddTodo();
          },
        },
      ),
    );
  }
}