home_page.dart
4.39 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import 'package:flutter/material.dart';
import 'package:Parlando/account/page/account_page.dart';
import 'package:Parlando/poem/page/poem_page.dart';
import 'package:Parlando/widgets/double_tap_back_exit_app.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/Parlando_localizations.dart';
import 'provider/home_provider.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> with RestorationMixin {
late List<Widget> _pageList;
final PageController _pageController = PageController();
HomeProvider provider = HomeProvider();
List<BottomNavigationBarItem>? _list;
@override
void initState() {
super.initState();
initData();
}
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
void initData() {
_pageList = [
const PoemPage(),
const AccountPage(),
];
}
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<HomeProvider>(
create: (_) => provider,
child: DoubleTapBackExitApp(
child: Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {},
tooltip: "发一言",
backgroundColor: Colors.white,
child: const Icon(
Icons.add,
color: Colors.black45,
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Consumer<HomeProvider>(
builder: (_, provider, __) {
return BottomAppBar(
color: Colors.black45,
shape: const CircularNotchedRectangle(),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: () {
_pageController.animateToPage(
0,
duration: const Duration(milliseconds: 100),
curve: Curves.easeOutSine,
);
},
child: Container(
alignment: Alignment.center,
height: 36.0,
child: Text(
ParlandoLocalizations.of(context)
.onePoemBottomNavigationBarItemTitle,
style: const TextStyle(
color: Colors.white54,
fontSize: 15.0,
),
),
),
),
InkWell(
onTap: () {
_pageController.animateToPage(
1,
duration: const Duration(milliseconds: 100),
curve: Curves.easeOutSine,
);
},
child: Container(
alignment: Alignment.center,
height: 36.0,
child: Text(
ParlandoLocalizations.of(context)
.profileBottomNavigationBarItemTitle,
style: const TextStyle(
color: Colors.white54,
fontSize: 15.0,
),
),
),
),
]),
elevation: 5.0,
);
},
),
// 使用PageView的原因参看 https://zhuanlan.zhihu.com/p/58582876
body: PageView(
physics: const NeverScrollableScrollPhysics(), // 禁止滑动
controller: _pageController,
onPageChanged: (int index) => provider.value = index,
children: _pageList,
),
),
),
);
}
@override
String? get restorationId => 'home';
@override
void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
registerForRestoration(provider, 'BottomNavigationBarCurrentIndex');
}
}