51 lines
1.3 KiB
Dart
51 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'com/xiaoyan/main/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(
|
|
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: '/',
|
|
builder: (context, state) => const HomePage(),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|