Blame view

lib/pages/tab/tab_page.dart 1.73 KB
2a29701f   liangchengyou   feat:提交代码
1
2
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
4b358e22   liangchengyou   feat:调整文件结构
3
4
5
6
  import 'package:wow_english/pages/home/home_page.dart';
  import 'package:wow_english/pages/lessons/lesson_page.dart';
  
  import 'blocs/tab_bloc.dart';
2a29701f   liangchengyou   feat:提交代码
7
8
9
10
11
  
  class TabPage extends StatelessWidget {
    const TabPage({super.key});
  
    final _pages =const <Widget>[
d35a4e87   liangchengyou   feat:磨耳朵功能UI
12
13
      HomePage(),
      LessonPage()
2a29701f   liangchengyou   feat:提交代码
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    ];
  
    final _tabIcons = const <Icon>[
      Icon(Icons.ac_unit),
      Icon(Icons.ac_unit_outlined)
    ];
  
    final  _tabTexts = const <String>[
      '页面1',
      '页面2'
    ];
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: _buildIndexedStack(),
        bottomNavigationBar: _buildBottomNavBars(),
      );
    }
  
    Widget _buildIndexedStack() => BlocBuilder<TabBloc,TabState>(
        builder: (context, state) => IndexedStack(
          index: state.index,
          children: _pages,
        )
    );
  
    Widget _buildBottomNavBars() => BlocBuilder<TabBloc,TabState>(
        builder: (context, state) => Container(
          decoration: BoxDecoration(
              boxShadow: <BoxShadow>[
                BoxShadow(
                    color: Theme.of(context).dividerColor,
                    blurRadius: .1
                )
              ]
          ),
          child: BottomNavigationBar(
            currentIndex: state.index,
            items: _buildBottomNavBarItems(context),
            onTap: (value) => context.read<TabBloc>().add(UpdateTabIndexEvent(value)),
          ),
        )
    );
  
    List<BottomNavigationBarItem> _buildBottomNavBarItems(BuildContext context) => _tabIcons.map((e) {
      final index = _tabIcons.indexOf(e);
      return BottomNavigationBarItem(
          label: _tabTexts[index],
          activeIcon: _tabIcons[index],
          icon: _tabIcons[index]
      );}).toList();
  }