feat: 添加布局和路由组件
This commit is contained in:
@@ -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
10
lib/views/HomePage.dart
Normal 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
66
lib/views/LoginPage.dart
Normal 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();
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import 'com/xiaoyan/main/LoginPage.dart';
|
import 'HomePage.dart';
|
||||||
|
import 'LoginPage.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MainApp());
|
runApp(MainApp());
|
||||||
@@ -16,6 +17,7 @@ class MainApp extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final _route = GoRouter(
|
final _route = GoRouter(
|
||||||
|
initialLocation: '/login',
|
||||||
routes: <RouteBase>[
|
routes: <RouteBase>[
|
||||||
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
|
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
|
||||||
StatefulShellRoute.indexedStack(
|
StatefulShellRoute.indexedStack(
|
||||||
@@ -38,11 +40,19 @@ class MainApp extends StatelessWidget {
|
|||||||
StatefulShellBranch(
|
StatefulShellBranch(
|
||||||
routes: <RouteBase>[
|
routes: <RouteBase>[
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/',
|
path: '/home',
|
||||||
builder: (context, state) => const HomePage(),
|
builder: (context, state) => const HomePage(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
StatefulShellBranch(
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: '/settings',
|
||||||
|
builder: (context, state) => const Text('Settings'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
32
pubspec.lock
32
pubspec.lock
@@ -80,6 +80,22 @@ packages:
|
|||||||
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "17.3.0"
|
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:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -205,6 +221,14 @@ packages:
|
|||||||
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.10"
|
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:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -221,6 +245,14 @@ packages:
|
|||||||
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
url: "https://mirror.sjtu.edu.cn/dart-pub/"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "15.2.0"
|
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:
|
sdks:
|
||||||
dart: ">=3.11.5 <4.0.0"
|
dart: ">=3.11.5 <4.0.0"
|
||||||
flutter: ">=3.38.0"
|
flutter: ">=3.38.0"
|
||||||
|
|||||||
@@ -16,5 +16,8 @@ dev_dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_lints: ^6.0.0
|
flutter_lints: ^6.0.0
|
||||||
|
|
||||||
|
dependency_overrides:
|
||||||
|
http: ^1.2.0
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|||||||
Reference in New Issue
Block a user