From 86a464b58f7ddf7c65ce9ce40b6c3666840efac9 Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Fri, 24 Jul 2026 18:01:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=92=8C=E8=B7=AF=E7=94=B1=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/com/xiaoyan/main/LoginPage.dart | 13 ------ lib/views/HomePage.dart | 10 +++++ lib/views/LoginPage.dart | 66 +++++++++++++++++++++++++++++ lib/{ => views}/main.dart | 14 +++++- pubspec.lock | 32 ++++++++++++++ pubspec.yaml | 3 ++ 6 files changed, 123 insertions(+), 15 deletions(-) delete mode 100644 lib/com/xiaoyan/main/LoginPage.dart create mode 100644 lib/views/HomePage.dart create mode 100644 lib/views/LoginPage.dart rename lib/{ => views}/main.dart (78%) diff --git a/lib/com/xiaoyan/main/LoginPage.dart b/lib/com/xiaoyan/main/LoginPage.dart deleted file mode 100644 index 6e82474..0000000 --- a/lib/com/xiaoyan/main/LoginPage.dart +++ /dev/null @@ -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')), - ); - } -} diff --git a/lib/views/HomePage.dart b/lib/views/HomePage.dart new file mode 100644 index 0000000..862ea39 --- /dev/null +++ b/lib/views/HomePage.dart @@ -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"))); + } +} diff --git a/lib/views/LoginPage.dart b/lib/views/LoginPage.dart new file mode 100644 index 0000000..6c516f0 --- /dev/null +++ b/lib/views/LoginPage.dart @@ -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(); diff --git a/lib/main.dart b/lib/views/main.dart similarity index 78% rename from lib/main.dart rename to lib/views/main.dart index dfbe639..459ea99 100644 --- a/lib/main.dart +++ b/lib/views/main.dart @@ -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: [ GoRoute(path: '/login', builder: (context, state) => const LoginPage()), StatefulShellRoute.indexedStack( @@ -38,11 +40,19 @@ class MainApp extends StatelessWidget { StatefulShellBranch( routes: [ GoRoute( - path: '/', + path: '/home', builder: (context, state) => const HomePage(), ), ], ), + StatefulShellBranch( + routes: [ + GoRoute( + path: '/settings', + builder: (context, state) => const Text('Settings'), + ), + ], + ), ], ), ], diff --git a/pubspec.lock b/pubspec.lock index 5f9b5a2..a9314f2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 5bad909..9c9804a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,5 +16,8 @@ dev_dependencies: sdk: flutter flutter_lints: ^6.0.0 +dependency_overrides: + http: ^1.2.0 + flutter: uses-material-design: true