tab_page.dart
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wow_english/pages/home/home_page.dart';
import 'package:wow_english/pages/lessons/lesson_page.dart';
import 'blocs/tab_bloc.dart';
class TabPage extends StatelessWidget {
const TabPage({super.key});
final _pages =const <Widget>[
HomePage(),
LessonPage()
];
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();
}