SHARE
TWEET

Untitled

a guest Mar 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_bloc/flutter_bloc.dart';
  3. import 'package:todos_app_core/todos_app_core.dart';
  4. import 'package:flutter_todos/blocs/filtered_todos/filtered_todos.dart';
  5. import 'package:flutter_todos/models/models.dart';
  6.  
  7. class FilterButton extends StatelessWidget {
  8.   final bool visible;
  9.  
  10.   FilterButton({this.visible, Key key}) : super(key: key);
  11.  
  12.   @override
  13.   Widget build(BuildContext context) {
  14.     final defaultStyle = Theme.of(context).textTheme.body1;
  15.     final activeStyle = Theme.of(context)
  16.         .textTheme
  17.         .body1
  18.         .copyWith(color: Theme.of(context).accentColor);
  19.     final FilteredTodosBloc filteredTodosBloc =
  20.         BlocProvider.of<FilteredTodosBloc>(context);
  21.     return BlocBuilder(
  22.         bloc: filteredTodosBloc,
  23.         builder: (BuildContext context, FilteredTodosState state) {
  24.           final button = _Button(
  25.             onSelected: (filter) {
  26.               filteredTodosBloc.dispatch(UpdateFilter(filter));
  27.             },
  28.             activeFilter: state is FilteredTodosLoaded
  29.                 ? state.activeFilter
  30.                 : VisibilityFilter.all,
  31.             activeStyle: activeStyle,
  32.             defaultStyle: defaultStyle,
  33.           );
  34.           return AnimatedOpacity(
  35.             opacity: visible ? 1.0 : 0.0,
  36.             duration: Duration(milliseconds: 150),
  37.             child: visible ? button : IgnorePointer(child: button),
  38.           );
  39.         });
  40.   }
  41. }
  42.  
  43. class _Button extends StatelessWidget {
  44.   const _Button({
  45.     Key key,
  46.     @required this.onSelected,
  47.     @required this.activeFilter,
  48.     @required this.activeStyle,
  49.     @required this.defaultStyle,
  50.   }) : super(key: key);
  51.  
  52.   final PopupMenuItemSelected<VisibilityFilter> onSelected;
  53.   final VisibilityFilter activeFilter;
  54.   final TextStyle activeStyle;
  55.   final TextStyle defaultStyle;
  56.  
  57.   @override
  58.   Widget build(BuildContext context) {
  59.     return PopupMenuButton<VisibilityFilter>(
  60.       key: ArchSampleKeys.filterButton,
  61.       tooltip: ArchSampleLocalizations.of(context).filterTodos,
  62.       onSelected: onSelected,
  63.       itemBuilder: (BuildContext context) => <PopupMenuItem<VisibilityFilter>>[
  64.             PopupMenuItem<VisibilityFilter>(
  65.               key: ArchSampleKeys.allFilter,
  66.               value: VisibilityFilter.all,
  67.               child: Text(
  68.                 ArchSampleLocalizations.of(context).showAll,
  69.                 style: activeFilter == VisibilityFilter.all
  70.                     ? activeStyle
  71.                     : defaultStyle,
  72.               ),
  73.             ),
  74.             PopupMenuItem<VisibilityFilter>(
  75.               key: ArchSampleKeys.activeFilter,
  76.               value: VisibilityFilter.active,
  77.               child: Text(
  78.                 ArchSampleLocalizations.of(context).showActive,
  79.                 style: activeFilter == VisibilityFilter.active
  80.                     ? activeStyle
  81.                     : defaultStyle,
  82.               ),
  83.             ),
  84.             PopupMenuItem<VisibilityFilter>(
  85.               key: ArchSampleKeys.completedFilter,
  86.               value: VisibilityFilter.completed,
  87.               child: Text(
  88.                 ArchSampleLocalizations.of(context).showCompleted,
  89.                 style: activeFilter == VisibilityFilter.completed
  90.                     ? activeStyle
  91.                     : defaultStyle,
  92.               ),
  93.             ),
  94.           ],
  95.       icon: Icon(Icons.filter_list),
  96.     );
  97.   }
  98. }
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
 
Top