opt: image view

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2024-12-15 11:44:44 +08:00
parent fee1ad56f7
commit 52f888167f
11 changed files with 120 additions and 57 deletions

View File

@@ -79,6 +79,8 @@ class InteractiveViewer extends StatefulWidget {
this.onPanStart,
this.onPanUpdate,
this.onPanEnd,
this.onReset,
this.isAnimating,
required Widget this.child,
}) : assert(minScale > 0),
assert(interactionEndFrictionCoefficient > 0),
@@ -127,6 +129,8 @@ class InteractiveViewer extends StatefulWidget {
this.onPanStart,
this.onPanUpdate,
this.onPanEnd,
this.onReset,
this.isAnimating,
required InteractiveViewerWidgetBuilder this.builder,
}) : assert(minScale > 0),
assert(interactionEndFrictionCoefficient > 0),
@@ -147,6 +151,8 @@ class InteractiveViewer extends StatefulWidget {
constrained = false,
child = null;
final Function? isAnimating;
final VoidCallback? onReset;
final ValueChanged<ScaleStartDetails>? onPanStart;
final ValueChanged<ScaleUpdateDetails>? onPanUpdate;
final ValueChanged<ScaleEndDetails>? onPanEnd;
@@ -755,8 +761,9 @@ class _InteractiveViewerState extends State<InteractiveViewer>
// Handle the start of a gesture. All of pan, scale, and rotate are handled
// with GestureDetector's scale gesture.
void _onScaleStart(ScaleStartDetails details) {
if (details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0) {
if (widget.isAnimating?.call() == true ||
(details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0)) {
widget.onPanStart?.call(details);
return;
}
@@ -788,8 +795,9 @@ class _InteractiveViewerState extends State<InteractiveViewer>
// Handle an update to an ongoing gesture. All of pan, scale, and rotate are
// handled with GestureDetector's scale gesture.
void _onScaleUpdate(ScaleUpdateDetails details) {
if (details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0) {
if (widget.isAnimating?.call() == true ||
(details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0)) {
widget.onPanUpdate?.call(details);
return;
}
@@ -892,8 +900,12 @@ class _InteractiveViewerState extends State<InteractiveViewer>
// Handle the end of a gesture of _GestureType. All of pan, scale, and rotate
// are handled with GestureDetector's scale gesture.
void _onScaleEnd(ScaleEndDetails details) {
if (details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0) {
if (_transformationController?.value.row0.x == 1.0) {
widget.onReset?.call();
}
if (widget.isAnimating?.call() == true ||
(details.pointerCount < 2 &&
_transformationController?.value.row0.x == 1.0)) {
widget.onPanEnd?.call(details);
return;
}

View File

@@ -25,9 +25,11 @@ class InteractiveViewerBoundary extends StatefulWidget {
required this.maxScale,
required this.minScale,
this.onDismissed,
this.onReset,
this.dismissThreshold = 0.2,
});
final VoidCallback? onReset;
final double dismissThreshold;
final VoidCallback? onDismissed;
@@ -230,6 +232,8 @@ class InteractiveViewerBoundaryState extends State<InteractiveViewerBoundary>
onPanStart: _handleDragStart,
onPanUpdate: _handleDragUpdate,
onPanEnd: _handleDragEnd,
onReset: widget.onReset,
isAnimating: () => _animateController.value != 0,
child: content,
);
}

View File

@@ -6,7 +6,6 @@ import 'package:PiliPalaX/utils/utils.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:path_provider/path_provider.dart';
@@ -224,6 +223,13 @@ class _InteractiveviewerGalleryState extends State<InteractiveviewerGallery>
Get.back();
widget.onDismissed?.call(_pageController!.page!.floor());
},
onReset: () {
if (!_enablePageView) {
setState(() {
_enablePageView = true;
});
}
},
child: PageView.builder(
onPageChanged: _onPageChanged,
controller: _pageController,