feat(android): 平板版适配(1280×800dp,免授权,应用商店分发)

- flutter create 增加 android 平台:包名 cc.sincos.sequence_diagram,应用名「时序图设计器」,minSdk 24 / targetSdk 36

- 多分辨率动态兼容:触屏侧栏默认贴边把手(点把手直接停靠),面板宽度随屏宽压缩,窄屏双侧栏停靠不溢出

- 免授权:LicenseService 非 Windows 平台直接判定已授权

- 移动端存储/文件浏览器适配(无 APPDATA/盘符/桌面);edge-to-edge + SafeArea + 文本缩放固定 1.0

- launcher 图标沿用「环序」标志(tools/gen-android-icons.py);Gradle 腾讯镜像 + Maven 阿里镜像

- 自测:7 种分辨率无溢出回归(test/tablet_layout_test.dart)+ 平板截图(demo/tablet-*.png)

- 产物:release/sequence_diagram_tablet_v1.0.1_release.apk(universal,50.3MB)
This commit is contained in:
admin
2026-10-06 21:04:38 +08:00
parent f5412ee99d
commit fad82a30d8
37 changed files with 772 additions and 42 deletions
+7
View File
@@ -58,7 +58,14 @@ class LicenseService {
Directory get licenseDir => Directory('${Directory.current.path}${Platform.pathSeparator}license');
/// 初始化:读取 MAC 并校验 `license/*.lic`。
///
/// Android 平板版(应用商店分发)不需要授权:非 Windows 平台直接判定为
/// 已授权,跳过 MAC 读取与 .lic 校验。
Future<LicenseInfo> init() async {
if (!Platform.isWindows) {
_info = const LicenseInfo(mac: null, valid: true);
return _info;
}
final String? mac = await _readMac();
bool valid = false;
String? hitPath;
+22
View File
@@ -5,6 +5,8 @@
// Storage(本地持久化),并通过 AppController 向整个 UI 层提供状态与
// 业务动作。启动后还会检查是否存在异常退出遗留的自动快照,并引导用户
// 选择恢复方式。
import 'dart:io' show Platform;
import 'dart:ui' show AppExitResponse;
import 'package:flutter/material.dart';
@@ -23,6 +25,16 @@ import 'ui/app_shell.dart';
/// 然后启动根组件 [SequenceDiagramApp]。
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// 移动端:沉浸式(edge-to-edge)显示,配合 SafeArea 自动避让系统栏。
if (Platform.isAndroid || Platform.isIOS) {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
systemNavigationBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.light,
));
}
await Storage.instance.init();
runApp(const SequenceDiagramApp());
}
@@ -158,6 +170,16 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
title: '时序图设计器 · Sequence Diagram Studio',
debugShowCheckedModeBanner: false,
theme: buildTheme(tokens),
// 固定文本缩放并包裹 SafeArea:保证平板等分辨率下布局像素级精准,
// 不受系统字体缩放影响,并自动避让状态栏 / 导航栏。
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaler: const TextScaler.linear(1.0),
),
child: SafeArea(child: child ?? const SizedBox.shrink()),
);
},
home: AppShell(controller: _controller),
);
},
+80 -25
View File
@@ -64,6 +64,18 @@ class _AppShellState extends State<AppShell> {
AppController get c => widget.controller;
// ---- 由上述三态派生的侧栏呈现方式 ----
/// 左侧栏宽度:随屏幕宽度动态压缩(300 → 200),窄屏双侧栏停靠也不溢出。
double get _leftPanelWidth {
final double w = MediaQuery.sizeOf(context).width;
return math.min(300.0, math.max(200.0, w * 0.24));
}
/// 右侧栏宽度:随屏幕宽度动态压缩(340 → 240),窄屏双侧栏停靠也不溢出。
double get _rightPanelWidth {
final double w = MediaQuery.sizeOf(context).width;
return math.min(340.0, math.max(240.0, w * 0.26));
}
/// 左侧栏是否处于停靠(固定)状态。
bool get _leftDocked => _leftVisible && _leftPinned;
/// 右侧栏是否处于停靠(固定)状态。
@@ -84,6 +96,27 @@ class _AppShellState extends State<AppShell> {
c.addListener(_onChange);
}
/// 是否已完成一次按平台 / 屏幕宽度的默认布局初始化。
bool _layoutInited = false;
/// 首次构建时按平台与屏幕宽度设定侧栏默认状态(动态兼容不同分辨率):
/// - 触屏平台(Android / iOS):默认收起为贴边轨道,给画布让出完整宽度;
/// - 桌面窄窗口(< 1500 逻辑宽):同样默认收起,避免两侧栏挤占画布。
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_layoutInited) return;
_layoutInited = true;
final bool touch = Platform.isAndroid || Platform.isIOS;
final double w = MediaQuery.of(context).size.width;
if (touch || w < 1500) {
_leftVisible = false;
_rightVisible = false;
_leftPinned = false;
_rightPinned = false;
}
}
/// 取消订阅并释放资源。
@override
void dispose() {
@@ -733,10 +766,19 @@ class _AppShellState extends State<AppShell> {
onTap: () => setState(() {
if (left) {
_leftVisible = true;
if (!_leftPinned) _leftHover = true;
if (Platform.isAndroid || Platform.isIOS) {
// 触屏平台:点把手直接停靠展开(无悬停概念)。
_leftPinned = true;
} else if (!_leftPinned) {
_leftHover = true;
}
} else {
_rightVisible = true;
if (!_rightPinned) _rightHover = true;
if (Platform.isAndroid || Platform.isIOS) {
_rightPinned = true;
} else if (!_rightPinned) {
_rightHover = true;
}
}
}),
child: Container(
@@ -784,7 +826,7 @@ class _AppShellState extends State<AppShell> {
Widget _leftPanel(Tokens t, {bool floating = false}) {
final bool bar = c.project.viewState.mode == ViewMode.bar;
return Container(
width: 300,
width: _leftPanelWidth,
decoration: BoxDecoration(
color: t.panel,
border: floating ? Border.all(color: t.line2) : Border(right: BorderSide(color: t.line)),
@@ -1073,15 +1115,22 @@ class _AppShellState extends State<AppShell> {
),
),
const SizedBox(width: 6),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}',
style: TextStyle(color: t.sub, fontSize: 11),
),
Text('${acts.length} 个动作', style: TextStyle(color: t.dim, fontSize: 10)),
],
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.sub, fontSize: 11),
),
Text('${acts.length} 个动作',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.dim, fontSize: 10)),
],
),
),
const SizedBox(width: 6),
InkWell(
@@ -1156,18 +1205,24 @@ class _AppShellState extends State<AppShell> {
),
),
const SizedBox(width: 6),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
bar
? '${a.startAngle.toStringAsFixed(0)}° – ${math.min(a.endAngle, 360).toStringAsFixed(0)}°'
: 'L${a.layer + 1}',
style: TextStyle(color: t.sub, fontSize: 10),
),
Text(tfmt(a.durationAngle / 360 * c.project.cycle.durationMs, c.project.units),
style: TextStyle(color: t.dim, fontSize: 10)),
],
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
bar
? '${a.startAngle.toStringAsFixed(0)}° – ${math.min(a.endAngle, 360).toStringAsFixed(0)}°'
: 'L${a.layer + 1}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.sub, fontSize: 10),
),
Text(tfmt(a.durationAngle / 360 * c.project.cycle.durationMs, c.project.units),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.dim, fontSize: 10)),
],
),
),
const SizedBox(width: 6),
InkWell(
@@ -1331,7 +1386,7 @@ class _AppShellState extends State<AppShell> {
final Action? a = c.selected;
final bool bar = c.project.viewState.mode == ViewMode.bar;
return Container(
width: 340,
width: _rightPanelWidth,
decoration: BoxDecoration(
color: t.panel,
border: floating ? Border.all(color: t.line2) : Border(left: BorderSide(color: t.line)),
+20 -15
View File
@@ -98,7 +98,11 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
super.initState();
String start = widget.initialPath ?? '';
if (start.isEmpty) {
start = Platform.environment['USERPROFILE'] ?? Directory.current.path;
// 桌面版从用户目录开始;Android/iOS 从应用可写目录(系统临时目录)开始。
start = Platform.environment['USERPROFILE'] ??
(Platform.isAndroid || Platform.isIOS
? Directory.systemTemp.path
: Directory.current.path);
}
if (File(start).existsSync()) {
start = File(start).parent.path;
@@ -218,21 +222,22 @@ class _FileBrowserDialogState extends State<FileBrowserDialog> {
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
// 桌面快捷入口:导出 / 打开 / 保存时一键跳到桌面。
Padding(
padding: const EdgeInsets.only(right: 6),
child: ActionChip(
avatar: Icon(Icons.desktop_windows_outlined, size: 15, color: t.accent),
label: const Text('桌面'),
onPressed: () {
final Directory? d = _desktop();
if (d != null) {
_dir = d;
_refresh();
}
},
// 桌面快捷入口:仅在桌面平台显示(移动平台无“桌面”概念)。
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS)
Padding(
padding: const EdgeInsets.only(right: 6),
child: ActionChip(
avatar: Icon(Icons.desktop_windows_outlined, size: 15, color: t.accent),
label: const Text('桌面'),
onPressed: () {
final Directory? d = _desktop();
if (d != null) {
_dir = d;
_refresh();
}
},
),
),
),
...drives.map((String d) {
return Padding(
padding: const EdgeInsets.only(right: 6),