我将优化页面颜色,使每个选项在视觉上同等重要,同时保持整体风格协调美观。以下是修改后的代码:
import 'package:flutter/material.dart';
import 'page_three_logic.dart';
class PageThree extends StatefulWidget {
const PageThree({super.key});
@override
PageThreeState createState() => PageThreeState();
}
class PageThreeState extends State<PageThree> {
final PageThreeLogic _logic = PageThreeLogic();
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final surfaceColor = colorScheme.surfaceContainerHighest;
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
colorScheme.surface.withOpacity(0.9),
surfaceColor.withOpacity(0.7),
],
),
),
child: SingleChildScrollView(
child: Align(
alignment: Alignment.topCenter,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: colorScheme.primaryContainer.withOpacity(0.15),
shape: BoxShape.circle,
border: Border.all(
color: colorScheme.primary.withOpacity(0.25),
width: 1.5,
),
),
child: Icon(
Icons.folder_special,
size: 48,
color: colorScheme.primary,
),
),
const SizedBox(height: 16),
Text(
'设置游戏目录',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.w700,
color: colorScheme.onSurface,
letterSpacing: 0.5,
),
),
const SizedBox(height: 8),
Text(
'请选择 Unturned 游戏的安装位置',
style: TextStyle(
fontSize: 15,
color: colorScheme.onSurfaceVariant.withOpacity(0.85),
),
),
const SizedBox(height: 32),
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: _logic.selectedGamePath != null
? _buildSelectedPathCard(colorScheme, surfaceColor)
: _buildSelectionOptions(colorScheme, surfaceColor),
),
const SizedBox(height: 24),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: surfaceColor.withOpacity(0.85),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: colorScheme.outline.withOpacity(0.15),
width: 1,
),
),
child: Row(
children: [
Icon(
Icons.info_outline_rounded,
size: 20,
color: colorScheme.primary,
),
const SizedBox(width: 12),
Expanded(
child: Text(
'需要选择包含 Unturned.exe 的游戏目录',
style: TextStyle(
fontSize: 13,
height: 1.4,
color: colorScheme.onSurfaceVariant,
),
),
),
],
),
),
],
),
),
),
),
),
),
);
}
Widget _buildSelectedPathCard(ColorScheme colorScheme, Color surfaceColor) {
return Column(
key: const ValueKey('selected-path'),
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: surfaceColor.withOpacity(0.95),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: colorScheme.primary.withOpacity(0.3),
width: 1.5,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: colorScheme.primary.withOpacity(0.9),
shape: BoxShape.circle,
),
child: Icon(
Icons.check_rounded,
color: colorScheme.onPrimary,
size: 20,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'已选择游戏目录',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
),
const SizedBox(height: 6),
Text(
_logic.selectedGamePath!,
style: TextStyle(
fontSize: 13,
height: 1.4,
color: colorScheme.onSurfaceVariant,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
icon: Icon(Icons.refresh, size: 18, color: colorScheme.onPrimary),
label: Text('重新选择', style: TextStyle(color: colorScheme.onPrimary)),
onPressed: () {
setState(() {
_logic.selectedGamePath = null;
});
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 14),
backgroundColor: colorScheme.primary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
],
),
),
],
);
}
Widget _buildSelectionOptions(ColorScheme colorScheme, Color surfaceColor) {
return Column(
key: const ValueKey('selection-options'),
children: [
_buildOptionCard(
icon: Icons.folder_open_rounded,
title: '手动选择目录',
subtitle: '浏览并选择游戏安装位置',
color: colorScheme.primary,
onPressed: () => _logic.selectGameDirectory(context, setState),
colorScheme: colorScheme,
surfaceColor: surfaceColor,
),
const SizedBox(height: 16),
_buildOptionCard(
icon: Icons.search_rounded,
title: '自动搜索',
subtitle: '扫描本地磁盘查找游戏',
color: colorScheme.secondary,
isLoading: _logic.isSearching,
onPressed:
_logic.isSearching ? null : () => _logic.autoSearchGame(setState),
colorScheme: colorScheme,
surfaceColor: surfaceColor,
),
const SizedBox(height: 16),
_buildOptionCard(
icon: Icons.memory_rounded,
title: '进程检测',
subtitle: '运行游戏后自动检测',
color: colorScheme.tertiary,
onPressed: () {},
colorScheme: colorScheme,
surfaceColor: surfaceColor,
),
],
);
}
Widget _buildOptionCard({
required IconData icon,
required String title,
required String subtitle,
required Color color,
required VoidCallback? onPressed,
required ColorScheme colorScheme,
required Color surfaceColor,
bool isLoading = false,
}) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
borderRadius: BorderRadius.circular(16),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: surfaceColor.withOpacity(0.95),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: colorScheme.outline.withOpacity(0.15),
width: 1,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 3),
),
],
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: isLoading
? SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: color,
),
)
: Icon(
icon,
color: color,
size: 24,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
),
const SizedBox(height: 4),
Text(
subtitle,
style: TextStyle(
fontSize: 13,
height: 1.4,
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
Icon(
Icons.arrow_forward_ios_rounded,
color: colorScheme.onSurfaceVariant.withOpacity(0.6),
size: 18,
),
],
),
),
),
);
}
}