600 lines
18 KiB
Dart
600 lines
18 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:shared_preferences/shared_preferences.dart';
|
||
import '../../../constants/app_constants.dart';
|
||
|
||
/// 时间: 2026-03-27
|
||
/// 功能: 权限管理页面
|
||
/// 介绍: 管理应用所需权限,包括震动、网络、剪切板等
|
||
/// 最新变化: 新建权限管理页面
|
||
|
||
class PermissionPage extends StatefulWidget {
|
||
const PermissionPage({super.key});
|
||
|
||
@override
|
||
State<PermissionPage> createState() => _PermissionPageState();
|
||
}
|
||
|
||
class _PermissionPageState extends State<PermissionPage> {
|
||
bool _vibrationEnabled = true;
|
||
bool _networkEnabled = true;
|
||
bool _clipboardEnabled = true;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_loadPermissionSettings();
|
||
}
|
||
|
||
Future<void> _loadPermissionSettings() async {
|
||
final prefs = await SharedPreferences.getInstance();
|
||
setState(() {
|
||
_vibrationEnabled = prefs.getBool('vibration_enabled') ?? true;
|
||
_networkEnabled = prefs.getBool('network_enabled') ?? true;
|
||
_clipboardEnabled = prefs.getBool('clipboard_enabled') ?? true;
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
backgroundColor: const Color(0xFFF5F5F5),
|
||
appBar: AppBar(
|
||
title: Text(
|
||
'权限管理',
|
||
style: TextStyle(
|
||
color: AppConstants.primaryColor,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
backgroundColor: Colors.white,
|
||
elevation: 0,
|
||
centerTitle: true,
|
||
leading: IconButton(
|
||
icon: const Icon(Icons.arrow_back),
|
||
onPressed: () => Navigator.pop(context),
|
||
),
|
||
),
|
||
body: ListView(
|
||
padding: const EdgeInsets.all(16),
|
||
children: [
|
||
_buildPermissionGroup('基础权限', [
|
||
_buildPermissionItem(
|
||
'震动反馈',
|
||
'操作时的震动反馈,提升交互体验',
|
||
Icons.vibration,
|
||
_vibrationEnabled,
|
||
null,
|
||
),
|
||
_buildPermissionItem(
|
||
'网络访问',
|
||
'访问网络获取诗词内容和数据',
|
||
Icons.wifi,
|
||
_networkEnabled,
|
||
null,
|
||
),
|
||
_buildPermissionItem(
|
||
'剪切板',
|
||
'复制诗词内容到剪切板',
|
||
Icons.content_copy,
|
||
_clipboardEnabled,
|
||
null,
|
||
),
|
||
]),
|
||
const SizedBox(height: 16),
|
||
_buildPermissionGroup('权限说明', [
|
||
_buildInfoItem('震动反馈', '用于点赞、收藏等操作的触觉反馈,提升用户体验。'),
|
||
_buildInfoItem('网络访问', '用于获取诗词内容、排行榜数据、用户信息等。'),
|
||
_buildInfoItem('剪切板', '用于复制诗词内容,方便用户分享和记录。'),
|
||
]),
|
||
const SizedBox(height: 16),
|
||
_buildProjectSupplement(),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildPermissionGroup(String title, List<Widget> items) {
|
||
return Container(
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(16),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.black.withValues(alpha: 0.05),
|
||
blurRadius: 10,
|
||
offset: const Offset(0, 2),
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Padding(
|
||
padding: const EdgeInsets.all(16),
|
||
child: Row(
|
||
children: [
|
||
Icon(
|
||
Icons.security,
|
||
color: AppConstants.primaryColor,
|
||
size: 20,
|
||
),
|
||
const SizedBox(width: 8),
|
||
Text(
|
||
title,
|
||
style: TextStyle(
|
||
color: AppConstants.primaryColor,
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
const Divider(height: 1),
|
||
...items,
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildPermissionItem(
|
||
String title,
|
||
String description,
|
||
IconData icon,
|
||
bool enabled,
|
||
Function(bool)? onToggle,
|
||
) {
|
||
return Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 40,
|
||
height: 40,
|
||
decoration: BoxDecoration(
|
||
color: AppConstants.primaryColor.withValues(alpha: 0.1),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: Icon(icon, color: AppConstants.primaryColor, size: 20),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
children: [
|
||
Text(
|
||
title,
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Container(
|
||
padding: const EdgeInsets.symmetric(
|
||
horizontal: 6,
|
||
vertical: 2,
|
||
),
|
||
decoration: BoxDecoration(
|
||
color: Colors.grey[200],
|
||
borderRadius: BorderRadius.circular(4),
|
||
),
|
||
child: Text(
|
||
'已开启',
|
||
style: TextStyle(fontSize: 10, color: Colors.grey[600]),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 2),
|
||
Text(
|
||
description,
|
||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Icon(Icons.lock, color: Colors.grey[400], size: 20),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildInfoItem(String title, String description) {
|
||
return Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||
child: Row(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Container(
|
||
width: 4,
|
||
height: 4,
|
||
margin: const EdgeInsets.only(top: 6),
|
||
decoration: BoxDecoration(
|
||
color: AppConstants.primaryColor,
|
||
borderRadius: BorderRadius.circular(2),
|
||
),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
title,
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
description,
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: Colors.grey[600],
|
||
height: 1.5,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildProjectSupplement() {
|
||
return Container(
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(16),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.black.withValues(alpha: 0.05),
|
||
blurRadius: 10,
|
||
offset: const Offset(0, 2),
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Padding(
|
||
padding: const EdgeInsets.all(16),
|
||
child: Row(
|
||
children: [
|
||
Icon(Icons.build, color: AppConstants.primaryColor, size: 20),
|
||
const SizedBox(width: 8),
|
||
Text(
|
||
'项目补充完善',
|
||
style: TextStyle(
|
||
color: AppConstants.primaryColor,
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
const Divider(height: 1),
|
||
_buildSupplementItem(
|
||
'用户反馈',
|
||
'帮助我们改进产品',
|
||
Icons.feedback,
|
||
() => _showFeedbackDialog(),
|
||
),
|
||
_buildSupplementItem(
|
||
'功能建议',
|
||
'提出您希望的功能',
|
||
Icons.lightbulb,
|
||
() => _showSuggestionDialog(),
|
||
),
|
||
_buildSupplementItem(
|
||
'Bug报告',
|
||
'报告遇到的问题',
|
||
Icons.bug_report,
|
||
() => _showBugReportDialog(),
|
||
),
|
||
_buildSupplementItem(
|
||
'参与开发',
|
||
'成为贡献者',
|
||
Icons.code,
|
||
() => _showContributionDialog(),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildSupplementItem(
|
||
String title,
|
||
String description,
|
||
IconData icon,
|
||
VoidCallback onTap,
|
||
) {
|
||
return InkWell(
|
||
onTap: onTap,
|
||
child: Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||
child: Row(
|
||
children: [
|
||
Container(
|
||
width: 40,
|
||
height: 40,
|
||
decoration: BoxDecoration(
|
||
color: AppConstants.primaryColor.withValues(alpha: 0.1),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: Icon(icon, color: AppConstants.primaryColor, size: 20),
|
||
),
|
||
const SizedBox(width: 12),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
title,
|
||
style: const TextStyle(
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
const SizedBox(height: 2),
|
||
Text(
|
||
description,
|
||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Icon(Icons.chevron_right, color: Colors.grey[400]),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _showFeedbackDialog() {
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) => AlertDialog(
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||
title: Row(
|
||
children: [
|
||
Icon(Icons.feedback, color: AppConstants.primaryColor),
|
||
const SizedBox(width: 8),
|
||
const Text('用户反馈'),
|
||
],
|
||
),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text(
|
||
'感谢您的反馈!请详细描述您遇到的问题或建议。',
|
||
style: TextStyle(fontSize: 14, height: 1.5),
|
||
),
|
||
const SizedBox(height: 16),
|
||
TextField(
|
||
maxLines: 5,
|
||
decoration: InputDecoration(
|
||
hintText: '请输入您的反馈内容...',
|
||
border: OutlineInputBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
contentPadding: const EdgeInsets.all(12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(context),
|
||
child: const Text('取消'),
|
||
),
|
||
ElevatedButton(
|
||
onPressed: () {
|
||
Navigator.pop(context);
|
||
ScaffoldMessenger.of(
|
||
context,
|
||
).showSnackBar(const SnackBar(content: Text('反馈已提交,感谢您的支持!')));
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: AppConstants.primaryColor,
|
||
foregroundColor: Colors.white,
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
),
|
||
child: const Text('提交'),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
void _showSuggestionDialog() {
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) => AlertDialog(
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||
title: Row(
|
||
children: [
|
||
Icon(Icons.lightbulb, color: AppConstants.primaryColor),
|
||
const SizedBox(width: 8),
|
||
const Text('功能建议'),
|
||
],
|
||
),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text(
|
||
'我们非常期待您的创意!请描述您希望添加的功能。',
|
||
style: TextStyle(fontSize: 14, height: 1.5),
|
||
),
|
||
const SizedBox(height: 16),
|
||
TextField(
|
||
maxLines: 5,
|
||
decoration: InputDecoration(
|
||
hintText: '请输入您的功能建议...',
|
||
border: OutlineInputBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
contentPadding: const EdgeInsets.all(12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(context),
|
||
child: const Text('取消'),
|
||
),
|
||
ElevatedButton(
|
||
onPressed: () {
|
||
Navigator.pop(context);
|
||
ScaffoldMessenger.of(
|
||
context,
|
||
).showSnackBar(const SnackBar(content: Text('建议已提交,我们会认真考虑!')));
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: AppConstants.primaryColor,
|
||
foregroundColor: Colors.white,
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
),
|
||
child: const Text('提交'),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
void _showBugReportDialog() {
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) => AlertDialog(
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||
title: Row(
|
||
children: [
|
||
Icon(Icons.bug_report, color: AppConstants.primaryColor),
|
||
const SizedBox(width: 8),
|
||
const Text('Bug报告'),
|
||
],
|
||
),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text(
|
||
'请详细描述遇到的问题,我们会尽快修复。',
|
||
style: TextStyle(fontSize: 14, height: 1.5),
|
||
),
|
||
const SizedBox(height: 16),
|
||
TextField(
|
||
maxLines: 5,
|
||
decoration: InputDecoration(
|
||
hintText: '请描述您遇到的问题...',
|
||
border: OutlineInputBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
contentPadding: const EdgeInsets.all(12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(context),
|
||
child: const Text('取消'),
|
||
),
|
||
ElevatedButton(
|
||
onPressed: () {
|
||
Navigator.pop(context);
|
||
ScaffoldMessenger.of(
|
||
context,
|
||
).showSnackBar(const SnackBar(content: Text('Bug报告已提交,感谢您的反馈!')));
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: AppConstants.primaryColor,
|
||
foregroundColor: Colors.white,
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
),
|
||
child: const Text('提交'),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
void _showContributionDialog() {
|
||
showDialog(
|
||
context: context,
|
||
builder: (context) => AlertDialog(
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||
title: Row(
|
||
children: [
|
||
Icon(Icons.code, color: AppConstants.primaryColor),
|
||
const SizedBox(width: 8),
|
||
const Text('参与开发'),
|
||
],
|
||
),
|
||
content: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const Text(
|
||
'欢迎参与项目开发!请选择您希望参与的方式。',
|
||
style: TextStyle(fontSize: 14, height: 1.5),
|
||
),
|
||
const SizedBox(height: 16),
|
||
_buildContributionOption('代码贡献', '提交代码改进'),
|
||
_buildContributionOption('文档完善', '完善项目文档'),
|
||
_buildContributionOption('测试反馈', '提供测试反馈'),
|
||
_buildContributionOption('设计建议', 'UI/UX设计建议'),
|
||
],
|
||
),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(context),
|
||
child: const Text('关闭'),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildContributionOption(String title, String description) {
|
||
return Container(
|
||
margin: const EdgeInsets.only(bottom: 12),
|
||
padding: const EdgeInsets.all(12),
|
||
decoration: BoxDecoration(
|
||
color: Colors.grey[50],
|
||
borderRadius: BorderRadius.circular(8),
|
||
border: Border.all(color: Colors.grey.withValues(alpha: 0.2)),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(
|
||
title,
|
||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||
),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
description,
|
||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|