SHARE
TWEET

Untitled

a guest Mar 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:todos_app_core/todos_app_core.dart';
  3. import 'package:flutter_bloc/flutter_bloc.dart';
  4. import 'package:flutter_todos/blocs/blocs.dart';
  5. import 'package:flutter_todos/widgets/widgets.dart';
  6. import 'package:flutter_todos/localization.dart';
  7. import 'package:flutter_todos/models/models.dart';
  8.  
  9. class HomeScreen extends StatefulWidget {
  10.   final void Function() onInit;
  11.  
  12.   HomeScreen({@required this.onInit}) : super(key: ArchSampleKeys.homeScreen);
  13.  
  14.   @override
  15.   _HomeScreenState createState() => _HomeScreenState();
  16. }
  17.  
  18. class _HomeScreenState extends State<HomeScreen> {
  19.   final TabBloc _tabBloc = TabBloc();
  20.   FilteredTodosBloc _filteredTodosBloc;
  21.   StatsBloc _statsBloc;
  22.  
  23.   @override
  24.   void initState() {
  25.     widget.onInit();
  26.     _filteredTodosBloc = FilteredTodosBloc(
  27.       todosBloc: BlocProvider.of<TodosBloc>(context),
  28.     );
  29.     _statsBloc = StatsBloc(
  30.       todosBloc: BlocProvider.of<TodosBloc>(context),
  31.     );
  32.     super.initState();
  33.   }
  34.  
  35.   @override
  36.   Widget build(BuildContext context) {
  37.     return BlocBuilder(
  38.       bloc: _tabBloc,
  39.       builder: (BuildContext context, AppTab activeTab) {
  40.         return BlocProviderTree(
  41.           blocProviders: [
  42.             BlocProvider<TabBloc>(bloc: _tabBloc),
  43.             BlocProvider<FilteredTodosBloc>(bloc: _filteredTodosBloc),
  44.             BlocProvider<StatsBloc>(bloc: _statsBloc),
  45.           ],
  46.           child: Scaffold(
  47.             appBar: AppBar(
  48.               title: Text(FlutterBlocLocalizations.of(context).appTitle),
  49.               actions: [
  50.                 FilterButton(visible: activeTab == AppTab.todos),
  51.                 ExtraActions(),
  52.               ],
  53.             ),
  54.             body: activeTab == AppTab.todos ? FilteredTodos() : Stats(),
  55.             floatingActionButton: FloatingActionButton(
  56.               key: ArchSampleKeys.addTodoFab,
  57.               onPressed: () {
  58.                 Navigator.pushNamed(context, ArchSampleRoutes.addTodo);
  59.               },
  60.               child: Icon(Icons.add),
  61.               tooltip: ArchSampleLocalizations.of(context).addTodo,
  62.             ),
  63.             bottomNavigationBar: TabSelector(
  64.               activeTab: activeTab,
  65.               onTabSelected: (tab) => _tabBloc.dispatch(UpdateTab(tab)),
  66.             ),
  67.           ),
  68.         );
  69.       },
  70.     );
  71.   }
  72.  
  73.   @override
  74.   void dispose() {
  75.     _statsBloc.dispose();
  76.     _filteredTodosBloc.dispose();
  77.     _tabBloc.dispose();
  78.     super.dispose();
  79.   }
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top