feat: 导出固定 1920×1080(标题恒定左上、内容自适应缩放)+ 安卓保存位置可配置
- 导出重设计(exe 与安卓一致):SVG/PNG 固定 1920×1080;标题恒定左上、图例恒定左下;内容按包围盒等比缩放居中(export_fit.dart 统一计算,不裁切不溢出);PNG 改为离屏 1920×1080 渲染 - 安卓保存位置可改:保存/打开对话框新增「更改位置」,基础目录可选文档/下载/图片 + 自定义子文件夹,设置持久化(save_location.json) - 原生通道 seqstudio/docs 支持 base/folder 参数;新增 export_test.dart 回归(尺寸/标题/transform) - 重建 dist(Windows)与签名 APK
This commit is contained in:
+132
-10
@@ -422,10 +422,99 @@ Future<String?> pickFile(
|
||||
|
||||
// ===================== 安卓公共 Documents 文件对话框 =====================
|
||||
|
||||
/// 安卓版文件对话框:保存到 / 打开自公共 `Documents/SequenceDiagram`。
|
||||
/// 保存位置设置:选择基础目录(文档 / 下载 / 图片)与子文件夹名。
|
||||
class SaveLocationDialog extends StatefulWidget {
|
||||
const SaveLocationDialog({super.key});
|
||||
|
||||
@override
|
||||
State<SaveLocationDialog> createState() => _SaveLocationDialogState();
|
||||
}
|
||||
|
||||
class _SaveLocationDialogState extends State<SaveLocationDialog> {
|
||||
late String _base;
|
||||
late TextEditingController _folder;
|
||||
|
||||
static String zh(String b) => switch (b) {
|
||||
'downloads' => '下载',
|
||||
'pictures' => '图片',
|
||||
_ => '文档',
|
||||
};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final Map<String, String> s = AndroidDocs.settings();
|
||||
_base = s['base'] ?? 'documents';
|
||||
_folder = TextEditingController(text: s['folder'] ?? 'SequenceDiagram');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_folder.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
return AlertDialog(
|
||||
backgroundColor: t.dialog,
|
||||
title: const Text('保存位置'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('基础目录', style: TextStyle(color: t.sub, fontSize: 12)),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
children: AndroidDocs.baseOptions.map((String b) {
|
||||
return ChoiceChip(
|
||||
label: Text(zh(b)),
|
||||
selected: _base == b,
|
||||
onSelected: (_) => setState(() => _base = b),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text('子文件夹名称', style: TextStyle(color: t.sub, fontSize: 12)),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _folder,
|
||||
style: TextStyle(color: t.text, fontSize: 12.5),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: t.panel2,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text('保存、导出、打开都使用该目录;位于平板「文件管理」可见的公共存储。',
|
||||
style: TextStyle(color: t.dim, fontSize: 11, height: 1.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
await AndroidDocs.saveSettings(_base, _folder.text);
|
||||
if (context.mounted) Navigator.pop(context);
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 安卓版文件对话框:保存到 / 打开自配置的公共目录(默认 Documents/SequenceDiagram)。
|
||||
///
|
||||
/// - 保存模式:输入文件名(自动补全后缀),确认后由调用方经 [AndroidDocs] 写入;
|
||||
/// - 打开模式:列出 Documents 目录中匹配后缀的文件,点选返回文件名。
|
||||
/// - 保存模式:显示当前保存位置(可点「更改位置」修改),输入文件名自动补全后缀;
|
||||
/// - 打开模式:列出目录中匹配后缀的文件,点选返回文件名。
|
||||
/// 返回值为文件名;取消返回 null。
|
||||
class AndroidFileDialog extends StatefulWidget {
|
||||
const AndroidFileDialog({
|
||||
@@ -465,7 +554,7 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 列出 Documents 目录中的匹配文件(新在前)。
|
||||
/// 列出配置目录中的匹配文件(新在前)。
|
||||
Future<void> _load() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
@@ -479,7 +568,7 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
.toList();
|
||||
if (mounted) setState(() => _files = matched);
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _error = '无法读取 Documents 目录:$e');
|
||||
if (mounted) setState(() => _error = '无法读取目录:$e');
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
@@ -500,21 +589,52 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
return '$n${widget.suffix}';
|
||||
}
|
||||
|
||||
/// 「更改位置」按钮:打开保存位置设置,返回后刷新本对话框。
|
||||
Future<void> _changeLocation() async {
|
||||
await showDialog<void>(context: context, builder: (_) => const SaveLocationDialog());
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
if (!widget.saveMode) _load();
|
||||
}
|
||||
|
||||
/// 当前保存位置展示行。
|
||||
Widget _locationRow(Tokens t) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.folder_outlined, size: 15, color: t.accent),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text('平板存储 / ${AndroidDocs.location()} /',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _changeLocation,
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
minimumSize: const Size(0, 28),
|
||||
),
|
||||
child: const Text('更改位置', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
return AlertDialog(
|
||||
backgroundColor: t.dialog,
|
||||
title: Text(widget.saveMode ? '保存到 Documents' : '从 Documents 打开'),
|
||||
title: Text(widget.saveMode ? '保存到公共目录' : '从公共目录打开'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
width: 460,
|
||||
child: widget.saveMode
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('文件将保存到平板存储的 ${AndroidDocs.displayDir}/',
|
||||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
_locationRow(t),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
controller: _name,
|
||||
@@ -533,6 +653,8 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
_locationRow(t),
|
||||
const SizedBox(height: 6),
|
||||
if (_loading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
@@ -546,7 +668,7 @@ class _AndroidFileDialogState extends State<AndroidFileDialog> {
|
||||
else if (_files.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Text('Documents 目录中暂无 ${widget.suffix} 文件',
|
||||
child: Text('目录中暂无 ${widget.suffix} 文件',
|
||||
style: TextStyle(color: t.dim, fontSize: 11.5)),
|
||||
)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user