mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
@@ -3,7 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io' show File;
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/gesture/image_horizontal_drag_gesture_recognizer.dart';
|
||||
import 'package:PiliPlus/common/widgets/gesture/image_tap_gesture_recognizer.dart';
|
||||
import 'package:PiliPlus/common/widgets/image_viewer/viewer.dart';
|
||||
@@ -37,7 +39,6 @@ class Image extends StatefulWidget {
|
||||
required this.minScale,
|
||||
required this.maxScale,
|
||||
required this.containerSize,
|
||||
required this.isAnimating,
|
||||
required this.onDragStart,
|
||||
required this.onDragUpdate,
|
||||
required this.onDragEnd,
|
||||
@@ -76,7 +77,6 @@ class Image extends StatefulWidget {
|
||||
required this.minScale,
|
||||
required this.maxScale,
|
||||
required this.containerSize,
|
||||
required this.isAnimating,
|
||||
required this.onDragStart,
|
||||
required this.onDragUpdate,
|
||||
required this.onDragEnd,
|
||||
@@ -122,7 +122,6 @@ class Image extends StatefulWidget {
|
||||
required this.minScale,
|
||||
required this.maxScale,
|
||||
required this.containerSize,
|
||||
required this.isAnimating,
|
||||
required this.onDragStart,
|
||||
required this.onDragUpdate,
|
||||
required this.onDragEnd,
|
||||
@@ -171,7 +170,6 @@ class Image extends StatefulWidget {
|
||||
required this.minScale,
|
||||
required this.maxScale,
|
||||
required this.containerSize,
|
||||
required this.isAnimating,
|
||||
required this.onDragStart,
|
||||
required this.onDragUpdate,
|
||||
required this.onDragEnd,
|
||||
@@ -220,7 +218,6 @@ class Image extends StatefulWidget {
|
||||
required this.minScale,
|
||||
required this.maxScale,
|
||||
required this.containerSize,
|
||||
required this.isAnimating,
|
||||
required this.onDragStart,
|
||||
required this.onDragUpdate,
|
||||
required this.onDragEnd,
|
||||
@@ -278,7 +275,6 @@ class Image extends StatefulWidget {
|
||||
final double maxScale;
|
||||
final Size containerSize;
|
||||
|
||||
final ValueGetter<bool> isAnimating;
|
||||
final ValueChanged<ScaleStartDetails>? onDragStart;
|
||||
final ValueChanged<ScaleUpdateDetails>? onDragUpdate;
|
||||
final ValueChanged<ScaleEndDetails>? onDragEnd;
|
||||
@@ -566,27 +562,27 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
|
||||
_isListeningToStream = false;
|
||||
}
|
||||
|
||||
Widget _debugBuildErrorWidget(BuildContext context, Object error) {
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: <Widget>[
|
||||
const Positioned.fill(child: Placeholder(color: Color(0xCF8D021F))),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: FittedBox(
|
||||
child: Text(
|
||||
'$error',
|
||||
textAlign: TextAlign.center,
|
||||
textDirection: TextDirection.ltr,
|
||||
style: const TextStyle(
|
||||
shadows: <Shadow>[Shadow(blurRadius: 1.0)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
// Widget _debugBuildErrorWidget(BuildContext context, Object error) {
|
||||
// return Stack(
|
||||
// alignment: Alignment.center,
|
||||
// children: <Widget>[
|
||||
// const Positioned.fill(child: Placeholder(color: Color(0xCF8D021F))),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.all(4.0),
|
||||
// child: FittedBox(
|
||||
// child: Text(
|
||||
// '$error',
|
||||
// textAlign: TextAlign.center,
|
||||
// textDirection: TextDirection.ltr,
|
||||
// style: const TextStyle(
|
||||
// shadows: <Shadow>[Shadow(blurRadius: 1.0)],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -594,25 +590,31 @@ class _ImageState extends State<Image> with WidgetsBindingObserver {
|
||||
if (widget.errorBuilder != null) {
|
||||
return widget.errorBuilder!(context, _lastException!, _lastStack);
|
||||
}
|
||||
if (kDebugMode) {
|
||||
return _debugBuildErrorWidget(context, _lastException!);
|
||||
}
|
||||
// if (kDebugMode) {
|
||||
// return _debugBuildErrorWidget(context, _lastException!);
|
||||
// }
|
||||
}
|
||||
|
||||
Widget result;
|
||||
if (_imageInfo != null) {
|
||||
// final isLongPic =
|
||||
// _imageInfo!.image.height / _imageInfo!.image.width >
|
||||
// StyleString.imgMaxRatio;
|
||||
double? minScale, maxScale;
|
||||
final imgWidth = _imageInfo!.image.width.toDouble();
|
||||
final imgHeight = _imageInfo!.image.height.toDouble();
|
||||
final imgRatio = imgHeight / imgWidth;
|
||||
final isLongPic =
|
||||
imgRatio > StyleString.imgMaxRatio &&
|
||||
imgHeight > widget.containerSize.height;
|
||||
if (isLongPic) {
|
||||
minScale =
|
||||
widget.containerSize.width / widget.containerSize.height * imgRatio;
|
||||
maxScale = math.max(widget.maxScale, minScale * 3);
|
||||
}
|
||||
result = Viewer(
|
||||
minScale: widget.minScale,
|
||||
maxScale: widget.maxScale,
|
||||
minScale: minScale ?? widget.minScale,
|
||||
maxScale: maxScale ?? widget.maxScale,
|
||||
isLongPic: isLongPic,
|
||||
containerSize: widget.containerSize,
|
||||
childSize: Size(
|
||||
_imageInfo!.image.width.toDouble(),
|
||||
_imageInfo!.image.height.toDouble(),
|
||||
),
|
||||
isAnimating: widget.isAnimating,
|
||||
childSize: Size(imgWidth, imgHeight),
|
||||
onDragStart: widget.onDragStart,
|
||||
onDragUpdate: widget.onDragUpdate,
|
||||
onDragEnd: widget.onDragEnd,
|
||||
|
||||
Reference in New Issue
Block a user