generated from dellevin/template
降低安装包体积,更改问本地选择字体
This commit is contained in:
399
lib/pages/font_picker_page.dart
Normal file
399
lib/pages/font_picker_page.dart
Normal file
@@ -0,0 +1,399 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import '../utils/font_download_manager.dart';
|
||||
import '../utils/toast_util.dart';
|
||||
|
||||
/// 字体选择页面
|
||||
///
|
||||
/// 用户输入或选择字体目录,遍历目录下的字体文件,点击即可加载使用。
|
||||
class FontPickerPage extends StatefulWidget {
|
||||
final String? initialFamily;
|
||||
const FontPickerPage({super.key, this.initialFamily});
|
||||
|
||||
@override
|
||||
State<FontPickerPage> createState() => _FontPickerPageState();
|
||||
}
|
||||
|
||||
class _FontPickerPageState extends State<FontPickerPage> {
|
||||
final TextEditingController _pathController = TextEditingController();
|
||||
final FontDownloadManager _fontManager = FontDownloadManager();
|
||||
|
||||
List<FontFileInfo> _fonts = [];
|
||||
String? _loadingPath;
|
||||
String? _selectedFamily;
|
||||
bool _isScanning = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selectedFamily = widget.initialFamily;
|
||||
// 默认填入内置字体目录
|
||||
_pathController.text = '/sdcard/Documents/mooknote/fonts';
|
||||
_checkPermissionAndScan();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pathController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 请求存储权限(Android 11+ 需要 MANAGE_EXTERNAL_STORAGE)
|
||||
Future<bool> _requestStoragePermission() async {
|
||||
if (!Platform.isAndroid) return true;
|
||||
|
||||
var status = await Permission.manageExternalStorage.status;
|
||||
if (status.isGranted) return true;
|
||||
|
||||
status = await Permission.manageExternalStorage.request();
|
||||
if (status.isGranted) return true;
|
||||
|
||||
status = await Permission.storage.status;
|
||||
if (status.isGranted) return true;
|
||||
|
||||
status = await Permission.storage.request();
|
||||
return status.isGranted;
|
||||
}
|
||||
|
||||
/// 检查权限并扫描
|
||||
Future<void> _checkPermissionAndScan() async {
|
||||
final hasPermission = await _requestStoragePermission();
|
||||
if (!hasPermission) {
|
||||
if (mounted) {
|
||||
_showPermissionDialog();
|
||||
}
|
||||
return;
|
||||
}
|
||||
await _scanDirectory();
|
||||
}
|
||||
|
||||
/// 显示权限提示弹窗
|
||||
void _showPermissionDialog() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('需要存储权限',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: Text(
|
||||
'Android 11+ 需要在系统设置中授予"所有文件访问权限"才能扫描字体文件。\n\n是否前往设置?',
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.6),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
openAppSettings();
|
||||
},
|
||||
child: Text('前往设置', style: TextStyle(color: colors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 扫描目录字体
|
||||
Future<void> _scanDirectory() async {
|
||||
final dirPath = _pathController.text.trim();
|
||||
if (dirPath.isEmpty) {
|
||||
if (mounted) ToastUtil.show(context, '请输入目录路径');
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isScanning = true);
|
||||
try {
|
||||
final fonts = await _fontManager.scanFontDirectory(dirPath);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_fonts = fonts;
|
||||
_isScanning = false;
|
||||
});
|
||||
if (fonts.isEmpty) {
|
||||
ToastUtil.show(context, '未找到字体文件');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
setState(() => _isScanning = false);
|
||||
ToastUtil.show(context, '扫描失败: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 使用 file_picker 选择目录
|
||||
Future<void> _pickDirectory() async {
|
||||
final hasPermission = await _requestStoragePermission();
|
||||
if (!hasPermission) {
|
||||
if (mounted) _showPermissionDialog();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final result = await FilePicker.platform.getDirectoryPath();
|
||||
if (result != null && result.isNotEmpty) {
|
||||
_pathController.text = result;
|
||||
await _scanDirectory();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) ToastUtil.show(context, '选择目录失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载并应用字体
|
||||
Future<void> _loadFont(FontFileInfo font) async {
|
||||
if (_loadingPath != null) return; // 防止重复点击
|
||||
|
||||
setState(() => _loadingPath = font.path);
|
||||
try {
|
||||
final family = await _fontManager.loadFontFile(font.path);
|
||||
if (family != null) {
|
||||
setState(() => _selectedFamily = family);
|
||||
if (mounted) {
|
||||
ToastUtil.show(context, '已应用: ${font.displayName}');
|
||||
Navigator.pop(context, family);
|
||||
}
|
||||
} else {
|
||||
if (mounted) ToastUtil.show(context, '字体加载失败');
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) ToastUtil.show(context, '加载失败: $e');
|
||||
} finally {
|
||||
setState(() => _loadingPath = null);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
appBar: AppBar(
|
||||
title: const Text('选择字体'),
|
||||
actions: [
|
||||
// 默认字体按钮
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, ''),
|
||||
child: Text(
|
||||
'恢复默认',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colors.primary,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// 路径输入区
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 12),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'字体目录',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _pathController,
|
||||
style: TextStyle(fontSize: 13, color: colors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入字体目录路径',
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 13,
|
||||
color: colors.onSurface.withValues(alpha: 0.3),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: colors.surfaceContainerHighest,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
Icons.folder_open_outlined,
|
||||
size: 18,
|
||||
color: colors.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
onPressed: _pickDirectory,
|
||||
),
|
||||
),
|
||||
onSubmitted: (_) => _scanDirectory(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton(
|
||||
onPressed: _scanDirectory,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.primary,
|
||||
foregroundColor: colors.onPrimary,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('扫描', style: TextStyle(fontSize: 13)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 字体列表
|
||||
Expanded(
|
||||
child: _isScanning
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colors.primary,
|
||||
),
|
||||
)
|
||||
: _fonts.isEmpty
|
||||
? _buildEmptyState(colors)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: _fonts.length,
|
||||
separatorBuilder: (_, __) => Divider(
|
||||
height: 0.5,
|
||||
indent: 20,
|
||||
endIndent: 20,
|
||||
color: colors.outlineVariant,
|
||||
),
|
||||
itemBuilder: (_, index) => _buildFontItem(
|
||||
_fonts[index],
|
||||
colors,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(ColorScheme colors) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.folder_open_outlined,
|
||||
size: 48,
|
||||
color: colors.onSurface.withValues(alpha: 0.15),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'未找到字体文件',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface.withValues(alpha: 0.4),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'支持 .ttf / .otf / .ttc 格式',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.onSurface.withValues(alpha: 0.25),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFontItem(FontFileInfo font, ColorScheme colors) {
|
||||
final isLoading = _loadingPath == font.path;
|
||||
final isSelected = _selectedFamily != null &&
|
||||
path.basenameWithoutExtension(font.fileName) == _selectedFamily;
|
||||
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
|
||||
leading: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? colors.primary.withValues(alpha: 0.1)
|
||||
: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: isSelected
|
||||
? Border.all(color: colors.primary.withValues(alpha: 0.3), width: 1)
|
||||
: null,
|
||||
),
|
||||
child: isLoading
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colors.primary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Icon(
|
||||
Icons.font_download_outlined,
|
||||
size: 18,
|
||||
color: isSelected
|
||||
? colors.primary
|
||||
: colors.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
font.displayName,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
font.fileName,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: colors.onSurface.withValues(alpha: 0.35),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: isSelected
|
||||
? Icon(Icons.check_circle, size: 18, color: colors.primary)
|
||||
: null,
|
||||
onTap: isLoading ? null : () => _loadFont(font),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:path/path.dart' as path;
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import '../main.dart' show routeObserver;
|
||||
import '../models/data_models.dart';
|
||||
import '../providers/app_provider.dart';
|
||||
@@ -25,6 +26,7 @@ import 'sync/cloud_sync_page.dart';
|
||||
import 'app_icon_picker_page.dart';
|
||||
import 'tag_management_page.dart';
|
||||
import 'stroll_page.dart';
|
||||
import 'font_picker_page.dart';
|
||||
|
||||
/// 个人中心页面
|
||||
class ProfilePage extends StatefulWidget {
|
||||
@@ -680,11 +682,7 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
() => Navigator.push(
|
||||
context, MaterialPageRoute(builder: (_) => const SettingsPage()))
|
||||
),
|
||||
(
|
||||
Icons.feedback_outlined,
|
||||
'反馈',
|
||||
() => _showFeedbackDialog(context)
|
||||
),
|
||||
(Icons.feedback_outlined, '反馈', () => _showFeedbackDialog(context)),
|
||||
];
|
||||
|
||||
return Padding(
|
||||
@@ -808,7 +806,8 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
Text('作者邮箱',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
color:
|
||||
colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 2),
|
||||
Text(email,
|
||||
style: TextStyle(
|
||||
@@ -824,7 +823,8 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
ToastUtil.show(context, '已复制到剪贴板');
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -834,7 +834,11 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
children: [
|
||||
Icon(Icons.copy, size: 14, color: colors.primary),
|
||||
const SizedBox(width: 4),
|
||||
Text('复制', style: TextStyle(fontSize: 12, color: colors.primary, fontWeight: FontWeight.w600)),
|
||||
Text('复制',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.primary,
|
||||
fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -864,7 +868,8 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
Text('QQ 群',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
color:
|
||||
colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 2),
|
||||
Text('1087203310',
|
||||
style: TextStyle(
|
||||
@@ -880,7 +885,8 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
ToastUtil.show(context, '已复制到剪贴板');
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary.withValues(alpha: 0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
@@ -890,7 +896,11 @@ class _ProfilePageState extends State<ProfilePage> with RouteAware {
|
||||
children: [
|
||||
Icon(Icons.copy, size: 14, color: colors.primary),
|
||||
const SizedBox(width: 4),
|
||||
Text('复制', style: TextStyle(fontSize: 12, color: colors.primary, fontWeight: FontWeight.w600)),
|
||||
Text('复制',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: colors.primary,
|
||||
fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -1225,6 +1235,17 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
subtitle: '清理未在数据库中引用的文件',
|
||||
onTap: () => _showClearCacheDialog(context),
|
||||
),
|
||||
Divider(
|
||||
height: 0.5,
|
||||
indent: 24,
|
||||
endIndent: 24,
|
||||
color: colors.outlineVariant),
|
||||
_buildActionItem(
|
||||
icon: Icons.folder_outlined,
|
||||
title: '获取系统权限',
|
||||
subtitle: '前往系统设置开启存储权限',
|
||||
onTap: _showStoragePermissionDialog,
|
||||
),
|
||||
Divider(
|
||||
height: 0.5,
|
||||
indent: 24,
|
||||
@@ -1758,28 +1779,20 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
|
||||
// ─── 字体选择器 ───
|
||||
|
||||
static const _fontLabels = ['默认字体', '霞鹜文楷', 'OPPO Sans', '思源宋体', '得意黑'];
|
||||
static const _fontValues = [
|
||||
'',
|
||||
'LXGWWenKai',
|
||||
'OPPOSans',
|
||||
'NotoSerifSC',
|
||||
'SmileySans'
|
||||
];
|
||||
static const _fontIcons = [
|
||||
Icons.font_download_outlined,
|
||||
Icons.brush_outlined,
|
||||
Icons.phone_android,
|
||||
Icons.text_fields,
|
||||
Icons.emoji_emotions_outlined
|
||||
];
|
||||
|
||||
Widget _buildFontSelector() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final idx = _fontValues.indexOf(_fontFamily);
|
||||
final label = idx >= 0 ? _fontLabels[idx] : '系统默认';
|
||||
final label = _fontFamily.isEmpty ? '系统默认' : _fontFamily;
|
||||
return InkWell(
|
||||
onTap: _showFontPicker,
|
||||
onTap: () async {
|
||||
final result = await Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const FontPickerPage(initialFamily: '')),
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_setFontFamily(result);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
child: Row(children: [
|
||||
@@ -1814,76 +1827,6 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showFontPicker() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) => Container(
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surface,
|
||||
borderRadius:
|
||||
const BorderRadius.vertical(top: Radius.circular(16))),
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 4,
|
||||
margin: const EdgeInsets.only(top: 12, bottom: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.onSurface.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(2))),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('字体',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface)))),
|
||||
const SizedBox(height: 8),
|
||||
for (int i = 0; i < _fontLabels.length; i++) ...[
|
||||
if (i > 0)
|
||||
Divider(
|
||||
height: 0.5,
|
||||
indent: 24,
|
||||
endIndent: 24,
|
||||
color: colors.outlineVariant),
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
leading: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(_fontIcons[i],
|
||||
size: 20,
|
||||
color: _fontFamily == _fontValues[i]
|
||||
? colors.primary
|
||||
: colors.onSurface.withValues(alpha: 0.6))),
|
||||
title: Text(_fontLabels[i],
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: _fontFamily == _fontValues[i]
|
||||
? FontWeight.w600
|
||||
: FontWeight.w400,
|
||||
color: colors.onSurface)),
|
||||
trailing: _fontFamily == _fontValues[i]
|
||||
? Icon(Icons.check, size: 20, color: colors.primary)
|
||||
: null,
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
_setFontFamily(_fontValues[i]);
|
||||
},
|
||||
),
|
||||
],
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _setFontFamily(String family) {
|
||||
setState(() => _fontFamily = family);
|
||||
context.read<AppProvider>().setFontFamily(family);
|
||||
@@ -2040,6 +1983,46 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showStoragePermissionDialog() {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('需要存储权限',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface)),
|
||||
content: Text(
|
||||
'Android 11+ 需要在系统设置中授予"所有文件访问权限"才能扫描字体文件。\n\n是否前往设置?',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
height: 1.6),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: Text('取消',
|
||||
style:
|
||||
TextStyle(color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(ctx);
|
||||
// 跳转到应用设置页(用户可在权限中找到"所有文件访问")
|
||||
openAppSettings();
|
||||
},
|
||||
child: Text('前往设置', style: TextStyle(color: colors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showClearCacheDialog(BuildContext pageContext) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
@@ -2174,8 +2157,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
try {
|
||||
final db = await DatabaseHelper.instance.database;
|
||||
// 收集数据库中所有引用的 epub_books 子目录名(包括软删除的)
|
||||
final rows = await db
|
||||
.query('reader_books', columns: ['id', 'file_path', 'cover_path', 'is_deleted']);
|
||||
final rows = await db.query('reader_books',
|
||||
columns: ['id', 'file_path', 'cover_path', 'is_deleted']);
|
||||
final usedDirs = <String>{};
|
||||
for (final r in rows) {
|
||||
// 只收集未删除的记录对应的目录
|
||||
|
||||
Reference in New Issue
Block a user