界面整合v2

This commit is contained in:
toly
2023-05-14 20:55:26 +08:00
parent 6b43f59e1e
commit 709bdcc9e5
4 changed files with 27 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ class GuessPage extends StatefulWidget {
State<GuessPage> createState() => _GuessPageState(); State<GuessPage> createState() => _GuessPageState();
} }
class _GuessPageState extends State<GuessPage> with SingleTickerProviderStateMixin{ class _GuessPageState extends State<GuessPage> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
late AnimationController controller; late AnimationController controller;
@@ -114,4 +114,7 @@ class _GuessPageState extends State<GuessPage> with SingleTickerProviderStateMix
), ),
); );
} }
@override
bool get wantKeepAlive => true;
} }

View File

@@ -23,7 +23,7 @@ class MuyuPage extends StatefulWidget {
State<MuyuPage> createState() => _MuyuPageState(); State<MuyuPage> createState() => _MuyuPageState();
} }
class _MuyuPageState extends State<MuyuPage> { class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin {
int _counter = 0; int _counter = 0;
MeritRecord? _cruRecord; MeritRecord? _cruRecord;
@@ -174,4 +174,7 @@ class _MuyuPageState extends State<MuyuPage> {
maxPlayers: 1, maxPlayers: 1,
); );
} }
@override
bool get wantKeepAlive => true;
} }

View File

@@ -14,6 +14,7 @@ class AppNavigation extends StatefulWidget {
class _AppNavigationState extends State<AppNavigation> { class _AppNavigationState extends State<AppNavigation> {
int _index = 0; int _index = 0;
final PageController _ctrl = PageController();
final List<MenuData> menus = const [ final List<MenuData> menus = const [
MenuData(label: '猜数字', icon: Icons.question_mark), MenuData(label: '猜数字', icon: Icons.question_mark),
@@ -26,7 +27,7 @@ class _AppNavigationState extends State<AppNavigation> {
return Column( return Column(
children: [ children: [
Expanded( Expanded(
child: _buildContent(_index), child: _buildContent(),
), ),
AppBottomBar( AppBottomBar(
currentIndex: _index, currentIndex: _index,
@@ -38,22 +39,22 @@ class _AppNavigationState extends State<AppNavigation> {
} }
void _onChangePage(int index) { void _onChangePage(int index) {
_ctrl.jumpToPage(index);
setState(() { setState(() {
_index = index; _index = index;
}); });
} }
Widget _buildContent(int index) { Widget _buildContent() {
switch(index){ return PageView(
case 0: physics: const NeverScrollableScrollPhysics(),
return const GuessPage(); controller: _ctrl,
case 1: children: const [
return const MuyuPage(); GuessPage(),
case 2: MuyuPage(),
return const Paper(); Paper(),
default: ],
return const SizedBox.shrink(); );
}
} }
} }

View File

@@ -16,7 +16,12 @@ class Paper extends StatefulWidget {
State<Paper> createState() => _PaperState(); State<Paper> createState() => _PaperState();
} }
class _PaperState extends State<Paper> { class _PaperState extends State<Paper> with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
List<Line> _lines = []; // 线列表 List<Line> _lines = []; // 线列表
int _activeColorIndex = 0; // 颜色激活索引 int _activeColorIndex = 0; // 颜色激活索引