Created
July 10, 2020 02:52
-
-
Save khoasvn/0bf419da6b166af391c3d36b0a077f73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class _HomeScreenState extends State<HomeScreen> { | |
| Widget _appBar; | |
| Widget _appBody; | |
| MenuBloc _menuBloc; | |
| List<TabItem> _tabItems = [ | |
| TabItem(icon: Icons.contacts, title: 'Contacts'), | |
| TabItem(icon: Icons.rate_review, title: 'Review'), | |
| TabItem(icon: Icons.message, title: 'Contracts'), | |
| TabItem(icon: Icons.person, title: 'Profile'), | |
| ]; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _menuBloc = BlocProvider.of<MenuBloc>(context); | |
| _appBar = contactAppBar(); | |
| _appBody = contactBody(); | |
| } | |
| void _changeScreen(int index) { | |
| switch (index) { | |
| case 0: | |
| _updateScreen(0); | |
| _menuBloc.add(GoToContacts()); | |
| break; | |
| case 1: | |
| _updateScreen(1); | |
| _menuBloc.add(GoToReview()); | |
| break; | |
| case 3: | |
| _updateScreen(3); | |
| _menuBloc.add(GoToProfile()); | |
| break; | |
| default: | |
| _updateScreen(0); | |
| _menuBloc.add(GoToContacts()); | |
| } | |
| } | |
| void _updateScreen(int index) { | |
| setState(() { | |
| switch (index) { | |
| case 0: | |
| _appBar = contactAppBar(); | |
| _appBody = contactBody(); | |
| break; | |
| case 1: | |
| _appBar = reviewAppBar(); | |
| _appBody = reviewBody(); | |
| break; | |
| case 3: | |
| _appBar = profileAppBar(); | |
| _appBody = profileBody(); | |
| break; | |
| default: | |
| _appBar = contactAppBar(); | |
| _appBody = contactBody(); | |
| } | |
| }); | |
| } | |
| AppBar contactAppBar() { | |
| return AppBar(title: Text('Contacts')); | |
| } | |
| Widget contactBody() { | |
| return ContactScreen(userRepository: _userRepository); | |
| } | |
| AppBar reviewAppBar() { | |
| return AppBar(title: Text('Review')); | |
| } | |
| Widget reviewBody() { | |
| return ReviewScreen(userRepository: _userRepository); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return BlocListener<MenuBloc, MenuState>( | |
| listener: (context, state) { | |
| if (state is MenuContacts) { | |
| _updateScreen(0); | |
| } else if (state is MenuReview) { | |
| _updateScreen(1); | |
| } else if (state is MenuContracts) { | |
| _updateScreen(2); | |
| } else if (state is MenuProfile) { | |
| _updateScreen(3); | |
| } | |
| }, | |
| child: Scaffold( | |
| appBar: _appBar, | |
| body: _appBody, | |
| bottomNavigationBar: ConvexAppBar( | |
| key: CBKey.bottomNav, | |
| backgroundColor: Colors.red, | |
| style: TabStyle.react, | |
| items: _tabItems, | |
| onTap: _changeScreen, | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment