Skip to content

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

refactor(image-preview): use modular

Prediditaba9790a9e68
diff --git a/lib/bean/widget/image_preview.dart b/lib/bean/widget/image_preview.dart
index 634745fd..272c7a24 100644
--- a/lib/bean/widget/image_preview.dart
+++ b/lib/bean/widget/image_preview.dart
@@ -1,36 +1,33 @@
import 'package:cached_network_image_ce/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
+import 'package:flutter_modular/flutter_modular.dart';
import 'package:photo_view/photo_view.dart';
+class ImageViewerRouteArgs {
+ const ImageViewerRouteArgs({required this.imageUrl, this.heroTag});
+
+ final String imageUrl;
+ final String? heroTag;
+}
+
class ImageViewer extends StatefulWidget {
+ static const String routePath = '/image-preview';
+
final String imageUrl;
final String? heroTag;
const ImageViewer({super.key, required this.imageUrl, this.heroTag});
/// 显示图片预览
- static void show(BuildContext context,
- {required String imageUrl, String? heroTag}) {
- Navigator.of(context).push(
- PageRouteBuilder(
- opaque: false,
- barrierColor: Colors.black.withValues(alpha: 0.8),
- pageBuilder: (context, animation, secondaryAnimation) {
- return ImageViewer(imageUrl: imageUrl, heroTag: heroTag);
- },
- transitionDuration: const Duration(milliseconds: 300),
- transitionsBuilder: (context, animation, secondaryAnimation, child) {
- return FadeTransition(
- opacity: animation,
- child: ScaleTransition(
- scale: Tween<double>(begin: 0.8, end: 1.0).animate(
- CurvedAnimation(parent: animation, curve: Curves.easeOutCubic),
- ),
- child: child,
- ),
- );
- },
+ static Future<void> show(BuildContext context,
+ {required String imageUrl, String? heroTag}) async {
+ final effectiveHeroTag = heroTag ?? imageUrl;
+ await Modular.to.pushNamed(
+ routePath,
+ arguments: ImageViewerRouteArgs(
+ imageUrl: imageUrl,
+ heroTag: effectiveHeroTag,
),
);
}
@@ -74,7 +71,8 @@ class _ImageViewerState extends State<ImageViewer> {
final currentScale = _photoViewController.scale ?? _initialScale ?? 1.0;
_initialScale ??= currentScale;
- final factor = event.scrollDelta.dy < 0 ? _wheelScaleStep : 1 / _wheelScaleStep;
+ final factor =
+ event.scrollDelta.dy < 0 ? _wheelScaleStep : 1 / _wheelScaleStep;
final minScale = _initialScale! * _minScaleFactor;
final maxScale = _initialScale! * _maxScaleFactor;
final newScale = (currentScale * factor).clamp(minScale, maxScale);
@@ -85,25 +83,27 @@ class _ImageViewerState extends State<ImageViewer> {
_scaleStateController.scaleState = PhotoViewScaleState.zoomedIn;
}
+ void _closePreview() {
+ Modular.to.pop();
+ }
+
@override
Widget build(BuildContext context) {
return Scaffold(
- backgroundColor: Colors.transparent,
+ backgroundColor: Colors.black,
body: Stack(
children: [
Listener(
onPointerSignal: _handlePointerSignal,
child: GestureDetector(
- onTap: () => Navigator.of(context).pop(),
+ onTap: _closePreview,
child: PhotoView(
imageProvider: CachedNetworkImageProvider(widget.imageUrl),
controller: _photoViewController,
scaleStateController: _scaleStateController,
minScale: PhotoViewComputedScale.contained,
maxScale: PhotoViewComputedScale.covered * 3,
- backgroundDecoration: const BoxDecoration(
- color: Colors.transparent,
- ),
+ backgroundDecoration: const BoxDecoration(color: Colors.black),
heroAttributes: widget.heroTag != null
? PhotoViewHeroAttributes(tag: widget.heroTag!)
: null,
@@ -123,8 +123,7 @@ class _ImageViewerState extends State<ImageViewer> {
Text(
'图片加载失败',
style: TextStyle(
- color:
- Theme.of(context).colorScheme.onErrorContainer,
+ color: Theme.of(context).colorScheme.onErrorContainer,
),
),
],
@@ -143,7 +142,7 @@ class _ImageViewerState extends State<ImageViewer> {
shape: BoxShape.circle,
),
child: IconButton(
- onPressed: () => Navigator.of(context).pop(),
+ onPressed: _closePreview,
icon: const Icon(Icons.close, color: Colors.white),
),
),
diff --git a/lib/pages/index_module.dart b/lib/pages/index_module.dart
index e139b69a..f8794005 100644
--- a/lib/pages/index_module.dart
+++ b/lib/pages/index_module.dart
@@ -22,6 +22,7 @@ import 'package:kazumi/repositories/history_repository.dart';
import 'package:kazumi/repositories/download_repository.dart';
import 'package:kazumi/utils/download_manager.dart';
import 'package:kazumi/pages/download/download_controller.dart';
+import 'package:kazumi/bean/widget/image_preview.dart';
class IndexModule extends Module {
@override
@@ -73,6 +74,18 @@ class IndexModule extends Module {
duration: Duration(milliseconds: 70),
);
r.module("/video", module: VideoModule());
+ r.child(
+ ImageViewer.routePath,
+ child: (_) {
+ final args = Modular.args.data as ImageViewerRouteArgs;
+ return ImageViewer(
+ imageUrl: args.imageUrl,
+ heroTag: args.heroTag,
+ );
+ },
+ transition: TransitionType.fadeIn,
+ duration: Duration(milliseconds: 220),
+ );
/// The route need [ BangumiItem ] as argument.
r.module("/info", module: InfoModule());
diff --git a/pubspec.lock b/pubspec.lock
index 77900c43..7be7860c 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1096,6 +1096,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.2"
+ photo_view:
+ dependency: "direct main"
+ description:
+ name: photo_view
+ sha256: "1fc3d970a91295fbd1364296575f854c9863f225505c28c46e0a03e48960c75e"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.15.0"
platform:
dependency: transitive
description: