11import 'package:easy_localization/easy_localization.dart' ;
22import 'package:escape_wild/core/index.dart' ;
3+ import 'package:escape_wild/design/adaptive_navigation.dart' ;
34import 'package:escape_wild/foundation.dart' ;
45import 'package:escape_wild/game/serialization.dart' ;
56import 'package:escape_wild/generated/icons.dart' ;
6- import 'package:escape_wild/ui/game/backpack/backpack.dart' ;
77import 'package:flutter/material.dart' ;
8- import 'package:flutter/services.dart' ;
98import 'package:go_router/go_router.dart' ;
109import 'package:rettulf/rettulf.dart' ;
11- import 'action/action.dart' ;
12- import 'camp/camp.dart' ;
13- import 'craft/craft.dart' ;
1410
1511part 'index.i18n.dart' ;
1612
1713class GameIndexPage extends StatefulWidget {
18- const GameIndexPage ({super .key});
14+ final StatefulNavigationShell navigationShell;
15+
16+ const GameIndexPage ({
17+ super .key,
18+ required this .navigationShell,
19+ });
1920
2021 @override
2122 State <GameIndexPage > createState () => _HomePageState ();
2223}
2324
24- class _P {
25- _P ._();
26-
27- static const action = 0 ;
28- static const backpack = 1 ;
29- static const craft = 2 ;
30- static const camp = 3 ;
31- static const pageCount = 4 ;
32- }
33-
3425class _HomePageState extends State <GameIndexPage > {
35- var curIndex = _P .action;
36-
3726 @override
3827 Widget build (BuildContext context) {
3928 return PopScope (
@@ -57,26 +46,43 @@ class _HomePageState extends State<GameIndexPage> {
5746 context.pop ();
5847 }
5948 },
60- child: KeyboardListener (
61- focusNode: focusNode,
62- autofocus: true ,
63- onKeyEvent: onKeyEvent,
64- child: player >>
65- (_) => [
66- buildMain (),
67- buildEnvColorCover (),
68- ].stack (),
69- ),
49+ child: player >>
50+ (_) => [
51+ buildMain (),
52+ buildEnvColorCover (),
53+ ].stack (),
7054 );
7155 }
7256
7357 Widget buildMain () {
74- return Scaffold (
75- body: AnimatedSwitcher (
76- duration: const Duration (milliseconds: 200 ),
77- child: buildBody (),
78- ),
79- bottomNavigationBar: buildBottom (),
58+ return AdaptiveNavigationScaffold (
59+ navigationShell: widget.navigationShell,
60+ items: [
61+ (
62+ route: "/action" ,
63+ icon: Icons .grid_view_outlined,
64+ activeIcon: Icons .grid_view_sharp,
65+ label: _I .action,
66+ ),
67+ (
68+ route: "/backpack" ,
69+ icon: Icons .backpack_outlined,
70+ activeIcon: Icons .backpack,
71+ label: _I .backpack,
72+ ),
73+ (
74+ route: "/craft" ,
75+ icon: Icons .build_outlined,
76+ activeIcon: Icons .build,
77+ label: _I .craft,
78+ ),
79+ (
80+ route: "/camp" ,
81+ icon: IconsX .camping_outlined,
82+ activeIcon: IconsX .camping,
83+ label: _I .camp,
84+ ),
85+ ],
8086 );
8187 }
8288
@@ -97,75 +103,4 @@ class _HomePageState extends State<GameIndexPage> {
97103 duration: const Duration (milliseconds: 100 ),
98104 );
99105 }
100-
101- Widget buildBottom () {
102- return BottomNavigationBar (
103- type: BottomNavigationBarType .fixed,
104- landscapeLayout: BottomNavigationBarLandscapeLayout .centered,
105- currentIndex: curIndex,
106- onTap: (newIndex) {
107- if (newIndex != curIndex) {
108- setState (() {
109- curIndex = newIndex;
110- });
111- }
112- },
113- items: [
114- BottomNavigationBarItem (
115- label: _I .action,
116- icon: const Icon (Icons .grid_view_outlined),
117- activeIcon: const Icon (Icons .grid_view_sharp),
118- ),
119- BottomNavigationBarItem (
120- label: _I .backpack,
121- icon: const Icon (Icons .backpack_outlined),
122- activeIcon: const Icon (Icons .backpack),
123- ),
124- BottomNavigationBarItem (
125- label: _I .craft,
126- icon: const Icon (Icons .build_outlined),
127- activeIcon: const Icon (Icons .build),
128- ),
129- BottomNavigationBarItem (
130- label: _I .camp,
131- icon: const Icon (IconsX .camping_outlined),
132- activeIcon: const Icon (IconsX .camping),
133- ),
134- ],
135- );
136- }
137-
138- final focusNode = FocusNode ();
139-
140- Widget buildBody () {
141- if (curIndex == _P .action) {
142- return ActionPage ();
143- } else if (curIndex == _P .backpack) {
144- return BackpackPage ();
145- } else if (curIndex == _P .craft) {
146- return CraftPage ();
147- } else {
148- return CampPage ();
149- }
150- }
151-
152- void onKeyEvent (KeyEvent k) {
153- if (k is KeyDownEvent ) {
154- if (k.character == "z" ) {
155- setState (() {
156- curIndex = (curIndex - 1 ) % _P .pageCount;
157- });
158- } else if (k.character == "x" ) {
159- setState (() {
160- curIndex = (curIndex + 1 ) % _P .pageCount;
161- });
162- }
163- }
164- }
165-
166- @override
167- void dispose () {
168- focusNode.dispose ();
169- super .dispose ();
170- }
171106}
0 commit comments