first commit

This commit is contained in:
ytc1012
2025-11-13 15:45:28 +08:00
commit 6b321890c0
54 changed files with 8412 additions and 0 deletions

View File

@@ -0,0 +1,241 @@
import 'package:flutter/material.dart';
/// 自定义时间选择器对话框
/// 用于选择小时和分钟,不会自动切换选择模式
class CustomTimePickerDialog extends StatefulWidget {
final String title;
final TimeOfDay initialTime;
const CustomTimePickerDialog({
super.key,
required this.title,
required this.initialTime,
});
@override
State<CustomTimePickerDialog> createState() => _CustomTimePickerDialogState();
/// 显示时间选择器对话框
static Future<TimeOfDay?> show({
required BuildContext context,
required String title,
required TimeOfDay initialTime,
}) async {
return await showDialog<TimeOfDay>(
context: context,
builder: (context) => CustomTimePickerDialog(
title: title,
initialTime: initialTime,
),
);
}
}
class _CustomTimePickerDialogState extends State<CustomTimePickerDialog> {
late int _hours;
late int _minutes;
@override
void initState() {
super.initState();
_hours = widget.initialTime.hour;
_minutes = widget.initialTime.minute;
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return AlertDialog(
title: Text(widget.title),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// 小时选择
Column(
children: [
Text('小时', style: theme.textTheme.bodySmall),
const SizedBox(height: 8),
Row(
children: [
IconButton(
icon: const Icon(Icons.remove_circle_outline),
onPressed: () {
setState(() {
if (_hours > 0) {
_hours--;
} else {
_hours = 23;
}
});
},
),
Container(
width: 60,
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer.withOpacity(0.3),
borderRadius: BorderRadius.circular(8),
),
child: Text(
'$_hours',
textAlign: TextAlign.center,
style: theme.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
IconButton(
icon: const Icon(Icons.add_circle_outline),
onPressed: () {
setState(() {
if (_hours < 23) {
_hours++;
} else {
_hours = 0;
}
});
},
),
],
),
],
),
const SizedBox(width: 24),
// 分隔符
Text(
':',
style: theme.textTheme.headlineLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 24),
// 分钟选择
Column(
children: [
Text('分钟', style: theme.textTheme.bodySmall),
const SizedBox(height: 8),
Row(
children: [
IconButton(
icon: const Icon(Icons.remove_circle_outline),
onPressed: () {
setState(() {
if (_minutes >= 15) {
_minutes -= 15;
} else if (_minutes > 0) {
_minutes = 0;
} else {
_minutes = 45;
}
});
},
),
Container(
width: 60,
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: theme.colorScheme.secondaryContainer.withOpacity(0.3),
borderRadius: BorderRadius.circular(8),
),
child: Text(
_minutes.toString().padLeft(2, '0'),
textAlign: TextAlign.center,
style: theme.textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
IconButton(
icon: const Icon(Icons.add_circle_outline),
onPressed: () {
setState(() {
_minutes += 15;
if (_minutes >= 60) {
_minutes = 0;
}
});
},
),
],
),
],
),
],
),
const SizedBox(height: 16),
// 快速选择按钮
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.center,
children: [
_buildQuickTimeButton(context, theme, '00:00', 0, 0),
_buildQuickTimeButton(context, theme, '08:00', 8, 0),
_buildQuickTimeButton(context, theme, '12:00', 12, 0),
_buildQuickTimeButton(context, theme, '18:00', 18, 0),
_buildQuickTimeButton(context, theme, '20:00', 20, 0),
_buildQuickTimeButton(context, theme, '22:00', 22, 0),
],
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop(
TimeOfDay(hour: _hours, minute: _minutes),
);
},
child: const Text('确定'),
),
],
);
}
Widget _buildQuickTimeButton(
BuildContext context,
ThemeData theme,
String label,
int hours,
int minutes,
) {
final isSelected = _hours == hours && _minutes == minutes;
return OutlinedButton(
onPressed: () {
setState(() {
_hours = hours;
_minutes = minutes;
});
},
style: OutlinedButton.styleFrom(
backgroundColor: isSelected
? theme.colorScheme.primaryContainer.withOpacity(0.3)
: null,
side: BorderSide(
color: isSelected
? theme.colorScheme.primary
: theme.colorScheme.outline.withOpacity(0.5),
width: isSelected ? 2 : 1,
),
),
child: Text(
label,
style: TextStyle(
fontSize: 12,
color: isSelected
? theme.colorScheme.primary
: theme.colorScheme.onSurface,
),
),
);
}
}

View File

@@ -0,0 +1,149 @@
import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
/// 空状态组件
/// 用于显示无数据时的友好提示
class EmptyStateWidget extends StatelessWidget {
final IconData icon;
final String title;
final String? subtitle;
final String? actionLabel;
final VoidCallback? onAction;
final bool showIllustration;
const EmptyStateWidget({
super.key,
required this.icon,
required this.title,
this.subtitle,
this.actionLabel,
this.onAction,
this.showIllustration = true,
});
/// 默认空状态 - 无数据
factory EmptyStateWidget.noData({
String? title,
String? subtitle,
String? actionLabel,
VoidCallback? onAction,
}) {
return EmptyStateWidget(
icon: Icons.inbox_outlined,
title: title ?? '暂无数据',
subtitle: subtitle ?? '使用应用一段时间后,数据将显示在这里',
actionLabel: actionLabel,
onAction: onAction,
);
}
/// 空状态 - 无搜索结果
factory EmptyStateWidget.noSearchResults({
String? query,
}) {
return EmptyStateWidget(
icon: Icons.search_off,
title: '未找到匹配结果',
subtitle: query != null ? '没有找到与 "$query" 相关的内容' : '请尝试其他关键词',
showIllustration: false,
);
}
/// 空状态 - 无应用数据
factory EmptyStateWidget.noApps({
VoidCallback? onAction,
}) {
return EmptyStateWidget(
icon: Icons.apps_outlined,
title: '暂无应用数据',
subtitle: '使用应用一段时间后,应用使用记录将显示在这里',
actionLabel: '刷新',
onAction: onAction,
);
}
/// 空状态 - 首次使用
factory EmptyStateWidget.firstTime({
VoidCallback? onAction,
}) {
return EmptyStateWidget(
icon: Icons.touch_app,
title: '欢迎使用 AutoTime Tracker',
subtitle: '开始追踪您的时间使用情况\n\n1. 授予应用使用权限\n2. 正常使用您的设备\n3. 查看详细的使用统计',
actionLabel: '去设置权限',
onAction: onAction,
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (showIllustration) ...[
Container(
width: 120,
height: 120,
decoration: BoxDecoration(
color: AppTheme.primaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
icon,
size: 64,
color: AppTheme.primaryColor.withOpacity(0.6),
),
),
const SizedBox(height: 24),
] else ...[
Icon(
icon,
size: 64,
color: theme.colorScheme.onSurface.withOpacity(0.3),
),
const SizedBox(height: 16),
],
Text(
title,
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.onSurface,
),
textAlign: TextAlign.center,
),
if (subtitle != null) ...[
const SizedBox(height: 12),
Text(
subtitle!,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
),
],
if (actionLabel != null && onAction != null) ...[
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: onAction,
icon: const Icon(Icons.refresh),
label: Text(actionLabel!),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
),
),
],
],
),
),
);
}
}

View File

@@ -0,0 +1,141 @@
import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
/// 错误状态组件
/// 用于显示错误时的友好提示
class ErrorStateWidget extends StatelessWidget {
final String? title;
final String? message;
final String? actionLabel;
final VoidCallback? onRetry;
final IconData icon;
final bool showDetails;
const ErrorStateWidget({
super.key,
this.title,
this.message,
this.actionLabel,
this.onRetry,
this.icon = Icons.error_outline,
this.showDetails = false,
});
/// 默认错误状态
factory ErrorStateWidget.generic({
String? message,
VoidCallback? onRetry,
}) {
return ErrorStateWidget(
title: '加载失败',
message: message ?? '请检查网络连接后重试',
actionLabel: '重试',
onRetry: onRetry,
);
}
/// 权限错误
factory ErrorStateWidget.permission({
VoidCallback? onRetry,
}) {
return ErrorStateWidget(
icon: Icons.security,
title: '权限未授予',
message: '需要授予应用使用权限才能追踪时间\n\n请在系统设置中开启"使用情况访问权限"',
actionLabel: '去设置',
onRetry: onRetry,
);
}
/// 网络错误
factory ErrorStateWidget.network({
VoidCallback? onRetry,
}) {
return ErrorStateWidget(
icon: Icons.wifi_off,
title: '网络连接失败',
message: '无法连接到服务器\n\n请检查网络连接后重试',
actionLabel: '重试',
onRetry: onRetry,
);
}
/// 数据加载错误
factory ErrorStateWidget.dataLoad({
String? message,
VoidCallback? onRetry,
}) {
return ErrorStateWidget(
icon: Icons.cloud_off,
title: '数据加载失败',
message: message ?? '无法加载数据,请稍后重试',
actionLabel: '重试',
onRetry: onRetry,
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: AppTheme.errorColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
icon,
size: 56,
color: AppTheme.errorColor,
),
),
const SizedBox(height: 24),
Text(
title ?? '出错了',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.error,
),
textAlign: TextAlign.center,
),
if (message != null) ...[
const SizedBox(height: 12),
Text(
message!,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurface.withOpacity(0.7),
),
textAlign: TextAlign.center,
),
],
if (actionLabel != null && onRetry != null) ...[
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: onRetry,
icon: const Icon(Icons.refresh),
label: Text(actionLabel!),
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.errorColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
),
),
],
],
),
),
);
}
}