feat: 添加布局和路由组件

This commit is contained in:
2026-07-24 18:01:12 +08:00
parent 725f911a6f
commit 86a464b58f
6 changed files with 123 additions and 15 deletions

60
lib/views/main.dart Normal file
View File

@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'HomePage.dart';
import 'LoginPage.dart';
void main() {
runApp(MainApp());
}
class MainApp extends StatelessWidget {
MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(routerConfig: _route);
}
final _route = GoRouter(
initialLocation: '/login',
routes: <RouteBase>[
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) => Scaffold(
body: navigationShell,
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Home'),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
onTap: (index) {
navigationShell.goBranch(index); // 跳转到GoRoute中定义的分支
},
),
),
branches: <StatefulShellBranch>[
StatefulShellBranch(
routes: <RouteBase>[
GoRoute(
path: '/home',
builder: (context, state) => const HomePage(),
),
],
),
StatefulShellBranch(
routes: <RouteBase>[
GoRoute(
path: '/settings',
builder: (context, state) => const Text('Settings'),
),
],
),
],
),
],
);
}