Blame view

lib/pages/tab/tab_page.dart 1.71 KB
2a29701f   liangchengyou   feat:提交代码
1
2
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
5b87e560   吴启风   feat:导航栏视觉优化
3
  import 'package:wow_english/pages/module/course_module_page.dart';
4b358e22   liangchengyou   feat:调整文件结构
4
  
2187c85f   吴启风   feat:课程结构调整
5
  import '../unit/view.dart';
4b358e22   liangchengyou   feat:调整文件结构
6
  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>[
2187c85f   吴启风   feat:课程结构调整
12
      UnitPage(),
5b87e560   吴启风   feat:导航栏视觉优化
13
      CourseModulePage()
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();
  }