api修改和更新检查器修改
modrinth_api.dart:拦截器改为只替换 options.baseUrl,path 保持相对 /v2/search、query 留在 queryParameters,避免"整串写回 path"导致的 host 缺失 + query 重复拼接。mirror_service.dart:新增 apiBase getter,返回当前镜像的 API base(official→api.modrinth.com、mcim→modrinth-api.mcimirror.top、custom→自定义 base) Signed-off-by: driftinblock <3480428251@qq.com>
This commit is contained in:
35 files changed
+4171
-1325
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/l10n/strings.dart';
|
||||
import '../widgets/z_widgets.dart';
|
||||
|
||||
/// 统一的「需要先选服务器 / 未配置」引导空状态页。
|
||||
/// 自带 AppBar 标题栏,避免页面看起来空白、引导文字无处安放。
|
||||
@@ -24,7 +25,7 @@ class EmptyStatePage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: T(title)),
|
||||
appBar: ZAppBar(title: T(title)),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/strings.dart';
|
||||
import '../utils/release_notes.dart';
|
||||
import '../utils/update_info.dart';
|
||||
|
||||
/// 检查更新详情弹窗:版本号、发布时间、发布页和解析后的更新日志。
|
||||
class UpdateDialog extends StatelessWidget {
|
||||
final UpdateInfo info;
|
||||
final String currentVersion;
|
||||
final VoidCallback onUpdate;
|
||||
final ValueChanged<String> onOpenUrl;
|
||||
|
||||
const UpdateDialog({
|
||||
super.key,
|
||||
required this.info,
|
||||
required this.currentVersion,
|
||||
required this.onUpdate,
|
||||
required this.onOpenUrl,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final notes = ReleaseNotes.parse(info.releaseNotes);
|
||||
final maxHeight = MediaQuery.sizeOf(context).height * 0.82;
|
||||
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 560, maxHeight: maxHeight),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 20, 24, 4),
|
||||
child: Text(
|
||||
S.t('发现新版本'),
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(24, 12, 24, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_InfoRow(label: S.t('版本号'), value: info.latestVersion),
|
||||
const SizedBox(height: 7),
|
||||
if (info.releasedAt != null) ...[
|
||||
_InfoRow(
|
||||
label: S.t('更新时间'),
|
||||
value: _formatDateTime(info.releasedAt!),
|
||||
),
|
||||
const SizedBox(height: 7),
|
||||
],
|
||||
_InfoRow(
|
||||
label: S.t('当前版本'),
|
||||
value: currentVersion,
|
||||
),
|
||||
if (info.releasePageUrl.isNotEmpty) ...[
|
||||
const SizedBox(height: 10),
|
||||
_InfoRow(
|
||||
label: S.t('更新发布页'),
|
||||
value: 'Gitee',
|
||||
link: true,
|
||||
onTap: () => onOpenUrl(info.releasePageUrl),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
S.t('更新内容'),
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (notes.isEmpty)
|
||||
Text(
|
||||
S.t('本次更新暂无详细说明'),
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
)
|
||||
else
|
||||
..._buildSections(context, notes.sections),
|
||||
if (notes.links.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
...notes.links.map(
|
||||
(link) => _NoteLink(
|
||||
label: link.label,
|
||||
onTap: () => onOpenUrl(link.url),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(height: 1, color: scheme.outlineVariant),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
if (info.releasePageUrl.isNotEmpty)
|
||||
TextButton(
|
||||
onPressed: () => onOpenUrl(info.releasePageUrl),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
child: T('查看发布页'),
|
||||
),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
child: T('忽略'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
onUpdate();
|
||||
},
|
||||
child: T('立即更新'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildSections(
|
||||
BuildContext context,
|
||||
List<ReleaseNoteSection> sections,
|
||||
) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final widgets = <Widget>[];
|
||||
|
||||
for (var i = 0; i < sections.length; i++) {
|
||||
final section = sections[i];
|
||||
if (i > 0) widgets.add(const SizedBox(height: 14));
|
||||
widgets.add(
|
||||
Text(
|
||||
S.t(section.title),
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: scheme.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
for (final item in section.items) {
|
||||
widgets.add(const SizedBox(height: 6));
|
||||
if (item.bullet) {
|
||||
widgets.add(
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 1),
|
||||
child: Text(
|
||||
'•',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: scheme.primary,
|
||||
height: 1.55,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.text,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(height: 1.55),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
widgets.add(
|
||||
Text(
|
||||
item.text,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(height: 1.55),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return widgets;
|
||||
}
|
||||
}
|
||||
|
||||
/// 「版本号:xxx」形式的单行信息。
|
||||
class _InfoRow extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
final bool link;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _InfoRow({
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.link = false,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final separator = S.en ? ': ' : ':';
|
||||
final valueStyle = TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: link ? scheme.primary : scheme.onSurface,
|
||||
);
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$label$separator',
|
||||
style: TextStyle(fontSize: 13.5, color: scheme.onSurfaceVariant),
|
||||
),
|
||||
Expanded(
|
||||
child: link
|
||||
? InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(value, style: valueStyle),
|
||||
const SizedBox(width: 2),
|
||||
Icon(
|
||||
Icons.open_in_new,
|
||||
size: 14,
|
||||
color: scheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(value, style: valueStyle),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 发布说明底部提取出的可点击链接。
|
||||
class _NoteLink extends StatelessWidget {
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _NoteLink({required this.label, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: onTap,
|
||||
icon: Icon(Icons.link, size: 17, color: scheme.primary),
|
||||
label: Text(S.t(label)),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: scheme.primary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
minimumSize: const Size(0, 36),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime value) {
|
||||
final local = value.toLocal();
|
||||
String two(int number) => number.toString().padLeft(2, '0');
|
||||
|
||||
if (S.en) {
|
||||
return '${local.year}-${two(local.month)}-${two(local.day)} '
|
||||
'${two(local.hour)}:${two(local.minute)}:${two(local.second)}';
|
||||
}
|
||||
return '${local.year}年${two(local.month)}月${two(local.day)}日 '
|
||||
'${two(local.hour)}:${two(local.minute)}:${two(local.second)}';
|
||||
}
|
||||
@@ -0,0 +1,559 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../l10n/strings.dart';
|
||||
import '../../providers/wallpaper_provider.dart';
|
||||
|
||||
/// ZL2 风格的通用视觉组件集合。
|
||||
///
|
||||
/// 设计要点(与 ZalithLauncher 保持一致的观感):
|
||||
/// - **分组圆角面板**:一组相关设置包在 18px 圆角容器里,行与行之间用极细
|
||||
/// 分隔线,而不是每行一张 Card。这样竖屏下信息密度更高、层级更清晰。
|
||||
/// - **两行行样式**:左侧「粗标题 + 小字灰色说明」,右侧「当前值 / 控件 / 箭头」。
|
||||
/// 说明文字用较小字号 + 降低不透明度,形成明确的视觉主次。
|
||||
/// - **圆形勾选钮**:开关不用 Material Switch,而用 46px 圆形按钮,
|
||||
/// 选中时绿底白勾(ZL2 的标志性元素)。
|
||||
///
|
||||
/// 所有组件都接受 [hasWallpaper],在有自定义壁纸时自动切换为半透明深色
|
||||
/// 浮层 + 白色文字,保证文字在任意背景下都能读清。
|
||||
|
||||
/// ZL2 主色:勾选钮/选中态统一使用的绿色。
|
||||
const Color kZAccent = Color(0xFF4CAF50);
|
||||
|
||||
/// ZL2 圆角:分组面板与内部行的圆角。
|
||||
const double kZRadius = 18.0;
|
||||
|
||||
/// 分组面板的着色与文字色工具。
|
||||
///
|
||||
/// 把「有壁纸 / 无壁纸」两套配色集中在这里,避免每个页面各写一遍
|
||||
/// `Colors.black.withOpacity(0.45)` 之类的魔数。
|
||||
class ZStyle {
|
||||
final bool hasWallpaper;
|
||||
final ColorScheme scheme;
|
||||
|
||||
const ZStyle({required this.hasWallpaper, required this.scheme});
|
||||
|
||||
/// 从 BuildContext 推导(需要外部传入 hasWallpaper)。
|
||||
factory ZStyle.of(BuildContext context, {required bool hasWallpaper}) =>
|
||||
ZStyle(hasWallpaper: hasWallpaper, scheme: Theme.of(context).colorScheme);
|
||||
|
||||
/// 面板底色:有壁纸时半透明黑浮层,否则用主题的低层容器色。
|
||||
Color get panelColor =>
|
||||
hasWallpaper ? Colors.black.withOpacity(0.45) : scheme.surfaceContainerLow;
|
||||
|
||||
/// 主文字色。
|
||||
Color get titleColor => hasWallpaper ? Colors.white : scheme.onSurface;
|
||||
|
||||
/// 次要说明文字色。
|
||||
Color get subColor =>
|
||||
hasWallpaper ? Colors.white.withOpacity(0.62) : scheme.onSurfaceVariant;
|
||||
|
||||
/// 分隔线色。
|
||||
Color get dividerColor =>
|
||||
hasWallpaper ? Colors.white.withOpacity(0.10) : scheme.outlineVariant;
|
||||
|
||||
/// 面板描边色(浅色主题下几乎不可见,仅用于在深色壁纸上勾出边界)。
|
||||
Color get borderColor => Colors.white.withOpacity(0.08);
|
||||
}
|
||||
|
||||
/// 分组面板:圆角容器 + 子行纵向排列。
|
||||
///
|
||||
/// 用法:把若干 [ZRow] 之间用 [ZDivider] 隔开后放进 children。
|
||||
class ZPanel extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
final ZStyle style;
|
||||
|
||||
const ZPanel({super.key, required this.style, required this.children});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: style.panelColor,
|
||||
borderRadius: BorderRadius.circular(kZRadius),
|
||||
border: Border.all(color: style.borderColor, width: 1),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 面板内的行分隔线(左右各留 16 的缩进)。
|
||||
class ZDivider extends StatelessWidget {
|
||||
final ZStyle style;
|
||||
const ZDivider({super.key, required this.style});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Divider(height: 1, thickness: 1, color: style.dividerColor),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 两行式设置行:粗标题 + 灰色说明 + 右侧值/控件/箭头。
|
||||
///
|
||||
/// - [onTap] 为空时整行不可点击(纯展示行),也不显示右侧箭头;
|
||||
/// - [trailing] 与 [value] 可同时存在;都没有且 [onTap] 不为空时显示 chevron。
|
||||
/// - [leading] 可选,用于在标题左侧放一个小图标(如日志文件行)。
|
||||
class ZRow extends StatelessWidget {
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final ZStyle style;
|
||||
final Widget? leading;
|
||||
final Widget? trailing;
|
||||
final String? value;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
/// 标题用主题色的强调样式(如危险操作变红)。
|
||||
final Color? titleOverride;
|
||||
|
||||
const ZRow({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.style,
|
||||
this.subtitle,
|
||||
this.leading,
|
||||
this.trailing,
|
||||
this.value,
|
||||
this.onTap,
|
||||
this.titleOverride,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final showChevron = trailing == null && onTap != null;
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(kZRadius),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 14, 12, 14),
|
||||
child: Row(
|
||||
children: [
|
||||
if (leading != null) ...[
|
||||
leading!,
|
||||
const SizedBox(width: 12),
|
||||
],
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
S.t(title),
|
||||
style: TextStyle(
|
||||
fontSize: 15.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: titleOverride ?? style.titleColor,
|
||||
),
|
||||
),
|
||||
if (subtitle != null && subtitle!.isNotEmpty) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
S.t(subtitle!),
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.35,
|
||||
color: style.subColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (value != null) ...[
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Text(
|
||||
value!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(fontSize: 13, color: style.subColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (trailing != null) ...[
|
||||
const SizedBox(width: 10),
|
||||
trailing!,
|
||||
] else if (showChevron) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.chevron_right, size: 20, color: style.subColor),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ZL2 式圆形勾选开关:选中为绿底白勾,未选中为描边空心圆。
|
||||
class ZToggle extends StatelessWidget {
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
/// 直径,设置页用 46,列表行内可用 40。
|
||||
final double size;
|
||||
|
||||
/// 未选中时描边颜色(有壁纸时传白色系)。
|
||||
final Color? borderColor;
|
||||
|
||||
const ZToggle({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.size = 46,
|
||||
this.borderColor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dim = borderColor ?? Colors.white54;
|
||||
return GestureDetector(
|
||||
onTap: () => onChanged(!value),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
width: size,
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: value ? kZAccent : Colors.transparent,
|
||||
border: Border.all(color: value ? kZAccent : dim, width: 2),
|
||||
),
|
||||
child: value
|
||||
? Icon(Icons.check, size: size * 0.52, color: Colors.white)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 圆形选择钮组:一组互斥选项,选中项显示绿底白勾,未选中显示图标。
|
||||
///
|
||||
/// 用于「亮色 / 暗色 / 跟随系统」这类三选一,也可复用到镜像线路等单选场景。
|
||||
class ZSegmentedCircles<T> extends StatelessWidget {
|
||||
final List<ZCircleOption<T>> options;
|
||||
final T value;
|
||||
final ValueChanged<T> onChanged;
|
||||
final Color onSurface;
|
||||
final double size;
|
||||
|
||||
const ZSegmentedCircles({
|
||||
super.key,
|
||||
required this.options,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
required this.onSurface,
|
||||
this.size = 38,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final o in options)
|
||||
GestureDetector(
|
||||
onTap: () => onChanged(o.value),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
width: size,
|
||||
height: size,
|
||||
margin: const EdgeInsets.only(left: 6),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: value == o.value ? kZAccent : Colors.transparent,
|
||||
border: Border.all(
|
||||
color: value == o.value
|
||||
? kZAccent
|
||||
: onSurface.withOpacity(0.35),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
value == o.value ? Icons.check : o.icon,
|
||||
size: size * 0.53,
|
||||
color: value == o.value
|
||||
? Colors.white
|
||||
: onSurface.withOpacity(0.7),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// [ZSegmentedCircles] 的单个选项描述。
|
||||
class ZCircleOption<T> {
|
||||
final T value;
|
||||
final IconData icon;
|
||||
const ZCircleOption({required this.value, required this.icon});
|
||||
}
|
||||
|
||||
/// 小块状态胶囊(在线/离线、下载状态等),比 Chip 更紧凑。
|
||||
class ZBadge extends StatelessWidget {
|
||||
final String label;
|
||||
final Color color;
|
||||
final bool outlined;
|
||||
const ZBadge({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.color,
|
||||
this.outlined = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.13),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: outlined ? Border.all(color: color.withOpacity(0.28)) : null,
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
height: 1.3,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ZL2 风格的弹层/列表行:左侧彩色图标块 + 粗标题 + 可选说明 + 右侧控件/箭头。
|
||||
///
|
||||
/// 用于替换旧式 [ListTile](底部弹层、对话框、详情页头部、依赖列表等):
|
||||
/// - [icon] + [iconColor] 决定左侧圆角图标块(默认绿色,危险操作用红色);
|
||||
/// - [subtitleMono] 让说明文字用等宽字体(如命令、文件名);
|
||||
/// - 有 [onTap] 且无 [trailing] 时显示右侧 chevron;[danger] 让标题与图标变红。
|
||||
class ZSheetRow extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final Color? iconColor;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final bool subtitleMono;
|
||||
final Widget? trailing;
|
||||
final VoidCallback? onTap;
|
||||
final bool danger;
|
||||
|
||||
const ZSheetRow({
|
||||
super.key,
|
||||
required this.icon,
|
||||
this.iconColor,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.subtitleMono = false,
|
||||
this.trailing,
|
||||
this.onTap,
|
||||
this.danger = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final color = danger ? Colors.red : (iconColor ?? kZAccent);
|
||||
final showChevron = trailing == null && onTap != null;
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 38,
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.13),
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Icon(icon, size: 20, color: color),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
S.t(title),
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: danger ? Colors.red : scheme.onSurface,
|
||||
),
|
||||
),
|
||||
if (subtitle != null && subtitle!.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
S.t(subtitle!),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
height: 1.35,
|
||||
fontFamily: subtitleMono ? 'monospace' : null,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (trailing != null) ...[
|
||||
const SizedBox(width: 8),
|
||||
trailing!,
|
||||
] else if (showChevron) ...[
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.chevron_right, size: 20, color: scheme.onSurfaceVariant),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ZL2 风格的顶部搜索框(圆角填充、无边框)。
|
||||
class ZSearchField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final String hint;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final Widget? trailing;
|
||||
|
||||
const ZSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hint,
|
||||
this.onSubmitted,
|
||||
this.onChanged,
|
||||
this.trailing,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHigh,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.search, size: 20, color: scheme.onSurfaceVariant),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
onSubmitted: onSubmitted,
|
||||
onChanged: onChanged,
|
||||
decoration: InputDecoration(
|
||||
hintText: S.t(hint),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 13),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (trailing != null) trailing!,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// ZL2 风格的沉浸式 AppBar。
|
||||
///
|
||||
/// 全局 [appBarTheme] 已把底色设为透明,这里再统一处理「前景色」与「状态栏」,
|
||||
/// 避免两类问题:
|
||||
/// 1. 有壁纸时顶栏文字/图标仍是深色 → 看不清;
|
||||
/// 2. 切页时顶栏在「白不透明 ↔ 透明」之间跳变 → 视觉闪烁。
|
||||
///
|
||||
/// 有自定义壁纸时:标题/图标转白、状态栏图标转浅色;无壁纸时跟随主题。
|
||||
/// 接受与 [AppBar] 同名的常用参数,可直接替换页面里的 `AppBar(`,无需改动其余代码。
|
||||
class ZAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
final Widget? title;
|
||||
final String? subtitle;
|
||||
final List<Widget>? actions;
|
||||
final PreferredSizeWidget? bottom;
|
||||
final Widget? leading;
|
||||
final bool automaticallyImplyLeading;
|
||||
final Color? backgroundColor;
|
||||
final Color? foregroundColor;
|
||||
final SystemUiOverlayStyle? systemOverlayStyle;
|
||||
final double? elevation;
|
||||
final double? scrolledUnderElevation;
|
||||
|
||||
const ZAppBar({
|
||||
super.key,
|
||||
this.title,
|
||||
this.subtitle,
|
||||
this.actions,
|
||||
this.bottom,
|
||||
this.leading,
|
||||
this.automaticallyImplyLeading = true,
|
||||
this.backgroundColor,
|
||||
this.foregroundColor,
|
||||
this.systemOverlayStyle,
|
||||
this.elevation,
|
||||
this.scrolledUnderElevation,
|
||||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize =>
|
||||
Size.fromHeight(kToolbarHeight + (bottom?.preferredSize.height ?? 0));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasWallpaper = context.watch<WallpaperProvider>().hasWallpaper;
|
||||
final titleWidget = (subtitle == null || subtitle!.isEmpty)
|
||||
? title
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (title != null) title!,
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.2,
|
||||
color: hasWallpaper
|
||||
? Colors.white.withOpacity(0.72)
|
||||
: Theme.of(context).hintColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
return AppBar(
|
||||
leading: leading,
|
||||
automaticallyImplyLeading: automaticallyImplyLeading,
|
||||
title: titleWidget,
|
||||
actions: actions,
|
||||
bottom: bottom,
|
||||
elevation: elevation ?? 0,
|
||||
scrolledUnderElevation: scrolledUnderElevation ?? 0,
|
||||
backgroundColor: backgroundColor ?? (hasWallpaper ? Colors.transparent : null),
|
||||
foregroundColor: foregroundColor ?? (hasWallpaper ? Colors.white : null),
|
||||
systemOverlayStyle: systemOverlayStyle ??
|
||||
(hasWallpaper
|
||||
? const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
)
|
||||
: null),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user