flutter架 构项目基础

This commit is contained in:
崔宝新
2026-09-04 15:22:20 +08:00
parent 70967229d0
commit 0c5aee59c0
265 changed files with 35484 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
/// 详情页
/// 独立文件 + 公开类 → 别的地方用 import 引入即可
/// 接收两种参数:构造函数参数(方式1)或命名路由 arguments(方式3)
class DetailPage extends StatelessWidget {
const DetailPage({super.key, this.name = '默认', this.age = 0});
final String name;
final int age;
@override
Widget build(BuildContext context) {
// 读取命名路由的 arguments(从 pushNamed 进来时才有)
final args = ModalRoute.of(context)?.settings.arguments;
final argMap = args is Map<String, dynamic> ? args : null;
return Scaffold(
appBar: AppBar(title: const Text('详情页')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 优先用 arguments 里的值,否则用构造函数传的值
Text(
'姓名:${argMap?['name'] ?? name}',
style: TextStyle(fontSize: 20.sp),
),
SizedBox(height: 8.h),
Text(
'年龄:${argMap?['age'] ?? age}',
style: TextStyle(fontSize: 20.sp),
),
SizedBox(height: 24.h),
// 手动 pop(AppBar 的返回箭头也是 pop)
OutlinedButton(
onPressed: () => Navigator.pop(context),
child: const Text('返回上一页'),
),
],
),
),
);
}
}