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: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'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
Reference in New Issue
Block a user