This commit is contained in:
vipg
2025-11-15 16:43:46 +08:00
parent d6bb904e64
commit 8c73afd3aa

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; // 如需退出应用可能需要
import 'package:flutter/services.dart';
class HomePage extends StatelessWidget {
// 功能列表数据
@@ -12,13 +12,17 @@ class HomePage extends StatelessWidget {
{'icon': Icons.settings, 'title': '设置'},
{'icon': Icons.help, 'title': '帮助中心'},
{'icon': Icons.share, 'title': '分享'},
// 可以添加更多项测试滚动
{'icon': Icons.accessibility, 'title': '无障碍'},
{'icon': Icons.add_alert, 'title': '提醒'},
{'icon': Icons.book, 'title': '书籍'},
{'icon': Icons.camera, 'title': '相机'},
];
HomePage({super.key});
// 退出登录方法
void _logout(BuildContext context) async {
// 显示确认对话框
final result = await showDialog(
context: context,
builder: (context) => AlertDialog(
@@ -37,17 +41,9 @@ class HomePage extends StatelessWidget {
),
);
// 如果用户确认退出
if (result == true) {
// 这里可以添加清除用户登录状态的逻辑
// 例如清除本地存储的token等
// 返回登录页面(假设登录页路由为'/login'
// 替换当前导航栈,避免返回时回到主页
// 清除用户登录状态的逻辑
Navigator.pushReplacementNamed(context, '/login');
// 如果需要完全退出应用,可以使用:
// SystemNavigator.pop();
}
}
@@ -56,16 +52,13 @@ class HomePage extends StatelessWidget {
final theme = Theme.of(context);
return Scaffold(
// 适配主题的AppBar
appBar: AppBar(
title: const Text('功能列表'),
centerTitle: true,
elevation: 4,
shadowColor: Colors.black12,
backgroundColor: theme.colorScheme.surfaceContainerHighest,
// 移除左上角返回按钮
automaticallyImplyLeading: false,
// 右上角添加退出登录按钮
actions: [
TextButton(
onPressed: () => _logout(context),
@@ -77,40 +70,46 @@ class HomePage extends StatelessWidget {
),
),
),
const SizedBox(width: 8), // 右侧间距
const SizedBox(width: 8),
],
),
// 使用主题背景色
body: Container(
color: theme.colorScheme.surface,
child: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 8),
itemCount: features.length,
// 确保列表始终可滚动并支持iOS弹性效果
physics: const AlwaysScrollableScrollPhysics(
parent: BouncingScrollPhysics(),
// 使用SafeArea确保内容在安全区域内
body: SafeArea(
// 使用Expanded确保ListView获得足够空间
child: Expanded(
child: Container(
color: theme.colorScheme.surface,
// 确保ListView占满可用空间
child: ListView.separated(
// 关键修复:添加内边距但不影响滚动范围
padding: const EdgeInsets.symmetric(vertical: 8),
// 确保列表有足够多的项可以滚动(已添加测试项)
itemCount: features.length,
// 增强的滚动物理效果
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics(),
),
separatorBuilder: (context, index) => Divider(
height: 1,
thickness: 1,
indent: 72,
endIndent: 16,
color: theme.dividerColor,
),
itemBuilder: (context, index) {
return _buildFeatureItem(
context: context,
icon: features[index]['icon'],
title: features[index]['title'],
);
},
),
),
// 分割线样式优化,使用主题中的分割色
separatorBuilder: (context, index) => Divider(
height: 1,
thickness: 1,
indent: 72,
endIndent: 16,
color: theme.dividerColor,
),
itemBuilder: (context, index) {
return _buildFeatureItem(
context: context,
icon: features[index]['icon'],
title: features[index]['title'],
);
},
),
),
);
}
// 功能项组件 - 优化为列表项样式
Widget _buildFeatureItem({
required BuildContext context,
required IconData icon,
@@ -122,10 +121,9 @@ class HomePage extends StatelessWidget {
color: Colors.transparent,
child: InkWell(
onTap: () {
// 可以添加点击事件
// 点击事件可以在这里添加
},
borderRadius: BorderRadius.circular(8),
// 点击水波纹颜色使用主题主色的透明版本
splashColor: theme.colorScheme.primary.withOpacity(0.1),
highlightColor: theme.colorScheme.primary.withOpacity(0.05),
child: Container(
@@ -133,7 +131,6 @@ class HomePage extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: [
// 图标容器 - 使用主题中的表面容器色
Container(
width: 40,
height: 40,
@@ -144,7 +141,6 @@ class HomePage extends StatelessWidget {
child: Icon(icon, size: 24, color: theme.colorScheme.secondary),
),
const SizedBox(width: 16),
// 标题 - 使用主题文本样式
Text(
title,
style: theme.textTheme.titleMedium?.copyWith(
@@ -153,7 +149,6 @@ class HomePage extends StatelessWidget {
),
),
const Spacer(),
// 箭头图标 - 使用主题提示色
Icon(Icons.arrow_forward_ios, size: 18, color: theme.hintColor),
],
),