Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat(onboarding): redesign setup

Predidit2d39ecbdc22e
diff --git a/lib/bean/settings/network_mirror_settings.dart b/lib/bean/settings/network_mirror_settings.dart
new file mode 100644
index 00000000..c3a37daf
--- /dev/null
+++ b/lib/bean/settings/network_mirror_settings.dart
@@ -0,0 +1,41 @@
+import 'package:flutter/material.dart';
+import 'package:kazumi/bean/settings/settings_list.dart';
+
+class NetworkMirrorSettings extends StatelessWidget {
+ const NetworkMirrorSettings({
+ super.key,
+ required this.enableBangumiProxy,
+ required this.enableGitProxy,
+ required this.onBangumiChanged,
+ required this.onGitChanged,
+ this.margin,
+ });
+
+ final bool enableBangumiProxy;
+ final bool enableGitProxy;
+ final ValueChanged<bool> onBangumiChanged;
+ final ValueChanged<bool> onGitChanged;
+ final EdgeInsetsGeometry? margin;
+
+ @override
+ Widget build(BuildContext context) => SettingsSection(
+ title: const Text('访问加速'),
+ margin: margin,
+ tiles: [
+ SettingsTile.switchTile(
+ leading: Icons.travel_explore_rounded,
+ title: const Text('Bangumi 镜像'),
+ description: const Text('加速番剧信息、热门与时间表加载'),
+ initialValue: enableBangumiProxy,
+ onToggle: (value) => onBangumiChanged(value ?? !enableBangumiProxy),
+ ),
+ SettingsTile.switchTile(
+ leading: Icons.extension_rounded,
+ title: const Text('规则仓库镜像'),
+ description: const Text('加速规则的下载与更新'),
+ initialValue: enableGitProxy,
+ onToggle: (value) => onGitChanged(value ?? !enableGitProxy),
+ ),
+ ],
+ );
+}
diff --git a/lib/bean/widget/split_list_row.dart b/lib/bean/widget/split_list_row.dart
index 5f71f8f3..183a9da0 100644
--- a/lib/bean/widget/split_list_row.dart
+++ b/lib/bean/widget/split_list_row.dart
@@ -55,7 +55,9 @@ class _SplitListRowState extends State<SplitListRow> {
);
// Animate color as well as shape; Material alone snaps color changes.
return AnimatedContainer(
- duration: splitListMotionDuration,
+ duration: MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : splitListMotionDuration,
curve: splitListMotionCurve,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
diff --git a/lib/pages/onboarding/onboarding_page.dart b/lib/pages/onboarding/onboarding_page.dart
index 58f94c78..40f5cc0e 100644
--- a/lib/pages/onboarding/onboarding_page.dart
+++ b/lib/pages/onboarding/onboarding_page.dart
@@ -12,6 +12,7 @@ import 'package:kazumi/pages/onboarding/steps/disclaimer_step.dart';
import 'package:kazumi/pages/onboarding/steps/mirror_settings_step.dart';
import 'package:kazumi/pages/onboarding/steps/plugin_shop_step.dart';
import 'package:kazumi/pages/onboarding/steps/update_source_step.dart';
+import 'package:kazumi/plugins/plugins.dart' show pluginNameKey;
import 'package:kazumi/plugins/plugins_controller.dart';
import 'package:kazumi/services/logging/logger.dart';
import 'package:kazumi/services/storage/storage.dart';
@@ -31,243 +32,321 @@ class OnboardingPage extends StatefulWidget {
State<OnboardingPage> createState() => _OnboardingPageState();
}
+enum _OnboardingStep {
+ welcome('使用约定'),
+ updates('更新来源'),
+ mirrors('网络镜像'),
+ rules('添加规则');
+
+ const _OnboardingStep(this.label);
+
+ final String label;
+}
+
class _OnboardingPageState extends State<OnboardingPage> {
- final PageController pageController = PageController();
- int currentIndex = 0;
- bool agreed = false;
- bool installingBundled = false;
- bool useGithubUpdate = true;
+ final _pageController = PageController();
+ final _steps = [
+ _OnboardingStep.welcome,
+ if (Platform.isAndroid) _OnboardingStep.updates,
+ _OnboardingStep.mirrors,
+ _OnboardingStep.rules,
+ ];
+ int _currentIndex = 0;
+ bool _agreed = false;
+ bool _installingBundled = false;
+ bool _busy = false;
+ late bool _useGithubUpdate;
+ late Set<String> _initialPluginNames;
- PluginsController get pluginsController => widget.pluginsController;
+ PluginsController get _pluginsController => widget.pluginsController;
+ bool get _isLastStep => _currentIndex == _steps.length - 1;
- int get stepCount => Platform.isAndroid ? 4 : 3;
+ @override
+ void initState() {
+ super.initState();
+ _useGithubUpdate = GStorage.getSetting(SettingsKeys.autoUpdate);
+ }
@override
void dispose() {
- pageController.dispose();
+ _pageController.dispose();
super.dispose();
}
- List<Widget> _buildStepBodies() {
- return [
- const DisclaimerStep(),
- if (Platform.isAndroid)
- UpdateSourceStep(
- useGithubUpdate: useGithubUpdate,
- onChanged: (value) {
- GStorage.putSetting(SettingsKeys.autoUpdate, value);
- setState(() {
- useGithubUpdate = value;
- });
- },
- ),
- const MirrorSettingsStep(),
- PluginShopStep(controller: pluginsController),
- ];
- }
-
- String get primaryLabel {
- if (currentIndex == 0 && !agreed) {
- return '同意并继续';
- }
- return currentIndex == stepCount - 1 ? '完成' : '下一步';
- }
+ Widget _buildStep(_OnboardingStep step) => switch (step) {
+ _OnboardingStep.welcome => const DisclaimerStep(),
+ _OnboardingStep.updates => UpdateSourceStep(
+ useGithubUpdate: _useGithubUpdate,
+ onChanged: (value) {
+ setState(() => _useGithubUpdate = value);
+ unawaited(GStorage.putSetting(SettingsKeys.autoUpdate, value));
+ },
+ ),
+ _OnboardingStep.mirrors => const MirrorSettingsStep(),
+ _OnboardingStep.rules => PluginShopStep(controller: _pluginsController),
+ };
- void _goToPage(int index) {
- pageController.animateToPage(
- index,
- duration: const Duration(milliseconds: 300),
- curve: Curves.easeOutCubic,
- );
- }
+ String get _primaryLabel => !_agreed
+ ? '同意并继续'
+ : _isLastStep
+ ? '开始使用'
+ : '继续';
- void _previousPage() {
- if (currentIndex > 0) {
- _goToPage(currentIndex - 1);
+ Future<void> _navigate({required bool forward}) async {
+ if (_busy || (!forward && _currentIndex == 0)) return;
+ _busy = true;
+ try {
+ if (forward && !_agreed && !await _installBundledRules()) return;
+ if (!mounted) return;
+ if (forward && _isLastStep) {
+ await _finish();
+ } else {
+ await _goToPage(_currentIndex + (forward ? 1 : -1));
+ }
+ } finally {
+ _busy = false;
}
}
- void _nextPage() {
- if (currentIndex < stepCount - 1) {
- _goToPage(currentIndex + 1);
+ Future<void> _goToPage(int index) async {
+ FocusManager.instance.primaryFocus?.unfocus();
+ if (MediaQuery.disableAnimationsOf(context)) {
+ _pageController.jumpToPage(index);
} else {
- _finish();
+ await _pageController.animateToPage(
+ index,
+ duration: const Duration(milliseconds: 400),
+ curve: Curves.easeInOutCubicEmphasized,
+ );
}
}
- Future<void> _agree() async {
- if (agreed) {
- _nextPage();
- return;
- }
- setState(() {
- installingBundled = true;
- });
+ Future<bool> _installBundledRules() async {
+ setState(() => _installingBundled = true);
try {
- await pluginsController.copyPluginsToExternalDirectory();
+ await _pluginsController.copyPluginsToExternalDirectory();
} catch (error, stackTrace) {
KazumiLogger().e(
'Plugin: failed to install bundled rules',
error: error,
stackTrace: stackTrace,
);
- if (mounted) {
- setState(() {
- installingBundled = false;
- });
- }
- KazumiDialog.showToast(message: '初始化规则失败');
- return;
- }
- if (!mounted) {
- return;
+ if (!mounted) return false;
+ setState(() => _installingBundled = false);
+ KazumiDialog.showToast(context: context, message: '初始化规则失败');
+ return false;
}
+ if (!mounted) return false;
+ _initialPluginNames = _pluginsController.pluginList
+ .map((plugin) => pluginNameKey(plugin.name))
+ .toSet();
setState(() {
- agreed = true;
- installingBundled = false;
+ _agreed = true;
+ _installingBundled = false;
});
- _nextPage();
+ return true;
}
- void _handlePrimary() {
- if (currentIndex == 0) {
- unawaited(_agree());
- } else {
- _nextPage();
+ Future<void> _finish() async {
+ // Updating a bundled rule must not count as installing an extra source.
+ final hasExtraRules = _pluginsController.pluginList.any(
+ (plugin) => !_initialPluginNames.contains(pluginNameKey(plugin.name)));
+ if (!hasExtraRules) {
+ final confirmed = await KazumiDialog.show<bool>(
+ context: context,
+ builder: (_) => const _SkipRulesDialog(),
+ );
+ if (confirmed != true) return;
}
- }
-
- void _finish() {
+ if (!mounted) return;
final myController = widget.myController;
unawaited(runStartupUpdateCheck(
isEnabled: () => GStorage.getSetting(SettingsKeys.autoUpdate),
- checkForUpdate: () async {
- await myController.checkUpdate(type: 'auto');
- },
+ checkForUpdate: () => myController.checkUpdate(type: 'auto'),
));
context.navigate(GStorage.getSetting(SettingsKeys.defaultStartupPage));
}
Widget _buildBottomBar(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- return SafeArea(
- top: false,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
- child: Row(
- children: [
- if (currentIndex == 0)
- TextButton(
- onPressed: () => exit(0),
- child: Text(
- '退出',
- style: TextStyle(color: colorScheme.outline),
- ),
- )
- else
- TextButton(
- onPressed: _previousPage,
- child: const Text('上一步'),
- ),
- Expanded(
- child: Center(
- child: _PageIndicator(
- count: stepCount,
- currentIndex: currentIndex,
- ),
- ),
- ),
- FilledButton(
- onPressed: installingBundled ? null : _handlePrimary,
- child: installingBundled
- ? const SizedBox(
- width: 18,
- height: 18,
- child: LoadingIndicator(),
- )
- : Text(primaryLabel),
- ),
- ],
+ final theme = Theme.of(context);
+ return LayoutBuilder(builder: (context, constraints) {
+ final stacked = constraints.maxWidth < 320 ||
+ MediaQuery.textScalerOf(context).scale(16) > 24;
+ final secondary = TextButton(
+ style: TextButton.styleFrom(
+ minimumSize: const Size(88, 56),
+ foregroundColor: theme.colorScheme.onSurfaceVariant,
),
- ),
- );
+ onPressed: _installingBundled
+ ? null
+ : _currentIndex == 0
+ ? () => exit(0)
+ : () => _navigate(forward: false),
+ child: Text(_currentIndex == 0 ? '退出' : '上一步'),
+ );
+ final primary = FilledButton.icon(
+ style: FilledButton.styleFrom(
+ minimumSize: const Size(176, 56),
+ padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
+ textStyle: theme.textTheme.titleMedium
+ ?.copyWith(fontWeight: FontWeight.w600),
+ ),
+ onPressed: _installingBundled ? null : () => _navigate(forward: true),
+ iconAlignment: IconAlignment.end,
+ icon: _installingBundled
+ ? const LoadingIndicator(size: 24, semanticsLabel: '正在准备内置规则')
+ : Icon(_isLastStep
+ ? Icons.check_rounded
+ : Icons.arrow_forward_rounded),
+ label: Text(_installingBundled ? '正在准备' : _primaryLabel),
+ );
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ child: stacked
+ ? Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [primary, const SizedBox(height: 4), secondary],
+ )
+ : Row(children: [
+ secondary,
+ const SizedBox(width: 16),
+ const Spacer(),
+ primary,
+ ]),
+ );
+ });
}
@override
- Widget build(BuildContext context) {
- return PopScope(
- canPop: false,
- onPopInvokedWithResult: (bool didPop, Object? result) {
- if (didPop) {
- return;
- }
- _previousPage();
- },
- child: Scaffold(
- appBar: const SysAppBar(),
- body: Column(
- children: [
- Expanded(
- child: PageView(
- controller: pageController,
- physics: agreed ? null : const NeverScrollableScrollPhysics(),
- onPageChanged: (index) {
- setState(() {
- currentIndex = index;
- });
- },
- children: [
- for (final body in _buildStepBodies())
- Center(
- child: ConstrainedBox(
- constraints: const BoxConstraints(maxWidth: 600),
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 24),
- child: body,
+ Widget build(BuildContext context) => PopScope(
+ canPop: false,
+ onPopInvokedWithResult: (bool didPop, Object? result) {
+ if (!didPop) unawaited(_navigate(forward: false));
+ },
+ child: Scaffold(
+ appBar: const SysAppBar(),
+ body: SafeArea(
+ top: false,
+ child: Center(
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 1184),
+ child: Padding(
+ padding: EdgeInsets.symmetric(
+ horizontal:
+ MediaQuery.sizeOf(context).width < 600 ? 20 : 32),
+ child: Column(
+ children: [
+ _OnboardingProgress(
+ labels: _steps.map((step) => step.label).toList(),
+ currentIndex: _currentIndex,
+ ),
+ Expanded(
+ child: PageView(
+ controller: _pageController,
+ physics: _agreed
+ ? null
+ : const NeverScrollableScrollPhysics(),
+ onPageChanged: (index) {
+ setState(() => _currentIndex = index);
+ },
+ children: _steps.map(_buildStep).toList(),
),
),
- ),
- ],
+ _buildBottomBar(context),
+ ],
+ ),
+ ),
),
),
- _buildBottomBar(context),
- ],
+ ),
),
- ),
- );
- }
+ );
+}
+
+class _SkipRulesDialog extends StatelessWidget {
+ const _SkipRulesDialog();
+
+ @override
+ Widget build(BuildContext context) => AlertDialog(
+ scrollable: true,
+ constraints: const BoxConstraints(maxWidth: 560),
+ icon: const Icon(Icons.warning_amber_rounded),
+ title: const Text('暂不添加规则?'),
+ content: const Text(
+ '你还没有安装额外规则。仅使用内置规则可能导致部分番剧无法搜索或播放,影响观看体验。\n\n确定仍要继续吗?',
+ ),
+ actions: [
+ TextButton(
+ onPressed: () => Navigator.of(context).pop(true),
+ child: const Text('仍然继续'),
+ ),
+ FilledButton(
+ autofocus: true,
+ onPressed: () => Navigator.of(context).pop(false),
+ child: const Text('返回安装'),
+ ),
+ ],
+ );
}
-class _PageIndicator extends StatelessWidget {
- const _PageIndicator({
- required this.count,
+class _OnboardingProgress extends StatelessWidget {
+ const _OnboardingProgress({
+ required this.labels,
required this.currentIndex,
});
- final int count;
+ final List<String> labels;
final int currentIndex;
@override
Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- for (int i = 0; i < count; i++)
- AnimatedContainer(
- duration: const Duration(milliseconds: 250),
- curve: Curves.easeOutCubic,
- margin: const EdgeInsets.symmetric(horizontal: 4),
- width: i == currentIndex ? 24 : 8,
- height: 8,
- decoration: BoxDecoration(
- color: i == currentIndex
- ? colorScheme.primary
- : colorScheme.surfaceContainerHighest,
- borderRadius: BorderRadius.circular(4),
- ),
+ final theme = Theme.of(context);
+ final colors = theme.colorScheme;
+ return Semantics(
+ label:
+ '第 ${currentIndex + 1} 步,共 ${labels.length} 步,${labels[currentIndex]}',
+ liveRegion: true,
+ child: ExcludeSemantics(
+ child: Padding(
+ padding: const EdgeInsets.only(top: 8, bottom: 12),
+ child: Column(
+ children: [
+ Row(children: [
+ Expanded(
+ child: Text(labels[currentIndex],
+ style: theme.textTheme.labelLarge?.copyWith(
+ color: colors.primary, fontWeight: FontWeight.w700)),
+ ),
+ Text('${currentIndex + 1} / ${labels.length}',
+ style: theme.textTheme.labelLarge
+ ?.copyWith(color: colors.onSurfaceVariant)),
+ ]),
+ const SizedBox(height: 12),
+ Row(children: [
+ for (var i = 0; i < labels.length; i++) ...[
+ if (i > 0) const SizedBox(width: 6),
+ Expanded(
+ child: AnimatedContainer(
+ duration: MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : const Duration(milliseconds: 250),
+ curve: Curves.easeInOutCubicEmphasized,
+ height: 6,
+ decoration: BoxDecoration(
+ color: i <= currentIndex
+ ? colors.primary
+ : colors.surfaceContainerHighest,
+ borderRadius: BorderRadius.circular(3),
+ ),
+ ),
+ ),
+ ],
+ ]),
+ ],
),
- ],
+ ),
+ ),
);
}
}
diff --git a/lib/pages/onboarding/onboarding_step_layout.dart b/lib/pages/onboarding/onboarding_step_layout.dart
index 92ccb077..f447ab77 100644
--- a/lib/pages/onboarding/onboarding_step_layout.dart
+++ b/lib/pages/onboarding/onboarding_step_layout.dart
@@ -1,66 +1,223 @@
import 'package:flutter/material.dart';
+import 'package:material_new_shapes/material_new_shapes.dart';
-/// Shared visual skeleton for onboarding steps: a leading badge, a headline,
-/// a one-line supporting text and the step content below.
+/// Keeps the rule catalog lazy within the responsive onboarding scroll surface.
class OnboardingStepLayout extends StatelessWidget {
const OnboardingStepLayout({
super.key,
required this.leading,
required this.title,
- required this.subtitle,
- required this.child,
- });
+ this.subtitle,
+ required Widget child,
+ }) : _child = child,
+ _slivers = null;
+
+ const OnboardingStepLayout.slivers({
+ super.key,
+ required this.leading,
+ required this.title,
+ this.subtitle,
+ required List<Widget> slivers,
+ }) : _slivers = slivers,
+ _child = null;
final Widget leading;
final String title;
- final String subtitle;
- final Widget child;
+ final String? subtitle;
+ final Widget? _child;
+ final List<Widget>? _slivers;
+
+ Widget _intro(BuildContext context,
+ {required bool wide, bool compact = false}) {
+ final theme = Theme.of(context);
+ final titleWidget = Semantics(
+ header: true,
+ child: Text(
+ title,
+ style: (wide
+ ? theme.textTheme.displaySmall
+ : compact
+ ? theme.textTheme.headlineSmall
+ : theme.textTheme.headlineLarge)
+ ?.copyWith(fontWeight: FontWeight.w700, height: 1.2),
+ ),
+ );
+ final description = subtitle == null
+ ? null
+ : Text(subtitle!,
+ style: theme.textTheme.bodyLarge?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant,
+ height: 1.5,
+ ));
+ if (compact) {
+ return Padding(
+ padding: const EdgeInsets.only(bottom: 24),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ExcludeSemantics(
+ child: SizedBox.square(
+ dimension: 48, child: FittedBox(child: leading)),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ titleWidget,
+ if (description != null) ...[
+ const SizedBox(height: 8),
+ description,
+ ],
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+ return Padding(
+ padding: EdgeInsets.only(bottom: wide ? 0 : 28),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ExcludeSemantics(child: leading),
+ const SizedBox(height: 24),
+ titleWidget,
+ if (description != null) ...[
+ const SizedBox(height: 12),
+ description,
+ ],
+ ],
+ ),
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) => LayoutBuilder(
+ builder: (context, constraints) {
+ final wide = constraints.maxWidth >= 840 &&
+ constraints.maxHeight >= 480 &&
+ MediaQuery.textScalerOf(context).scale(16) <= 24;
+ final compact = constraints.maxHeight < 400 ||
+ MediaQuery.textScalerOf(context).scale(16) > 24;
+ final content = _slivers ?? [SliverToBoxAdapter(child: _child!)];
+ final scrollView = CustomScrollView(
+ key: PageStorageKey('onboarding-$title-$wide'),
+ keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
+ slivers: [
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(0, 20, 0, 24),
+ sliver: SliverMainAxisGroup(slivers: [
+ if (!wide)
+ SliverToBoxAdapter(
+ child: _intro(context, wide: false, compact: compact)),
+ ...content,
+ ]),
+ ),
+ ],
+ );
+ if (!wide) return scrollView;
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ width: constraints.maxWidth * 0.34,
+ child: SingleChildScrollView(
+ padding: const EdgeInsets.only(top: 40, bottom: 24),
+ child: _intro(context, wide: true),
+ ),
+ ),
+ const SizedBox(width: 48),
+ Expanded(child: scrollView),
+ ],
+ );
+ },
+ );
+}
+
+enum OnboardingIconShape { sunny, cookie, clover, flower }
+
+class OnboardingStepIcon extends StatelessWidget {
+ const OnboardingStepIcon({
+ super.key,
+ required this.icon,
+ this.shape = OnboardingIconShape.sunny,
+ });
+
+ final IconData icon;
+ final OnboardingIconShape shape;
@override
Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- final textTheme = Theme.of(context).textTheme;
- return Column(
- children: [
- const SizedBox(height: 24),
- leading,
- const SizedBox(height: 20),
- Text(
- title,
- style: textTheme.headlineSmall,
- textAlign: TextAlign.center,
+ final colors = Theme.of(context).colorScheme;
+ final (background, foreground) = switch (shape) {
+ OnboardingIconShape.cookie => (
+ colors.secondaryContainer,
+ colors.onSecondaryContainer
+ ),
+ OnboardingIconShape.clover => (
+ colors.tertiaryContainer,
+ colors.onTertiaryContainer
),
- const SizedBox(height: 8),
- Text(
- subtitle,
- style:
- textTheme.bodyMedium?.copyWith(color: colorScheme.onSurfaceVariant),
- textAlign: TextAlign.center,
+ _ => (colors.primaryContainer, colors.onPrimaryContainer),
+ };
+ return ClipPath(
+ clipper: _StepShapeClipper(shape),
+ child: ColoredBox(
+ color: background,
+ child: SizedBox.square(
+ dimension: 88,
+ child: Icon(icon, size: 36, color: foreground),
),
- const SizedBox(height: 24),
- Expanded(child: child),
- ],
+ ),
);
}
}
-/// Circular tonal badge holding the step icon.
-class OnboardingStepIcon extends StatelessWidget {
- const OnboardingStepIcon({super.key, required this.icon});
+class _StepShapeClipper extends CustomClipper<Path> {
+ const _StepShapeClipper(this.shape);
- final IconData icon;
+ final OnboardingIconShape shape;
+ static final _paths = {
+ OnboardingIconShape.sunny: MaterialShapes.sunny.toPath(),
+ OnboardingIconShape.cookie: MaterialShapes.cookie4Sided.toPath(),
+ OnboardingIconShape.clover: MaterialShapes.clover4Leaf.toPath(),
+ OnboardingIconShape.flower: MaterialShapes.flower.toPath(),
+ };
+
+ @override
+ Path getClip(Size size) => _paths[shape]!
+ .transform(Matrix4.diagonal3Values(size.width, size.height, 1).storage);
+
+ @override
+ bool shouldReclip(_StepShapeClipper oldClipper) => oldClipper.shape != shape;
+}
+
+class OnboardingHint extends StatelessWidget {
+ const OnboardingHint({super.key, required this.text});
+
+ final String text;
@override
Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- return Container(
- width: 64,
- height: 64,
- decoration: BoxDecoration(
- color: colorScheme.secondaryContainer,
- shape: BoxShape.circle,
+ final theme = Theme.of(context);
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Icon(Icons.info_outline_rounded,
+ size: 20, color: theme.colorScheme.onSurfaceVariant),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(text,
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: theme.colorScheme.onSurfaceVariant, height: 1.5)),
+ ),
+ ],
),
- child: Icon(icon, size: 32, color: colorScheme.onSecondaryContainer),
);
}
}
diff --git a/lib/pages/onboarding/steps/disclaimer_step.dart b/lib/pages/onboarding/steps/disclaimer_step.dart
index 482b7771..bceb5342 100644
--- a/lib/pages/onboarding/steps/disclaimer_step.dart
+++ b/lib/pages/onboarding/steps/disclaimer_step.dart
@@ -14,7 +14,7 @@ class DisclaimerStep extends StatefulWidget {
}
class _DisclaimerStepState extends State<DisclaimerStep> {
- String? statementsText;
+ String? _statementsText;
@override
void initState() {
@@ -38,7 +38,7 @@ class _DisclaimerStepState extends State<DisclaimerStep> {
return;
}
setState(() {
- statementsText = text;
+ _statementsText = text;
});
}
@@ -47,17 +47,35 @@ class _DisclaimerStepState extends State<DisclaimerStep> {
final textTheme = Theme.of(context).textTheme;
return OnboardingStepLayout(
leading: const OnboardingStepIcon(icon: Icons.waving_hand_rounded),
- title: '欢迎使用',
- subtitle: '请阅读并同意免责声明',
+ title: '欢迎来到 Kazumi',
child: TonalCard(
- child: statementsText == null
- ? const Center(child: LoadingIndicator())
- : SingleChildScrollView(
- padding: const EdgeInsets.all(20),
- child: Text(
- statementsText!,
- style: textTheme.bodyMedium?.copyWith(height: 1.7),
- ),
+ padding: const EdgeInsets.all(24),
+ child: _statementsText == null
+ ? const Padding(
+ padding: EdgeInsets.all(32),
+ child: Center(child: LoadingIndicator()),
+ )
+ : Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(children: [
+ Icon(Icons.description_outlined,
+ color: Theme.of(context).colorScheme.primary),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Text('免责声明',
+ style: textTheme.titleLarge
+ ?.copyWith(fontWeight: FontWeight.w600)),
+ ),
+ ]),
+ const SizedBox(height: 20),
+ for (final paragraph in _statementsText!.trim().split('\n'))
+ Padding(
+ padding: const EdgeInsets.only(bottom: 12),
+ child: Text(paragraph.trim(),
+ style: textTheme.bodyMedium?.copyWith(height: 1.7)),
+ ),
+ ],
),
),
);
diff --git a/lib/pages/onboarding/steps/mirror_settings_step.dart b/lib/pages/onboarding/steps/mirror_settings_step.dart
index dd35e1a9..9c6c061c 100644
--- a/lib/pages/onboarding/steps/mirror_settings_step.dart
+++ b/lib/pages/onboarding/steps/mirror_settings_step.dart
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
-
-import 'package:kazumi/bean/widget/tonal_card.dart';
+import 'package:kazumi/bean/settings/network_mirror_settings.dart';
import 'package:kazumi/pages/onboarding/onboarding_step_layout.dart';
import 'package:kazumi/services/storage/storage.dart';
@@ -12,79 +11,43 @@ class MirrorSettingsStep extends StatefulWidget {
}
class _MirrorSettingsStepState extends State<MirrorSettingsStep> {
- late bool enableGitProxy;
- late bool enableBangumiProxy;
+ late bool _enableGitProxy;
+ late bool _enableBangumiProxy;
@override
void initState() {
super.initState();
- enableGitProxy = GStorage.getSetting(SettingsKeys.enableGitProxy);
- enableBangumiProxy = GStorage.getSetting(SettingsKeys.enableBangumiProxy);
+ _enableGitProxy = GStorage.getSetting(SettingsKeys.enableGitProxy);
+ _enableBangumiProxy = GStorage.getSetting(SettingsKeys.enableBangumiProxy);
}
@override
- Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- return OnboardingStepLayout(
- leading: const OnboardingStepIcon(icon: Icons.public_rounded),
- title: '网络镜像',
- subtitle: '中国大陆用户推荐启用,提升访问速度',
- child: Align(
- alignment: Alignment.topCenter,
- child: TonalCard(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- SwitchListTile(
- secondary: const Icon(Icons.travel_explore_rounded),
- title: const Text('Bangumi 镜像'),
- subtitle: const Text('加速热门与时间表加载'),
- value: enableBangumiProxy,
- onChanged: (value) async {
- enableBangumiProxy = value;
- await GStorage.putSetting(
- SettingsKeys.enableBangumiProxy, value);
- if (mounted) {
- setState(() {});
- }
- },
- ),
- SwitchListTile(
- secondary: const Icon(Icons.extension_rounded),
- title: const Text('规则仓库镜像'),
- subtitle: const Text('加速规则的下载与更新'),
- value: enableGitProxy,
- onChanged: (value) async {
- enableGitProxy = value;
- await GStorage.putSetting(SettingsKeys.enableGitProxy, value);
- if (mounted) {
- setState(() {});
- }
- },
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
- child: Row(
- children: [
- Icon(Icons.info_outline_rounded,
- size: 16, color: colorScheme.onSurfaceVariant),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- '可稍后在 设置 → 同步设置 中修改',
- style: Theme.of(context)
- .textTheme
- .bodySmall
- ?.copyWith(color: colorScheme.onSurfaceVariant),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
+ Widget build(BuildContext context) => OnboardingStepLayout(
+ leading: const OnboardingStepIcon(
+ icon: Icons.public_rounded,
+ shape: OnboardingIconShape.clover,
),
- ),
- );
- }
+ title: '让连接更顺畅',
+ subtitle: '中国大陆用户推荐启用镜像,加快番剧信息与规则的访问。',
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ NetworkMirrorSettings(
+ margin: EdgeInsets.zero,
+ enableBangumiProxy: _enableBangumiProxy,
+ enableGitProxy: _enableGitProxy,
+ onBangumiChanged: (value) async {
+ setState(() => _enableBangumiProxy = value);
+ await GStorage.putSetting(
+ SettingsKeys.enableBangumiProxy, value);
+ },
+ onGitChanged: (value) async {
+ setState(() => _enableGitProxy = value);
+ await GStorage.putSetting(SettingsKeys.enableGitProxy, value);
+ },
+ ),
+ const OnboardingHint(text: '可随时在 设置 → 同步设置 中调整这两项设置。'),
+ ],
+ ),
+ );
}
diff --git a/lib/pages/onboarding/steps/plugin_shop_step.dart b/lib/pages/onboarding/steps/plugin_shop_step.dart
index 8fc423fc..d11a8c89 100644
--- a/lib/pages/onboarding/steps/plugin_shop_step.dart
+++ b/lib/pages/onboarding/steps/plugin_shop_step.dart
@@ -12,10 +12,16 @@ class PluginShopStep extends StatelessWidget {
final PluginsController controller;
@override
- Widget build(BuildContext context) => OnboardingStepLayout(
- leading: const OnboardingStepIcon(icon: Icons.travel_explore_rounded),
- title: '添加规则',
- subtitle: '规则提供番剧搜索源,可稍后在 设置 → 规则管理 中调整',
- child: PluginCatalogView(controller: controller, onboarding: true),
+ Widget build(BuildContext context) => PluginCatalogView.onboarding(
+ controller: controller,
+ builder: (context, slivers) => OnboardingStepLayout.slivers(
+ leading: const OnboardingStepIcon(
+ icon: Icons.extension_rounded,
+ shape: OnboardingIconShape.flower,
+ ),
+ title: '发现更多番剧来源',
+ subtitle: '添加喜欢的规则,拓展搜索来源。也可以先开始使用,稍后在规则管理中添加。',
+ slivers: slivers,
+ ),
);
}
diff --git a/lib/pages/onboarding/steps/update_source_step.dart b/lib/pages/onboarding/steps/update_source_step.dart
index 080d3b38..0aac52aa 100644
--- a/lib/pages/onboarding/steps/update_source_step.dart
+++ b/lib/pages/onboarding/steps/update_source_step.dart
@@ -8,40 +8,46 @@ class UpdateSourceStep extends StatelessWidget {
required this.onChanged,
});
- /// true = Github 应用内检查更新,false = 交由 F-Droid 商店更新
final bool useGithubUpdate;
final ValueChanged<bool> onChanged;
@override
- Widget build(BuildContext context) {
- return OnboardingStepLayout(
- leading: const OnboardingStepIcon(icon: Icons.system_update_rounded),
- title: '更新来源',
- subtitle: '选择获取应用更新的方式',
- child: Align(
- alignment: Alignment.topCenter,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- _OptionCard(
- icon: Icons.rocket_launch_rounded,
- title: 'Github',
- description: '应用内检查更新,适合大多数用户',
- selected: useGithubUpdate,
- onTap: () => onChanged(true),
- ),
- _OptionCard(
- icon: Icons.storefront_rounded,
- title: 'F-Droid',
- description: '由 F-Droid 商店管理更新',
- selected: !useGithubUpdate,
- onTap: () => onChanged(false),
- ),
- ],
+ Widget build(BuildContext context) => OnboardingStepLayout(
+ leading: const OnboardingStepIcon(
+ icon: Icons.system_update_rounded,
+ shape: OnboardingIconShape.cookie,
),
- ),
- );
- }
+ title: '以你的方式更新',
+ subtitle: '选择适合你的更新来源,让 Kazumi 保持最新。',
+ child: RadioGroup<bool>(
+ groupValue: useGithubUpdate,
+ onChanged: (value) {
+ if (value != null) onChanged(value);
+ },
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ _OptionCard(
+ icon: Icons.rocket_launch_rounded,
+ title: 'GitHub',
+ description: '在应用内检查并获取新版本,适合大多数用户。',
+ value: true,
+ selected: useGithubUpdate,
+ recommended: true,
+ ),
+ const SizedBox(height: 12),
+ _OptionCard(
+ icon: Icons.storefront_rounded,
+ title: 'F-Droid',
+ description: '由 F-Droid 商店管理更新,应用内不再自动检查。',
+ value: false,
+ selected: !useGithubUpdate,
+ ),
+ const OnboardingHint(text: '之后也可以在 关于 → 自动检查更新 中修改。'),
+ ],
+ ),
+ ),
+ );
}
class _OptionCard extends StatelessWidget {
@@ -49,64 +55,76 @@ class _OptionCard extends StatelessWidget {
required this.icon,
required this.title,
required this.description,
+ required this.value,
required this.selected,
- required this.onTap,
+ this.recommended = false,
});
final IconData icon;
final String title;
final String description;
+ final bool value;
final bool selected;
- final VoidCallback onTap;
+ final bool recommended;
@override
Widget build(BuildContext context) {
- final colorScheme = Theme.of(context).colorScheme;
- final textTheme = Theme.of(context).textTheme;
- return Card(
- elevation: 0,
- margin: const EdgeInsets.only(bottom: 12),
- color: selected
- ? colorScheme.secondaryContainer
- : colorScheme.surfaceContainerLow,
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
+ final theme = Theme.of(context);
+ final colors = theme.colorScheme;
+ final foreground =
+ selected ? colors.onSecondaryContainer : colors.onSurface;
+ return AnimatedContainer(
+ duration: MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : const Duration(milliseconds: 250),
+ curve: Curves.easeInOutCubicEmphasized,
clipBehavior: Clip.antiAlias,
- child: InkWell(
- onTap: onTap,
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Row(
+ decoration: BoxDecoration(
+ color:
+ selected ? colors.secondaryContainer : colors.surfaceContainerLow,
+ borderRadius: BorderRadius.circular(selected ? 20 : 28),
+ border: Border.all(
+ color: selected ? colors.secondary : Colors.transparent,
+ width: 2,
+ ),
+ ),
+ child: Material(
+ type: MaterialType.transparency,
+ child: RadioListTile<bool>(
+ value: value,
+ controlAffinity: ListTileControlAffinity.trailing,
+ contentPadding:
+ const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
+ secondary: Icon(icon, size: 28, color: foreground),
+ title: Wrap(
+ spacing: 10,
+ runSpacing: 6,
+ crossAxisAlignment: WrapCrossAlignment.center,
children: [
- Icon(
- icon,
- color: selected
- ? colorScheme.onSecondaryContainer
- : colorScheme.onSurfaceVariant,
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(title, style: textTheme.titleMedium),
- const SizedBox(height: 2),
- Text(
- description,
- style: textTheme.bodyMedium
- ?.copyWith(color: colorScheme.onSurfaceVariant),
- ),
- ],
+ Text(title,
+ style: theme.textTheme.titleLarge?.copyWith(
+ color: foreground, fontWeight: FontWeight.w700)),
+ if (recommended)
+ Container(
+ padding:
+ const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
+ decoration: ShapeDecoration(
+ color: colors.tertiaryContainer,
+ shape: const StadiumBorder()),
+ child: Text('推荐',
+ style: theme.textTheme.labelMedium
+ ?.copyWith(color: colors.onTertiaryContainer)),
),
- ),
- const SizedBox(width: 16),
- Icon(
- selected
- ? Icons.check_circle_rounded
- : Icons.circle_outlined,
- color: selected ? colorScheme.primary : colorScheme.outline,
- ),
],
),
+ subtitle: Padding(
+ padding: const EdgeInsets.only(top: 8),
+ child: Text(description,
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: selected ? foreground : colors.onSurfaceVariant,
+ height: 1.5,
+ )),
+ ),
),
),
);
diff --git a/lib/pages/plugin_editor/plugin_catalog_view.dart b/lib/pages/plugin_editor/plugin_catalog_view.dart
index 5b1fdfac..2373c2f5 100644
--- a/lib/pages/plugin_editor/plugin_catalog_view.dart
+++ b/lib/pages/plugin_editor/plugin_catalog_view.dart
@@ -20,11 +20,20 @@ class PluginCatalogView extends StatefulWidget {
const PluginCatalogView({
super.key,
required this.controller,
- this.onboarding = false,
- });
+ }) : _scrollViewBuilder = null;
+
+ const PluginCatalogView.onboarding({
+ super.key,
+ required this.controller,
+ required Widget Function(BuildContext context, List<Widget> slivers)
+ builder,
+ }) : _scrollViewBuilder = builder;
final PluginsController controller;
- final bool onboarding;
+ final Widget Function(BuildContext context, List<Widget> slivers)?
+ _scrollViewBuilder;
+
+ bool get _onboarding => _scrollViewBuilder != null;
@override
State<PluginCatalogView> createState() => _PluginCatalogViewState();
@@ -154,7 +163,7 @@ class _PluginCatalogViewState extends State<PluginCatalogView> {
Widget _header(int total, int installed, int updates) {
final theme = Theme.of(context);
return Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
- if (!widget.onboarding) ...[
+ if (!widget._onboarding) ...[
const RulePageIntro(
title: '发现更多来源',
description: '浏览社区规则,为你的番剧搜索添加更多选择。',
@@ -193,8 +202,17 @@ class _PluginCatalogViewState extends State<PluginCatalogView> {
),
],
Row(children: [
- if (!widget.onboarding) _sortButton(),
- const Spacer(),
+ if (widget._onboarding)
+ Expanded(
+ child: Text('规则仓库 · 已安装 $installed',
+ style: theme.textTheme.titleSmall?.copyWith(
+ color: theme.colorScheme.primary,
+ fontWeight: FontWeight.w600)),
+ )
+ else ...[
+ _sortButton(),
+ const Spacer(),
+ ],
IconButton.filledTonal(
tooltip: '刷新规则列表',
onPressed: _loading ? null : _refresh,
@@ -256,57 +274,59 @@ class _PluginCatalogViewState extends State<PluginCatalogView> {
_controller.pluginStatus(p) == PluginCatalogItemStatus.update)
.length;
final items = _visibleItems();
- return CustomScrollView(
- keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
- slivers: [
- SliverPadding(
- padding: widget.onboarding
- ? EdgeInsets.zero
- : const EdgeInsets.fromLTRB(16, 12, 16, 24),
- sliver: SliverMainAxisGroup(slivers: [
- SliverToBoxAdapter(
- child: _header(catalog.length, installed, updates)),
- if (items.isEmpty)
- SliverToBoxAdapter(child: _emptyBody())
- else
- SliverList.builder(
- itemCount: items.length,
- itemBuilder: (context, index) {
- final item = items[index];
- final status = _controller.pluginStatus(item);
- final busy = _installing.contains(item.name);
- return RuleCard(
- key: ValueKey(item.name),
- title: item.name,
- installed: status == PluginCatalogItemStatus.installed,
- subtitle:
- item.author.isEmpty ? null : '作者 · ${item.author}',
- tags: [
+ final slivers = <Widget>[
+ SliverPadding(
+ padding: widget._onboarding
+ ? EdgeInsets.zero
+ : const EdgeInsets.fromLTRB(16, 12, 16, 24),
+ sliver: SliverMainAxisGroup(slivers: [
+ SliverToBoxAdapter(
+ child: _header(catalog.length, installed, updates)),
+ if (items.isEmpty)
+ SliverToBoxAdapter(child: _emptyBody())
+ else
+ SliverList.builder(
+ itemCount: items.length,
+ itemBuilder: (context, index) {
+ final item = items[index];
+ final status = _controller.pluginStatus(item);
+ final busy = _installing.contains(item.name);
+ return RuleCard(
+ key: ValueKey(item.name),
+ title: item.name,
+ installed: status == PluginCatalogItemStatus.installed,
+ subtitle:
+ item.author.isEmpty ? null : '作者 · ${item.author}',
+ tags: [
+ RuleTag(
+ label: item.version,
+ background: colors.surfaceContainerHighest,
+ foreground: colors.onSurfaceVariant),
+ if (item.antiCrawlerEnabled)
RuleTag(
- label: item.version,
- background: colors.surfaceContainerHighest,
- foreground: colors.onSurfaceVariant),
- if (item.antiCrawlerEnabled)
- RuleTag(
- label: '含验证支持',
- background: colors.tertiaryContainer,
- foreground: colors.onTertiaryContainer),
- ],
- caption: item.lastUpdate > 0
- ? '更新于 ${DateTime.fromMillisecondsSinceEpoch(item.lastUpdate).toString().split(' ').first}'
- : null,
- trailing: _CatalogRuleAction(
- status: status,
- busy: busy,
- onPressed: () => _install(item, status),
- ),
- );
- },
- ),
- ]),
- ),
- ],
- );
+ label: '含验证支持',
+ background: colors.tertiaryContainer,
+ foreground: colors.onTertiaryContainer),
+ ],
+ caption: item.lastUpdate > 0
+ ? '更新于 ${DateTime.fromMillisecondsSinceEpoch(item.lastUpdate).toString().split(' ').first}'
+ : null,
+ trailing: _CatalogRuleAction(
+ status: status,
+ busy: busy,
+ onPressed: () => _install(item, status),
+ ),
+ );
+ },
+ ),
+ ]),
+ ),
+ ];
+ return widget._scrollViewBuilder?.call(context, slivers) ??
+ CustomScrollView(
+ keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
+ slivers: slivers,
+ );
});
}
diff --git a/lib/pages/webdav_editor/webdav_setting.dart b/lib/pages/webdav_editor/webdav_setting.dart
index b13461e7..05a0f951 100644
--- a/lib/pages/webdav_editor/webdav_setting.dart
+++ b/lib/pages/webdav_editor/webdav_setting.dart
@@ -7,6 +7,7 @@ import 'package:kazumi/services/sync/webdav.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/settings/settings_detail_scaffold.dart';
import 'package:kazumi/bean/settings/settings_list.dart';
+import 'package:kazumi/bean/settings/network_mirror_settings.dart';
class WebDavSettingsPage extends StatefulWidget {
const WebDavSettingsPage({super.key});
@@ -79,40 +80,22 @@ class _PlayerSettingsPageState extends State<WebDavSettingsPage> {
title: const Text('同步设置'),
body: SettingsList(
sections: [
- SettingsSection(
- title: Text('规则仓库'),
- tiles: [
- SettingsTile.switchTile(
- leading: Icons.hub_rounded,
- onToggle: (value) async {
- enableGitProxy = value ?? !enableGitProxy;
- await GStorage.putSetting(
- SettingsKeys.enableGitProxy, enableGitProxy);
- setState(() {});
- },
- title: Text('规则仓库镜像'),
- description: Text('使用镜像访问规则更新和管理仓库'),
- initialValue: enableGitProxy,
- ),
- ],
+ NetworkMirrorSettings(
+ enableBangumiProxy: enableBangumiProxy,
+ enableGitProxy: enableGitProxy,
+ onBangumiChanged: (value) async {
+ setState(() => enableBangumiProxy = value);
+ await GStorage.putSetting(
+ SettingsKeys.enableBangumiProxy, value);
+ },
+ onGitChanged: (value) async {
+ setState(() => enableGitProxy = value);
+ await GStorage.putSetting(SettingsKeys.enableGitProxy, value);
+ },
),
SettingsSection(
title: Text('Bangumi'),
tiles: [
- SettingsTile.switchTile(
- leading: Icons.cloud_rounded,
- onToggle: (value) async {
- enableBangumiProxy = value ?? !enableBangumiProxy;
- await GStorage.putSetting(
- SettingsKeys.enableBangumiProxy, enableBangumiProxy);
- if (mounted) {
- setState(() {});
- }
- },
- title: Text('Bangumi 镜像'),
- description: Text('使用缓存后端加载榜单'),
- initialValue: enableBangumiProxy,
- ),
SettingsTile.switchTile(
leading: Icons.sync_rounded,
onToggle: (value) async {