Skip to content

Commit

Permalink
New loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Oct 30, 2024
1 parent a492305 commit 45d3027
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 117 deletions.
67 changes: 22 additions & 45 deletions lib/pages/image_view/view/eh_flutter_list_view_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,28 @@ import 'package:flutter_list_view/flutter_list_view.dart';

class EhFlutterListViewDelegate extends FlutterListViewDelegate {
EhFlutterListViewDelegate(
NullableIndexedWidgetBuilder builder, {
int? childCount,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
bool addSemanticIndexes = true,
SemanticIndexCallback semanticIndexCallback =
_kDefaultSemanticIndexCallback,
int semanticIndexOffset = 0,
FlutterListViewDelegateOnItemKey? onItemKey,
bool keepPosition = false,
double keepPositionOffset = 0.0,
FlutterListViewDelegateOnItemSticky? onItemSticky,
bool stickyAtTailer = false,
FlutterListViewDelegateOnItemHeight? onItemHeight,
double preferItemHeight = 50.0,
FirstItemAlign firstItemAlign = FirstItemAlign.start,
int initIndex = 0,
int? forceToExecuteInitIndex,
double initOffset = 0.0,
bool initOffsetBasedOnBottom = false,
bool Function(String keyOrIndex)? onIsPermanent,
bool isSupressElementGenerate = false,
}) : super(
builder,
childCount: childCount,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
addSemanticIndexes: addSemanticIndexes,
semanticIndexCallback: semanticIndexCallback,
semanticIndexOffset: semanticIndexOffset,
onItemKey: onItemKey,
keepPosition: keepPosition,
keepPositionOffset: keepPositionOffset,
onItemSticky: onItemSticky,
stickyAtTailer: stickyAtTailer,
onItemHeight: onItemHeight,
preferItemHeight: preferItemHeight,
firstItemAlign: firstItemAlign,
initIndex: initIndex,
forceToExecuteInitIndex: forceToExecuteInitIndex,
initOffset: initOffset,
initOffsetBasedOnBottom: initOffsetBasedOnBottom,
onIsPermanent: onIsPermanent,
isSupressElementGenerate: isSupressElementGenerate,
);
super.builder, {
super.childCount,
super.addAutomaticKeepAlives,
super.addRepaintBoundaries,
super.addSemanticIndexes,
super.semanticIndexCallback = _kDefaultSemanticIndexCallback,
super.semanticIndexOffset,
super.onItemKey,
super.keepPosition,
super.keepPositionOffset,
super.onItemSticky,
super.stickyAtTailer,
super.onItemHeight,
super.preferItemHeight,
super.firstItemAlign,
super.initIndex,
super.forceToExecuteInitIndex,
super.initOffset,
super.initOffsetBasedOnBottom,
super.onIsPermanent,
super.isSupressElementGenerate,
});
}

int _kDefaultSemanticIndexCallback(Widget _, int localIndex) => localIndex;
3 changes: 2 additions & 1 deletion lib/pages/image_view/view/hero.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
/// make hero better when slide out
class HeroWidget extends StatefulWidget {
const HeroWidget({
super.key,
required this.child,
required this.tag,
required this.slidePagekey,
Expand All @@ -15,7 +16,7 @@ class HeroWidget extends StatefulWidget {
final Object tag;
final GlobalKey<ExtendedImageSlidePageState> slidePagekey;
@override
_HeroWidgetState createState() => _HeroWidgetState();
State<HeroWidget> createState() => _HeroWidgetState();
}

class _HeroWidgetState extends State<HeroWidget> {
Expand Down
18 changes: 9 additions & 9 deletions lib/pages/image_view/view/image_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '../controller/view_controller.dart';
import 'view_image.dart';

class ImageListView extends StatefulWidget {
const ImageListView({Key? key}) : super(key: key);
const ImageListView({super.key});

@override
State<ImageListView> createState() => _ImageListViewState();
Expand Down Expand Up @@ -145,7 +145,7 @@ class _ImageListViewState extends State<ImageListView> {
final vState = logic.vState;

// 计算容器高度
double? _height = () {
double? height = () {
// 从已下载进入阅读的情况 imageMap 会未初始化
try {
if (vState.imageMap?[itemSer]?.hide ?? false) {
Expand All @@ -166,19 +166,19 @@ class _ImageListViewState extends State<ImageListView> {
(context.width / _curImage.imageWidth!);
} on Exception catch (_) {
// 根据缩略图进行计算
final _curImage = vState.imageMap?[itemSer];
return _curImage!.thumbHeight! *
(context.width / _curImage.thumbWidth!);
final curImage = vState.imageMap?[itemSer];
return curImage!.thumbHeight! *
(context.width / curImage.thumbWidth!);
} catch (e) {
return null;
}
}();

if (_height != null) {
_height += vState.showPageInterval ? 8 : 0;
if (height != null) {
height += vState.showPageInterval ? 8 : 0;
}

loggerSimple.v('builder itemBuilder $itemSer $_height');
loggerSimple.t('builder itemBuilder $itemSer $height');

final viewImage = ViewImage(
imageSer: itemSer,
Expand Down Expand Up @@ -246,7 +246,7 @@ class _ImageListViewState extends State<ImageListView> {
return AnimatedContainer(
padding:
EdgeInsets.only(bottom: vState.showPageInterval ? 8 : 0),
height: _height ?? context.mediaQueryShortestSide,
height: height ?? context.mediaQueryShortestSide,
duration: const Duration(milliseconds: 200),
curve: Curves.ease,
// child: !kDebugMode ? viewImage : viewImage2,
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/image_view/view/image_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '../controller/view_controller.dart';
import 'view_image.dart';

class ImagePageView extends GetView<ViewExtController> {
const ImagePageView({Key? key, this.reverse = false}) : super(key: key);
const ImagePageView({super.key, this.reverse = false});
final bool reverse;

@override
Expand All @@ -38,7 +38,6 @@ class ImagePageView extends GetView<ViewExtController> {

// 上下滑动图片 返回
return ExtendedImageSlidePage(
child: imageView,
slideAxis: SlideAxis.vertical,
slideType: SlideType.wholePage,
resetPageDuration: const Duration(milliseconds: 300),
Expand All @@ -55,6 +54,7 @@ class ImagePageView extends GetView<ViewExtController> {
controller.update([idViewBar]);
}
},
child: imageView,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/pages/image_view/view/image_page_view_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

class ImagePhotoView extends GetView<ViewExtController> {
const ImagePhotoView({Key? key, this.reverse = false}) : super(key: key);
const ImagePhotoView({super.key, this.reverse = false});
final bool reverse;

ViewExtState get vState => controller.vState;
Expand Down
35 changes: 18 additions & 17 deletions lib/pages/image_view/view/view_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ typedef DoubleClickAnimationListener = void Function();

class ViewImage extends StatefulWidget {
const ViewImage({
Key? key,
super.key,
required this.imageSer,
this.initialScale = 1.0,
this.enableDoubleTap = true,
this.mode = ExtendedImageMode.gesture,
this.enableSlideOutPage = true,
this.imageSizeChanged,
}) : super(key: key);
});

final int imageSer;
final double initialScale;
Expand All @@ -41,7 +41,7 @@ class ViewImage extends StatefulWidget {
final ValueChanged<Size>? imageSizeChanged;

@override
_ViewImageState createState() => _ViewImageState();
State<ViewImage> createState() => _ViewImageState();
}

class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
Expand Down Expand Up @@ -127,7 +127,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
/// 双击事件
DoubleTap get _onDoubleTap => (ExtendedImageGestureState state) {
///you can use define pointerDownPosition as you can,
///default value is double tap pointer down postion.
///default value is double tap pointer down position.
final Offset? pointerDownPosition = state.pointerDownPosition;
final double begin = state.gestureDetails?.totalScale ?? 0.0;
double end;
Expand Down Expand Up @@ -170,7 +170,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {

@override
Widget build(BuildContext context) {
Widget _image = () {
Widget image = () {
switch (vState.loadFrom) {
case LoadFrom.download:
// 从已下载查看
Expand All @@ -190,8 +190,8 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {

return Obx(() {
return HeroMode(
child: _image,
enabled: widget.imageSer == controller.vState.currentItemIndex + 1,
child: image,
);
});
}
Expand All @@ -200,7 +200,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
Widget fileImage(String path) {
final Size size = MediaQuery.of(context).size;

final loadStateChanged = (ExtendedImageState state) {
Widget? loadStateChanged(ExtendedImageState state) {
final ImageInfo? imageInfo = state.extendedImageInfo;
widget.imageSizeChanged?.call(Size(
imageInfo?.image.width.toDouble() ?? 0.0,
Expand Down Expand Up @@ -246,7 +246,8 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
debugLable: '### Widget fileImage 加载图片文件',
);
}
};
return null;
}

return path.isContentUri
? ExtendedImage(
Expand Down Expand Up @@ -506,7 +507,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
// 常规情况 加载网络图片

// 图片加载完成
_onLoadCompleted(ExtendedImageState state) {
void onLoadCompleted(ExtendedImageState state) {
final ImageInfo? imageInfo = state.extendedImageInfo;
controller.setScale100(imageInfo!, context.mediaQuerySize);

Expand Down Expand Up @@ -545,7 +546,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
controller.reloadImage(widget.imageSer, changeSource: true),
fadeAnimationController: _fadeAnimationController,
initGestureConfigHandler: _initGestureConfigHandler,
onLoadCompleted: _onLoadCompleted,
onLoadCompleted: onLoadCompleted,
);
}

Expand Down Expand Up @@ -575,7 +576,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
controller.reloadImage(widget.imageSer, changeSource: true),
fadeAnimationController: _fadeAnimationController,
initGestureConfigHandler: _initGestureConfigHandler,
onLoadCompleted: _onLoadCompleted,
onLoadCompleted: onLoadCompleted,
);

return image;
Expand All @@ -592,27 +593,27 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
}

Widget _buildErr(Object? e) {
String _errInfo = '';
String errInfo = '';
logger.e('${e.runtimeType}');
if (e is DioException) {
final DioException dioErr = e;
logger.e('${dioErr.error}');
_errInfo = dioErr.type.toString();
errInfo = dioErr.type.toString();
} else if (e is EhError) {
final EhError ehErr = e;
logger.e('$ehErr');
_errInfo = ehErr.type.toString();
errInfo = ehErr.type.toString();
if (ehErr.type == EhErrorType.image509) {
return ViewErr509(ser: widget.imageSer);
}
} else if (e is HttpException) {
if (e is BadRequestException && e.code == 429) {
return ViewErr429(ser: widget.imageSer);
} else {
_errInfo = e.message;
errInfo = e.message;
}
} else {
_errInfo = e.toString();
errInfo = e.toString();
}

if ((vState.errCountMap[widget.imageSer] ?? 0) < vState.retryCount) {
Expand All @@ -626,7 +627,7 @@ class _ViewImageState extends State<ViewImage> with TickerProviderStateMixin {
'${widget.imageSer} 重试 第 ${vState.errCountMap[widget.imageSer]} 次');
}
if ((vState.errCountMap[widget.imageSer] ?? 0) >= vState.retryCount) {
return ViewError(ser: widget.imageSer, errInfo: _errInfo);
return ViewError(ser: widget.imageSer, errInfo: errInfo);
} else {
return ViewLoading(
debugLable: '重试',
Expand Down
Loading

0 comments on commit 45d3027

Please sign in to comment.