照片预览

master
张萌 3 years ago
parent 4048004ba6
commit 5af832deb8

@ -40,7 +40,7 @@ class _ExamplePickerState extends State<ExamplePicker> {
trailing: ASButton(
title: '日期选择器',
onPressed: () async {
DateTime? date = await asDatePicker(context);
DateTime? date = await showAsDatePicker(context);
Get.snackbar(date.toString(), 'MESSAGE');
},
),

@ -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<File>? files;
final List<String>? 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());
}
}

@ -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<CameraView> {
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(

@ -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<PhotoViewer> {
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<PhotoViewer> {
);
}
}
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);
},
),
);
}

Loading…
Cancel
Save