第一次提交
This commit is contained in:
6
lib/main.dart
Normal file
6
lib/main.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mydearest/routes/index.dart';
|
||||
|
||||
void main(List<String> args) {
|
||||
runApp(getRootWidget());
|
||||
}
|
||||
23
lib/pages/login/index.dart
Normal file
23
lib/pages/login/index.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
// 不清楚需求一律使用有状态组件
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoginPage> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Login"),
|
||||
),
|
||||
body: Center(
|
||||
child: Text("This is the login page."),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
22
lib/pages/main/index.dart
Normal file
22
lib/pages/main/index.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Main Page"),
|
||||
),
|
||||
body: Center(
|
||||
child: Text("This is the main page."),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
21
lib/routes/index.dart
Normal file
21
lib/routes/index.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// 管理路由
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mydearest/pages/main/index.dart';
|
||||
import 'package:mydearest/pages/login/index.dart';
|
||||
|
||||
// 返回APP根组件
|
||||
Widget getRootWidget() {
|
||||
return MaterialApp(
|
||||
routes: getRootRoutes(),
|
||||
);
|
||||
// 真正的项目都是使用的命名路由
|
||||
}
|
||||
|
||||
// 返回路由表
|
||||
Map<String, Widget Function(BuildContext)> getRootRoutes() {
|
||||
return {
|
||||
"/": (context) => MainPage(), // 主页路由
|
||||
"/login": (context) => LoginPage(), // 登录页路由
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user