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

View File

@@ -1,13 +0,0 @@
import 'package:flutter/material.dart';
class LoginPage extends StatelessWidget {
const LoginPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Login')),
body: Center(child: Text('Login Page')),
);
}
}

10
lib/views/HomePage.dart Normal file
View File

@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(body: Center(child: Text("Home")));
}
}

66
lib/views/LoginPage.dart Normal file
View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:flutter/widget_previews.dart';
import 'package:go_router/go_router.dart';
class LoginPage extends StatelessWidget {
const LoginPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('登录')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text('登录', style: TextStyle(fontSize: 24)),
const SizedBox(height: 16),
Row(
children: [
Expanded(flex: 1, child: const Text('用户名:')),
const SizedBox(width: 8),
Expanded(
flex: 4,
child: TextField(
decoration: const InputDecoration(hintText: '请输入用户名'),
),
),
],
),
Row(
children: [
Expanded(flex: 1, child: const Text('密码:')),
const SizedBox(width: 8),
Expanded(
flex: 4,
child: TextField(
decoration: const InputDecoration(hintText: '请输入密码'),
obscureText: true,
),
),
],
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
context.go('/home');
},
style: ElevatedButton.styleFrom(
minimumSize: const Size(double.infinity, 48),
),
child: const Text('登录'),
),
],
),
),
);
}
}
// ========== 组件预览(顶层函数) ==========
@Preview(name: 'LoginPage 默认状态')
Widget loginPagePreview() => const LoginPage();

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'com/xiaoyan/main/LoginPage.dart';
import 'HomePage.dart';
import 'LoginPage.dart';
void main() {
runApp(MainApp());
@@ -16,6 +17,7 @@ class MainApp extends StatelessWidget {
}
final _route = GoRouter(
initialLocation: '/login',
routes: <RouteBase>[
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
StatefulShellRoute.indexedStack(
@@ -38,11 +40,19 @@ class MainApp extends StatelessWidget {
StatefulShellBranch(
routes: <RouteBase>[
GoRoute(
path: '/',
path: '/home',
builder: (context, state) => const HomePage(),
),
],
),
StatefulShellBranch(
routes: <RouteBase>[
GoRoute(
path: '/settings',
builder: (context, state) => const Text('Settings'),
),
],
),
],
),
],

View File

@@ -80,6 +80,22 @@ packages:
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "17.3.0"
http:
dependency: "direct overridden"
description:
name: http
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "1.6.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "4.1.2"
leak_tracker:
dependency: transitive
description:
@@ -205,6 +221,14 @@ packages:
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "0.7.10"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "1.4.0"
vector_math:
dependency: transitive
description:
@@ -221,6 +245,14 @@ packages:
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "15.2.0"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://mirror.sjtu.edu.cn/dart-pub/"
source: hosted
version: "1.1.1"
sdks:
dart: ">=3.11.5 <4.0.0"
flutter: ">=3.38.0"

View File

@@ -16,5 +16,8 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^6.0.0
dependency_overrides:
http: ^1.2.0
flutter:
uses-material-design: true