feat: align shared app foundations
This commit is contained in:
1 parent
bd6bb0ffce
commit
c5653a3699
21 files changed
+894
-66
No files matched your search
@@ -54,22 +54,43 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
ShellRoute(
|
||||
builder: (context, state, child) =>
|
||||
TabShell(location: state.matchedLocation, child: child),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.assets,
|
||||
builder: (ctx, s) => const AssetsPage(),
|
||||
StatefulShellRoute.indexedStack(
|
||||
builder: (context, state, navigationShell) => TabShell(
|
||||
location: state.matchedLocation,
|
||||
navigationShell: navigationShell,
|
||||
),
|
||||
branches: [
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.assets,
|
||||
builder: (ctx, s) => const AssetsPage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: AppRoutes.market,
|
||||
builder: (ctx, s) => const MarketPage(),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.market,
|
||||
builder: (ctx, s) => const MarketPage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
GoRoute(path: AppRoutes.news, builder: (ctx, s) => const NewsPage()),
|
||||
GoRoute(
|
||||
path: AppRoutes.profile,
|
||||
builder: (ctx, s) => const ProfilePage(),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.news,
|
||||
builder: (ctx, s) => const NewsPage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
StatefulShellBranch(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: AppRoutes.profile,
|
||||
builder: (ctx, s) => const ProfilePage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -8,9 +8,13 @@ import '../widgets/adaptive.dart';
|
||||
import 'app_router.dart';
|
||||
|
||||
class TabShell extends StatefulWidget {
|
||||
const TabShell({super.key, required this.child, required this.location});
|
||||
const TabShell({
|
||||
super.key,
|
||||
required this.navigationShell,
|
||||
required this.location,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final StatefulNavigationShell navigationShell;
|
||||
final String location;
|
||||
|
||||
@override
|
||||
@@ -22,10 +26,7 @@ class _TabShellState extends State<TabShell> {
|
||||
|
||||
bool _showCompactHeader = false;
|
||||
|
||||
static const _tabs = ['/assets', '/market', '/news', '/profile'];
|
||||
|
||||
int get _index =>
|
||||
_tabs.indexWhere((t) => widget.location.startsWith(t)).clamp(0, 3);
|
||||
int get _index => widget.navigationShell.currentIndex;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant TabShell oldWidget) {
|
||||
@@ -104,7 +105,7 @@ class _TabShellState extends State<TabShell> {
|
||||
color: cs.background,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: _handleScrollNotification,
|
||||
child: Stack(children: [Positioned.fill(child: widget.child)]),
|
||||
child: widget.navigationShell,
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
@@ -129,7 +130,7 @@ class _TabShellState extends State<TabShell> {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
for (var i = 0; i < _tabs.length; i++)
|
||||
for (var i = 0; i < _labels.length; i++)
|
||||
Expanded(
|
||||
child: _TabButton(
|
||||
icon: i == _index
|
||||
@@ -137,7 +138,11 @@ class _TabShellState extends State<TabShell> {
|
||||
: _outlineIcons[i],
|
||||
label: _labels[i],
|
||||
selected: i == _index,
|
||||
onTap: () => context.go(_tabs[i]),
|
||||
onTap: () =>
|
||||
widget.navigationShell.goBranch(
|
||||
i,
|
||||
initialLocation: i == _index,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user