💄 Optimized tab router

This commit is contained in:
LittleSheep 2025-04-25 00:36:32 +08:00
parent 057ab16381
commit 7b8ee81f03
6 changed files with 116 additions and 79 deletions

View File

@ -9,15 +9,13 @@ class AppRouter extends RootStackRouter {
@override
List<AutoRoute> get routes => [
AutoRoute(
page: ExploreRoute.page,
page: TabsRoute.page,
path: '/',
meta: {'bottomNav': true},
initial: true,
),
AutoRoute(
page: AccountRoute.page,
path: '/account',
meta: {'bottomNav': true},
children: [
AutoRoute(page: ExploreRoute.page, path: 'explore'),
AutoRoute(page: AccountRoute.page, path: 'account'),
],
),
AutoRoute(page: LoginRoute.page, path: '/auth/login'),
AutoRoute(page: CreateAccountRoute.page, path: '/auth/create-account'),

View File

@ -9,21 +9,22 @@
// coverage:ignore-file
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:auto_route/auto_route.dart' as _i5;
import 'package:auto_route/auto_route.dart' as _i6;
import 'package:island/screens/account.dart' as _i1;
import 'package:island/screens/auth/create_account.dart' as _i2;
import 'package:island/screens/auth/login.dart' as _i4;
import 'package:island/screens/auth/tabs.dart' as _i5;
import 'package:island/screens/explore.dart' as _i3;
/// generated route for
/// [_i1.AccountScreen]
class AccountRoute extends _i5.PageRouteInfo<void> {
const AccountRoute({List<_i5.PageRouteInfo>? children})
class AccountRoute extends _i6.PageRouteInfo<void> {
const AccountRoute({List<_i6.PageRouteInfo>? children})
: super(AccountRoute.name, initialChildren: children);
static const String name = 'AccountRoute';
static _i5.PageInfo page = _i5.PageInfo(
static _i6.PageInfo page = _i6.PageInfo(
name,
builder: (data) {
return const _i1.AccountScreen();
@ -33,13 +34,13 @@ class AccountRoute extends _i5.PageRouteInfo<void> {
/// generated route for
/// [_i2.CreateAccountScreen]
class CreateAccountRoute extends _i5.PageRouteInfo<void> {
const CreateAccountRoute({List<_i5.PageRouteInfo>? children})
class CreateAccountRoute extends _i6.PageRouteInfo<void> {
const CreateAccountRoute({List<_i6.PageRouteInfo>? children})
: super(CreateAccountRoute.name, initialChildren: children);
static const String name = 'CreateAccountRoute';
static _i5.PageInfo page = _i5.PageInfo(
static _i6.PageInfo page = _i6.PageInfo(
name,
builder: (data) {
return const _i2.CreateAccountScreen();
@ -49,13 +50,13 @@ class CreateAccountRoute extends _i5.PageRouteInfo<void> {
/// generated route for
/// [_i3.ExploreScreen]
class ExploreRoute extends _i5.PageRouteInfo<void> {
const ExploreRoute({List<_i5.PageRouteInfo>? children})
class ExploreRoute extends _i6.PageRouteInfo<void> {
const ExploreRoute({List<_i6.PageRouteInfo>? children})
: super(ExploreRoute.name, initialChildren: children);
static const String name = 'ExploreRoute';
static _i5.PageInfo page = _i5.PageInfo(
static _i6.PageInfo page = _i6.PageInfo(
name,
builder: (data) {
return const _i3.ExploreScreen();
@ -65,16 +66,32 @@ class ExploreRoute extends _i5.PageRouteInfo<void> {
/// generated route for
/// [_i4.LoginScreen]
class LoginRoute extends _i5.PageRouteInfo<void> {
const LoginRoute({List<_i5.PageRouteInfo>? children})
class LoginRoute extends _i6.PageRouteInfo<void> {
const LoginRoute({List<_i6.PageRouteInfo>? children})
: super(LoginRoute.name, initialChildren: children);
static const String name = 'LoginRoute';
static _i5.PageInfo page = _i5.PageInfo(
static _i6.PageInfo page = _i6.PageInfo(
name,
builder: (data) {
return const _i4.LoginScreen();
},
);
}
/// generated route for
/// [_i5.TabsScreen]
class TabsRoute extends _i6.PageRouteInfo<void> {
const TabsRoute({List<_i6.PageRouteInfo>? children})
: super(TabsRoute.name, initialChildren: children);
static const String name = 'TabsRoute';
static _i6.PageInfo page = _i6.PageInfo(
name,
builder: (data) {
return const _i5.TabsScreen();
},
);
}

View File

@ -0,0 +1,39 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:island/route.gr.dart';
import 'package:lucide_icons/lucide_icons.dart';
@RoutePage()
class TabsScreen extends StatelessWidget {
const TabsScreen({super.key});
@override
Widget build(BuildContext context) {
return AutoTabsRouter.pageView(
routes: const [ExploreRoute(), AccountRoute()],
builder: (context, child, _) {
final tabsRouter = AutoTabsRouter.of(context);
return Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
backgroundColor: Colors.transparent,
body: child,
bottomNavigationBar: NavigationBar(
selectedIndex: tabsRouter.activeIndex,
onDestinationSelected: tabsRouter.setActiveIndex,
destinations: [
NavigationDestination(
label: 'Explore',
icon: const Icon(LucideIcons.compass),
),
NavigationDestination(
label: 'Account',
icon: const Icon(LucideIcons.userCircle),
),
],
),
);
},
);
}
}

View File

@ -4,11 +4,8 @@ import 'package:auto_route/auto_route.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:island/route.dart';
import 'package:island/route.gr.dart';
import 'package:lucide_icons/lucide_icons.dart';
import 'package:path_provider/path_provider.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -82,54 +79,7 @@ class WindowScaffold extends StatelessWidget {
);
}
return Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
backgroundColor: Colors.transparent,
body: SizedBox.expand(child: child),
key: rootScaffoldKey,
bottomNavigationBar:
router.current.meta['bottomNav'] == true || router.currentPath == '/'
? AppBottomNavigationBar(router: router)
: null,
);
}
}
class AppBottomNavigationBar extends HookConsumerWidget {
const AppBottomNavigationBar({super.key, required this.router});
final AppRouter router;
@override
Widget build(BuildContext context, WidgetRef ref) {
final destination = useState(0);
return NavigationBar(
selectedIndex: destination.value,
destinations: [
NavigationDestination(
icon: Icon(LucideIcons.compass),
label: 'Explore',
),
NavigationDestination(
icon: Icon(LucideIcons.userCircle),
label: 'Account',
),
],
onDestinationSelected: (idx) {
switch (idx) {
case 0:
destination.value = idx;
router.replace(ExploreRoute());
break;
case 1:
destination.value = idx;
router.replace(AccountRoute());
break;
}
},
);
return child;
}
}

View File

@ -13,10 +13,10 @@ packages:
dependency: transitive
description:
name: analyzer
sha256: f4c21c94eb4623b183c1014a470196b3910701bea9b926e6c91270d756e6fc60
sha256: "13c1e6c6fd460522ea840abec3f677cc226f5fec7872c04ad7b425517ccf54f7"
url: "https://pub.dev"
source: hosted
version: "7.4.1"
version: "7.4.4"
animations:
dependency: "direct main"
description:
@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: archive
sha256: a7f37ff061d7abc2fcf213554b9dcaca713c5853afa5c065c44888bc9ccaf813
sha256: "2fde1607386ab523f7a36bb3e7edb43bd58e6edaf2ffb29d8a6d578b297fdbbd"
url: "https://pub.dev"
source: hosted
version: "4.0.6"
version: "4.0.7"
args:
dependency: transitive
description:
@ -249,6 +249,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.2"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670"
url: "https://pub.dev"
source: hosted
version: "0.3.4+2"
crypto:
dependency: transitive
description:
@ -378,10 +386,10 @@ packages:
dependency: "direct main"
description:
name: flutter_blurhash
sha256: d472467141a279885be558335fe36a782e515f96cc5e372eee2c558ff2c2fb39
sha256: e97b9aff13b9930bbaa74d0d899fec76e3f320aba3190322dcc5d32104e3d25d
url: "https://pub.dev"
source: hosted
version: "0.9.0"
version: "0.9.1"
flutter_cache_manager:
dependency: "direct main"
description:
@ -1162,6 +1170,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.1"
speed_test_dart:
dependency: transitive
description:
name: speed_test_dart
sha256: "4131faa68d5c9259766626450a10e552bc11ff6e651bb6377cc56476443e1cfa"
url: "https://pub.dev"
source: hosted
version: "1.0.5+0"
sprintf:
dependency: transitive
description:
@ -1258,6 +1274,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.1"
sync:
dependency: transitive
description:
name: sync
sha256: f2ebb89eac969abb02b498562a35c4da63d6843396c4fe81948cd06a76845fce
url: "https://pub.dev"
source: hosted
version: "0.3.0"
synchronized:
dependency: transitive
description:
@ -1298,6 +1322,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.2"
tus_client_dart:
dependency: "direct main"
description:
name: tus_client_dart
sha256: dd6bb9f53b0c330480bbd91b7e4f46663b879f836e3b450c17a988e9dd959170
url: "https://pub.dev"
source: hosted
version: "2.5.0"
typed_data:
dependency: transitive
description:
@ -1374,10 +1406,10 @@ packages:
dependency: transitive
description:
name: url_launcher_web
sha256: "3ba963161bd0fe395917ba881d320b9c4f6dd3c4a233da62ab18a5025c85f1e9"
sha256: "4bd2b7b4dc4d4d0b94e5babfffbca8eac1a126c7f3d6ecbc1a11013faa3abba2"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
version: "2.4.1"
url_launcher_windows:
dependency: transitive
description:

View File

@ -70,6 +70,7 @@ dependencies:
package_info_plus: ^8.3.0
device_info_plus: ^11.4.0
lucide_icons: ^0.257.0
tus_client_dart: ^2.5.0
dev_dependencies:
flutter_test: