适配深色模式

This commit is contained in:
DelLevin-Home
2026-05-26 05:10:21 +08:00
parent b36f50827f
commit 73f3795e65
53 changed files with 3846 additions and 3211 deletions

View File

@@ -90,26 +90,30 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
void _showPermissionDeniedDialog() {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('需要存储权限', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
content: const Text(
'Android 11+ 需要在系统设置中授予"所有文件访问权限"才能读取目录中的 Markdown 文件。\n\n是否前往设置?',
style: TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('取消', style: TextStyle(color: Color(0xFF999999))),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return AlertDialog(
title: const Text('需要存储权限',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
content: Text(
'Android 11+ 需要在系统设置中授予"所有文件访问权限"才能读取目录中的 Markdown 文件。\n\n是否前往设置?',
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.6),
),
TextButton(
onPressed: () {
Navigator.pop(ctx);
openAppSettings();
},
child: const Text('前往设置', style: TextStyle(color: Color(0xFF1A1A1A))),
),
],
),
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.onSurface)),
),
],
);
},
);
}
@@ -121,7 +125,10 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
for (final entity in dir.listSync(recursive: true, followLinks: false)) {
if (entity is File) {
final lower = p.basename(entity.path).toLowerCase();
if (lower.endsWith('.md') || lower.endsWith('.markdown') || lower.endsWith('.mdown') || lower.endsWith('.txt')) {
if (lower.endsWith('.md') ||
lower.endsWith('.markdown') ||
lower.endsWith('.mdown') ||
lower.endsWith('.txt')) {
return true;
}
}
@@ -135,13 +142,28 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
try {
final dir = Directory(dirPath);
if (!dir.existsSync()) return false;
const imageExts = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.svg', '.ico', '.tiff', '.heic', '.webm'];
const imageExts = [
'.png',
'.jpg',
'.jpeg',
'.gif',
'.webp',
'.bmp',
'.svg',
'.ico',
'.tiff',
'.heic',
'.webm'
];
bool hasAnyFile = false;
for (final entity in dir.listSync(recursive: true, followLinks: false)) {
if (entity is File) {
hasAnyFile = true;
final lower = p.basename(entity.path).toLowerCase();
if (lower.endsWith('.md') || lower.endsWith('.markdown') || lower.endsWith('.mdown') || lower.endsWith('.txt')) {
if (lower.endsWith('.md') ||
lower.endsWith('.markdown') ||
lower.endsWith('.mdown') ||
lower.endsWith('.txt')) {
return false;
}
if (!imageExts.any((ext) => lower.endsWith(ext))) {
@@ -193,9 +215,13 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
}
} else if (entity is File) {
final lower = name.toLowerCase();
if (lower.endsWith('.md') || lower.endsWith('.markdown') || lower.endsWith('.mdown') || lower.endsWith('.txt')) {
if (lower.endsWith('.md') ||
lower.endsWith('.markdown') ||
lower.endsWith('.mdown') ||
lower.endsWith('.txt')) {
final stat = entity.statSync();
entries.add(_FileEntry(name: name, path: entity.path, isDir: false, size: stat.size));
entries.add(_FileEntry(
name: name, path: entity.path, isDir: false, size: stat.size));
}
}
}
@@ -236,9 +262,10 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
}
void _openFile(_FileEntry entry) {
Navigator.push(context, MaterialPageRoute(
builder: (context) => MdViewerPage(filePath: entry.path),
));
Navigator.push(context,
MaterialPageRoute(
builder: (context) => MdViewerPage(filePath: entry.path),
));
}
void _showSettingsSheet() {
@@ -249,6 +276,7 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return StatefulBuilder(
builder: (ctx, setLocalState) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
@@ -256,24 +284,31 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 36, height: 4,
width: 36,
height: 4,
decoration: BoxDecoration(
color: const Color(0xFFDDDDDD),
color: colors.onSurface.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(height: 20),
const Align(
Align(
alignment: Alignment.centerLeft,
child: Text('目录显示设置', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
child: Text('目录显示设置',
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface)),
),
const SizedBox(height: 16),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('显示空目录', style: TextStyle(fontSize: 14, color: Color(0xFF333333))),
subtitle: const Text('关闭后隐藏无 Markdown 文件的目录', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
title: Text('显示空目录',
style: TextStyle(
fontSize: 14, color: colors.onSurface.withValues(alpha: 0.75))),
subtitle: Text('关闭后隐藏无 Markdown 文件的目录',
style:
TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
value: _showEmptyDirs,
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: colors.primary,
onChanged: (val) {
setLocalState(() => _showEmptyDirs = val);
UserPrefs().setShowEmptyDirs(val);
@@ -281,13 +316,17 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
_loadDirectory();
},
),
const Divider(height: 0.5, color: Color(0xFFF0F0F0)),
Divider(height: 0.5, color: colors.outlineVariant),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('显示纯图片目录', style: TextStyle(fontSize: 14, color: Color(0xFF333333))),
subtitle: const Text('关闭后隐藏只含图片、无 Markdown 的目录', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
title: Text('显示纯图片目录',
style: TextStyle(
fontSize: 14, color: colors.onSurface.withValues(alpha: 0.75))),
subtitle: Text('关闭后隐藏只含图片、无 Markdown 的目录',
style:
TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
value: _showImageOnlyDirs,
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: colors.primary,
onChanged: (val) {
setLocalState(() => _showImageOnlyDirs = val);
UserPrefs().setShowImageOnlyDirs(val);
@@ -304,40 +343,26 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
);
}
bool get _canGoBack => _currentPath != null && _rootPath != null && _currentPath != _rootPath;
bool get _canGoBack =>
_currentPath != null && _rootPath != null && _currentPath != _rootPath;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
elevation: 0,
title: Text(
_currentPath != null ? p.basename(_currentPath!) : 'Markdown 阅读',
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: colors.onSurface),
),
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Color(0xFF1A1A1A)),
icon: Icon(Icons.arrow_back, color: colors.onSurface),
onPressed: () => Navigator.pop(context),
),
actions: [
// if (_canGoBack)
// Padding(
// padding: const EdgeInsets.only(right: 8),
// child: GestureDetector(
// onTap: _goBack,
// child: Container(
// padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
// decoration: BoxDecoration(
// color: const Color(0xFFF5F5F5),
// borderRadius: BorderRadius.circular(14),
// border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
// ),
// child: const Text('返回上级', style: TextStyle(fontSize: 12, color: Color(0xFF666666))),
// ),
// ),
// ),
if (_currentPath != null)
Padding(
padding: const EdgeInsets.only(right: 4),
@@ -346,86 +371,109 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outline, width: 0.5),
),
child: const Text('更换目录', style: TextStyle(fontSize: 12, color: Color(0xFF888888))),
child: Text('更换目录',
style: TextStyle(
fontSize: 12, color: colors.onSurface.withValues(alpha: 0.5))),
),
),
),
IconButton(
icon: const Icon(Icons.tune, size: 20, color: Color(0xFF888888)),
icon: Icon(Icons.tune, size: 20, color: colors.onSurface.withValues(alpha: 0.5)),
onPressed: _showSettingsSheet,
),
const SizedBox(width: 4),
],
),
body: _buildBody(),
body: _buildBody(colors),
);
}
Widget _buildBody() {
Widget _buildBody(ColorScheme colors) {
if (_currentPath == null) {
return _buildWelcome();
return _buildWelcome(colors);
}
if (_isLoading) {
return const Center(child: CircularProgressIndicator(color: Color(0xFF1A1A1A)));
return Center(child: CircularProgressIndicator(color: colors.primary));
}
if (_error != null) {
return _buildError();
return _buildError(colors);
}
return RefreshIndicator(
onRefresh: _loadDirectory,
color: const Color(0xFF1A1A1A),
backgroundColor: Colors.white,
child: _entries.isEmpty ? _buildEmpty() : ListView.separated(
padding: EdgeInsets.zero,
itemCount: (_canGoBack ? 1 : 0) + _entries.length,
separatorBuilder: (_, __) => const Divider(height: 0.5, thickness: 0.5, color: Color(0xFFF0F0F0)),
itemBuilder: (context, index) {
if (_canGoBack && index == 0) {
return ListTile(
leading: Container(
width: 36, height: 36,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(8),
),
child: const Icon(Icons.arrow_upward, size: 18, color: Color(0xFF888888)),
),
title: const Text('..', style: TextStyle(fontSize: 14, color: Color(0xFF888888))),
onTap: _goBack,
);
}
final entry = _entries[_canGoBack ? index - 1 : index];
return ListTile(
leading: Container(
width: 36, height: 36,
decoration: BoxDecoration(
color: entry.isDir ? const Color(0xFFF0F7FF) : const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
entry.isDir ? Icons.folder_outlined : Icons.description_outlined,
size: 18,
color: entry.isDir ? const Color(0xFF4A90D9) : const Color(0xFF666666),
),
color: colors.primary,
backgroundColor: colors.surface,
child: _entries.isEmpty
? _buildEmpty(colors)
: ListView.separated(
padding: EdgeInsets.zero,
itemCount: (_canGoBack ? 1 : 0) + _entries.length,
separatorBuilder: (_, __) =>
Divider(height: 0.5, thickness: 0.5, color: colors.outlineVariant),
itemBuilder: (context, index) {
if (_canGoBack && index == 0) {
return ListTile(
leading: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Icon(Icons.arrow_upward,
size: 18, color: colors.onSurface.withValues(alpha: 0.5)),
),
title: Text('..',
style: TextStyle(
fontSize: 14, color: colors.onSurface.withValues(alpha: 0.5))),
onTap: _goBack,
);
}
final entry = _entries[_canGoBack ? index - 1 : index];
return ListTile(
leading: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: entry.isDir
? const Color(0xFFF0F7FF)
: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Icon(
entry.isDir ? Icons.folder_outlined : Icons.description_outlined,
size: 18,
color: entry.isDir
? const Color(0xFF4A90D9)
: colors.onSurface.withValues(alpha: 0.6),
),
),
title: Text(entry.name,
style: TextStyle(fontSize: 14, color: colors.onSurface),
maxLines: 1,
overflow: TextOverflow.ellipsis),
subtitle: entry.isDir
? null
: Text(_formatSize(entry.size),
style: TextStyle(
fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4))),
trailing: Icon(entry.isDir ? Icons.chevron_right : Icons.open_in_new_outlined,
size: 16, color: colors.onSurface.withValues(alpha: 0.25)),
onTap: () =>
entry.isDir ? _enterDirectory(entry.path) : _openFile(entry),
);
},
),
title: Text(entry.name, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)), maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: entry.isDir ? null : Text(_formatSize(entry.size), style: const TextStyle(fontSize: 11, color: Color(0xFF999999))),
trailing: Icon(entry.isDir ? Icons.chevron_right : Icons.open_in_new_outlined, size: 16, color: const Color(0xFFCCCCCC)),
onTap: () => entry.isDir ? _enterDirectory(entry.path) : _openFile(entry),
);
},
),
);
}
Widget _buildWelcome() {
Widget _buildWelcome(ColorScheme colors) {
return Center(
child: Padding(
padding: const EdgeInsets.all(40),
@@ -433,27 +481,34 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 80, height: 80,
width: 80,
height: 80,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(Icons.folder_open_outlined, size: 40, color: Color(0xFFCCCCCC)),
child: Icon(Icons.folder_open_outlined,
size: 40, color: colors.onSurface.withValues(alpha: 0.25)),
),
const SizedBox(height: 24),
const Text('Markdown 阅读', style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
Text('Markdown 阅读',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600, color: colors.onSurface)),
const SizedBox(height: 8),
const Text('选择一个包含 .md 文件的文件夹', style: TextStyle(fontSize: 14, color: Color(0xFF999999))),
Text('选择一个包含 .md 文件的文件夹',
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.4))),
const SizedBox(height: 32),
GestureDetector(
onTap: _pickDirectory,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 14),
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.primary,
borderRadius: BorderRadius.circular(24),
),
child: const Text('选择目录', style: TextStyle(fontSize: 15, color: Colors.white, fontWeight: FontWeight.w500)),
child: Text('选择目录',
style: TextStyle(
fontSize: 15, color: colors.onPrimary, fontWeight: FontWeight.w500)),
),
),
],
@@ -462,28 +517,31 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
);
}
Widget _buildEmpty() {
Widget _buildEmpty(ColorScheme colors) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.folder_open_outlined, size: 64, color: Color(0xFFE0E0E0)),
Icon(Icons.folder_open_outlined, size: 64, color: colors.outline),
const SizedBox(height: 16),
const Text('此目录下没有 Markdown 文件', style: TextStyle(fontSize: 15, color: Color(0xFF999999))),
Text('此目录下没有 Markdown 文件',
style: TextStyle(fontSize: 15, color: colors.onSurface.withValues(alpha: 0.4))),
const SizedBox(height: 4),
Text(_currentPath ?? '', style: const TextStyle(fontSize: 12, color: Color(0xFFCCCCCC))),
Text(_currentPath ?? '',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.25))),
const SizedBox(height: 24),
GestureDetector(
onTap: _canGoBack ? _goBack : () => _pickDirectory(),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFDDDDDD)),
border: Border.all(color: colors.onSurface.withValues(alpha: 0.15)),
borderRadius: BorderRadius.circular(20),
),
child: Text(
_canGoBack ? '返回上级目录' : '换一个目录',
style: const TextStyle(fontSize: 13, color: Color(0xFF888888)),
style: TextStyle(
fontSize: 13, color: colors.onSurface.withValues(alpha: 0.5)),
),
),
),
@@ -492,18 +550,22 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
);
}
Widget _buildError() {
Widget _buildError(ColorScheme colors) {
return Center(
child: Padding(
padding: const EdgeInsets.all(40),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline, size: 48, color: Color(0xFFCCCCCC)),
Icon(Icons.error_outline,
size: 48, color: colors.onSurface.withValues(alpha: 0.25)),
const SizedBox(height: 16),
Text(_error!, style: const TextStyle(fontSize: 14, color: Color(0xFF999999)), textAlign: TextAlign.center),
Text(_error!,
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.4)),
textAlign: TextAlign.center),
const SizedBox(height: 8),
Text('路径: ${_currentPath ?? ""}', style: const TextStyle(fontSize: 12, color: Color(0xFFCCCCCC))),
Text('路径: ${_currentPath ?? ""}',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.25))),
const SizedBox(height: 24),
Row(
mainAxisSize: MainAxisSize.min,
@@ -513,10 +575,11 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.primary,
borderRadius: BorderRadius.circular(20),
),
child: const Text('重试', style: TextStyle(fontSize: 13, color: Colors.white)),
child: Text('重试',
style: TextStyle(fontSize: 13, color: colors.onPrimary)),
),
),
const SizedBox(width: 12),
@@ -525,10 +588,12 @@ class _MdReaderTabPageState extends State<MdReaderTabPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 10),
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFFDDDDDD)),
border: Border.all(color: colors.onSurface.withValues(alpha: 0.15)),
borderRadius: BorderRadius.circular(20),
),
child: const Text('更换目录', style: TextStyle(fontSize: 13, color: Color(0xFF888888))),
child: Text('更换目录',
style: TextStyle(
fontSize: 13, color: colors.onSurface.withValues(alpha: 0.5))),
),
),
],

View File

@@ -50,10 +50,11 @@ class _MdViewerPageState extends State<MdViewerPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final fileName = widget.filePath.split('/').last;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
elevation: 0,
title: Text(
@@ -61,69 +62,71 @@ class _MdViewerPageState extends State<MdViewerPage> {
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
),
),
body: _buildBody(),
body: _buildBody(colors),
);
}
Widget _buildBody() {
Widget _buildBody(ColorScheme colors) {
if (_isLoading) {
return const Center(child: CircularProgressIndicator(color: Color(0xFF1A1A1A)));
return Center(child: CircularProgressIndicator(color: colors.primary));
}
if (_error != null) {
return _buildErrorState();
return _buildErrorState(colors);
}
return Markdown(
data: _content,
padding: const EdgeInsets.all(20),
styleSheet: MarkdownStyleSheet(
h1: const TextStyle(
h1: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.4,
),
h2: const TextStyle(
h2: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.4,
),
h3: const TextStyle(
h3: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.4,
),
p: const TextStyle(
p: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
height: 1.8,
),
code: const TextStyle(
code: TextStyle(
fontSize: 13,
color: Color(0xFF1A1A1A),
backgroundColor: Color(0xFFF5F5F5),
color: colors.onSurface,
backgroundColor: colors.surfaceContainerHighest,
),
codeblockDecoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
border: Border.all(color: const Color(0xFFE5E5E5)),
color: colors.surfaceContainerHighest,
border: Border.all(color: colors.outline),
borderRadius: BorderRadius.circular(6),
),
codeblockPadding: const EdgeInsets.all(12),
blockquote: const TextStyle(
blockquote: TextStyle(
fontSize: 15,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
fontStyle: FontStyle.italic,
),
blockquoteDecoration: const BoxDecoration(
border: Border(left: BorderSide(color: Color(0xFF999999), width: 4)),
blockquoteDecoration: BoxDecoration(
border: Border(
left: BorderSide(
color: colors.onSurface.withValues(alpha: 0.4), width: 4)),
),
blockquotePadding: const EdgeInsets.only(left: 12),
listBullet: const TextStyle(
listBullet: TextStyle(
fontSize: 15,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
listIndent: 24,
a: const TextStyle(
@@ -133,12 +136,12 @@ class _MdViewerPageState extends State<MdViewerPage> {
),
),
// ignore: deprecated_member_use
imageBuilder: (uri, title, alt) => _buildImage(uri.toString(), alt),
imageBuilder: (uri, title, alt) => _buildImage(colors, uri.toString(), alt),
);
}
/// 构建图片显示
Widget _buildImage(String uri, String? alt) {
Widget _buildImage(ColorScheme colors, String uri, String? alt) {
if (uri.isEmpty) return const SizedBox.shrink();
// 处理相对路径:基于 md 文件所在目录
@@ -158,17 +161,19 @@ class _MdViewerPageState extends State<MdViewerPage> {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.broken_image_outlined, size: 20, color: Color(0xFF999999)),
Icon(Icons.broken_image_outlined,
size: 20, color: colors.onSurface.withValues(alpha: 0.4)),
const SizedBox(width: 8),
Expanded(
child: Text(
alt ?? '图片加载失败',
style: const TextStyle(fontSize: 13, color: Color(0xFF999999)),
style:
TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.4)),
),
),
],
@@ -179,16 +184,17 @@ class _MdViewerPageState extends State<MdViewerPage> {
);
}
Widget _buildErrorState() {
Widget _buildErrorState(ColorScheme colors) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48, color: Color(0xFFCCCCCC)),
Icon(Icons.error_outline,
size: 48, color: colors.onSurface.withValues(alpha: 0.25)),
const SizedBox(height: 16),
Text(
_error!,
style: const TextStyle(fontSize: 14, color: Color(0xFF999999)),
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.4)),
),
],
),