diff --git a/example/lib/widgets/example_picker.dart b/example/lib/widgets/example_picker.dart index 8702021..db98431 100644 --- a/example/lib/widgets/example_picker.dart +++ b/example/lib/widgets/example_picker.dart @@ -40,7 +40,7 @@ class _ExamplePickerState extends State { trailing: ASButton( title: '日期选择器', onPressed: () async { - DateTime? date = await asDatePicker(context); + DateTime? date = await showAsDatePicker(context); Get.snackbar(date.toString(), 'MESSAGE'); }, ), diff --git a/lib/utils/as_grid_image_view.dart b/lib/utils/as_grid_image_view.dart new file mode 100644 index 0000000..011f667 --- /dev/null +++ b/lib/utils/as_grid_image_view.dart @@ -0,0 +1,38 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class AsGridImageView extends StatelessWidget { + final List? files; + final List? nets; + final String? placeholder; + + const AsGridImageView.fromFile( + {Key? key, required this.files, this.placeholder}) + : nets = null, + super(key: key); + + const AsGridImageView.fromNets( + {Key? key, required this.nets, this.placeholder}) + : files = null, + super(key: key); + + @override + Widget build(BuildContext context) { + return GridView( + padding: EdgeInsets.all(10.w), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 3, + mainAxisSpacing: 10.w, + crossAxisSpacing: 10.w, + ), + shrinkWrap: true, + children: files == null + ? nets! + .map((e) => FadeInImage.assetNetwork( + placeholder: placeholder ?? '', image: e)) + .toList() + : files!.map((e) => Image.file(e)).toList()); + } +} diff --git a/lib/utils/camera_view.dart b/lib/utils/camera_view.dart index ac91937..b649efb 100644 --- a/lib/utils/camera_view.dart +++ b/lib/utils/camera_view.dart @@ -1,20 +1,20 @@ import 'dart:io'; import 'dart:ui'; -import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:ansu_ui/divider/as_divider.dart'; +import 'package:ansu_ui/extension/list_extension.dart'; import 'package:ansu_ui/scaffold/as_scaffold.dart'; -import 'package:ansu_ui/utils/photo_viewer.dart'; +import 'package:ansu_ui/styles/as_colors.dart'; import 'package:ansu_ui/utils/camera_util.dart'; -import 'package:ansu_ui/extension/list_extension.dart'; -import 'package:ansu_ui/divider/as_divider.dart'; - +import 'package:ansu_ui/utils/photo_viewer.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:velocity_x/velocity_x.dart'; class CameraView extends StatefulWidget { final File? file; final String? title; + CameraView({Key? key, this.file, this.title}) : super(key: key); @override @@ -41,7 +41,8 @@ class _CameraViewState extends State { alignment: Alignment.center, child: GestureDetector( onTap: () { - toPhotoViewer(context, tag: widget.title, file: widget.file); + PhotoViewer.fromFile(context, + tag: widget.title ?? '', file: widget.file!); }, child: Hero( child: Image.file( diff --git a/lib/utils/photo_viewer.dart b/lib/utils/photo_viewer.dart index 498e705..e56b405 100644 --- a/lib/utils/photo_viewer.dart +++ b/lib/utils/photo_viewer.dart @@ -1,12 +1,55 @@ import 'dart:io'; -import 'package:flutter/material.dart'; import 'package:ansu_ui/extension/num_extension.dart'; +import 'package:flutter/material.dart'; class PhotoViewer extends StatefulWidget { final File? file; - final String? tag; - PhotoViewer({Key? key, this.file, this.tag}) : super(key: key); + final String? net; + final String tag; + + static fromFile(BuildContext context, + {required String tag, required File file}) { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation, secondAnimation) { + return PhotoViewer.toFile(file: file, tag: tag); + }, + opaque: false, + transitionsBuilder: (context, animation, secondaryAnimation, child) { + return FadeTransition(opacity: animation, child: child); + }, + ), + ); + } + + static fromNet(BuildContext context, + {required String tag, required String net}) { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation, secondAnimation) { + return PhotoViewer.toNet(net: net, tag: tag); + }, + opaque: false, + transitionsBuilder: (context, animation, secondaryAnimation, child) { + return FadeTransition(opacity: animation, child: child); + }, + ), + ); + } + + PhotoViewer.toFile({ + Key? key, + this.file, + required this.tag, + }) : net = null, + super(key: key); + + PhotoViewer.toNet({Key? key, required this.tag, this.net}) + : file = null, + super(key: key); @override _PhotoViewerState createState() => _PhotoViewerState(); @@ -23,8 +66,10 @@ class _PhotoViewerState extends State { child: InteractiveViewer( boundaryMargin: 100.edge, child: Hero( - tag: widget.tag!, - child: Image.file(widget.file!), + tag: widget.tag, + child: widget.file != null + ? Image.file(widget.file!) + : Image.network(widget.net!), ), ), ), @@ -32,18 +77,3 @@ class _PhotoViewerState extends State { ); } } - -toPhotoViewer(BuildContext context, {String? tag, File? file}) { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation, secondAnimation) { - return PhotoViewer(file: file, tag: tag); - }, - opaque: false, - transitionsBuilder: (context, animation, secondaryAnimation, child) { - return FadeTransition(opacity: animation, child: child); - }, - ), - ); -}