diff --git a/lib/const/resource.dart b/lib/const/resource.dart index ae65be93..aeb32a6d 100644 --- a/lib/const/resource.dart +++ b/lib/const/resource.dart @@ -1,8 +1,7 @@ /// Generate by [resource_generator](https://github.com/CaiJingLong/flutter_resource_generator) library. /// PLEASE DO NOT EDIT MANUALLY. class R { - /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/.DS_Store) - static const String ASSETS__DS_STORE = 'assets/.DS_Store'; + const R._(); /// ![preview](file:///Users/akufe/Documents/akuCommunity/assets/example/QR_code.png) static const String ASSETS_EXAMPLE_QR_CODE_PNG = 'assets/example/QR_code.png'; diff --git a/lib/widget/horizontal_image_view.dart b/lib/widget/horizontal_image_view.dart index 020249db..66a51641 100644 --- a/lib/widget/horizontal_image_view.dart +++ b/lib/widget/horizontal_image_view.dart @@ -1,9 +1,11 @@ import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/widget/picker/bee_image_preview.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:akuCommunity/const/resource.dart'; +import 'package:get/get.dart'; class HorizontalImageView extends StatefulWidget { final List urls; @@ -21,17 +23,30 @@ class _HorizontalImageViewState extends State { Widget build(BuildContext context) { if (widget.urls.isEmpty) return 15.hb; return Container( - height: 184.w + 24.w, - child: ListView.builder( + height: 184.w + 32.w, + child: ListView.separated( + padding: EdgeInsets.all(16.w), + separatorBuilder: (_, __) => 16.wb, scrollDirection: Axis.horizontal, itemBuilder: (context, index) { - return Padding( - padding: EdgeInsets.all(16.w), - child: ClipRRect( - borderRadius: BorderRadius.circular(8.w), - child: FadeInImage.assetNetwork( - placeholder: R.ASSETS_ICONS_PROPOSAL_PNG, - image: API.image(widget.urls[index]), + return ClipRRect( + borderRadius: BorderRadius.circular(8.w), + child: GestureDetector( + onTap: () { + Get.to( + BeeImagePreview.path(path: widget.urls[index]), + opaque: false, + ); + }, + child: Hero( + tag: widget.urls[index], + child: FadeInImage.assetNetwork( + height: 184.w, + width: 184.w, + placeholder: R.ASSETS_IMAGES_LOGO_PNG, + image: API.image(widget.urls[index]), + fit: BoxFit.cover, + ), ), ), ); diff --git a/lib/widget/picker/bee_image_preview.dart b/lib/widget/picker/bee_image_preview.dart index bb6781c9..4534954c 100644 --- a/lib/widget/picker/bee_image_preview.dart +++ b/lib/widget/picker/bee_image_preview.dart @@ -1,17 +1,42 @@ import 'dart:io'; +import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/constants/api.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; class BeeImagePreview extends StatefulWidget { final File file; - BeeImagePreview({Key key, @required this.file}) : super(key: key); + final String path; + BeeImagePreview.file({Key key, @required this.file}) + : path = null, + super(key: key); + + BeeImagePreview.path({Key key, @required this.path}) + : file = null, + super(key: key); @override _BeeImagePreviewState createState() => _BeeImagePreviewState(); } class _BeeImagePreviewState extends State { + Widget get image { + if (widget.file == null) + return Hero( + tag: widget.path, + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_IMAGES_LOGO_PNG, + image: API.image(widget.path), + ), + ); + else + return Hero( + tag: widget.file.hashCode, + child: Image.file(widget.file), + ); + } + @override Widget build(BuildContext context) { return GestureDetector( @@ -21,10 +46,7 @@ class _BeeImagePreviewState extends State { body: Center( child: InteractiveViewer( minScale: 0.2, - child: Hero( - tag: widget.file.hashCode, - child: Image.file(widget.file), - ), + child: image, ), ), ), diff --git a/lib/widget/picker/grid_image_picker.dart b/lib/widget/picker/grid_image_picker.dart index a0b29eef..9bcbc420 100644 --- a/lib/widget/picker/grid_image_picker.dart +++ b/lib/widget/picker/grid_image_picker.dart @@ -77,7 +77,7 @@ class _GridImagePickerState extends State { ), child: MaterialButton( onPressed: () { - Get.to(BeeImagePreview(file: file),opaque: false); + Get.to(BeeImagePreview.file(file: file), opaque: false); }, onLongPress: () async { bool result = await Get.dialog(CupertinoAlertDialog(