add photo viewer

null_safety
小赖 4 years ago
parent c6eadb8a0e
commit c1af00fcad

@ -69,7 +69,7 @@ class _ExamplePickerState extends State<ExamplePicker> {
trailing: ASButton( trailing: ASButton(
title: '图片选择器', title: '图片选择器',
onPressed: () async { onPressed: () async {
File file = await camView(context); File file = await camView(context, title: '图片选择器');
}, },
), ),
), ),

@ -1,6 +1,7 @@
library ansu_ui; library ansu_ui;
import 'dart:io'; import 'dart:io';
import 'dart:ui';
import 'package:ansu_ui/bar/as_tab_indicator.dart'; import 'package:ansu_ui/bar/as_tab_indicator.dart';
import 'package:ansu_ui/painters/as_numeric_painter.dart'; import 'package:ansu_ui/painters/as_numeric_painter.dart';
@ -11,7 +12,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
export 'package:flutter_screenutil/flutter_screenutil.dart'; export 'package:flutter_screenutil/flutter_screenutil.dart';
export 'package:flutter_easyrefresh/easy_refresh.dart'; export 'package:flutter_easyrefresh/easy_refresh.dart';
export 'package:bot_toast/bot_toast.dart'; export 'package:bot_toast/bot_toast.dart';
@ -64,7 +64,9 @@ part 'divider/as_divider.dart';
part 'text_field/as_search_text_field.dart'; part 'text_field/as_search_text_field.dart';
part 'utils/screen_adapter.dart'; part 'utils/screen_adapter.dart';
part 'utils/camera_util.dart';part 'utils/camera_view.dart'; part 'utils/camera_util.dart';
part 'utils/camera_view.dart';
part 'utils/photo_viewer.dart';
part 'extension/num_extension.dart'; part 'extension/num_extension.dart';
part 'extension/list_extension.dart'; part 'extension/list_extension.dart';

@ -23,7 +23,24 @@ class _CameraViewState extends State<CameraView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ASScaffold( return ASScaffold(
title: widget.title, title: widget.title,
body: Image.file(widget.file, fit: BoxFit.cover), body: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
alignment: Alignment.center,
child: GestureDetector(
onTap: () {
toPhotoViewer(context, tag: widget.title, file: widget.file);
},
child: Hero(
child: Image.file(
widget.file,
fit: BoxFit.cover,
),
tag: widget.title,
),
),
),
),
bottomNavigationBar: Material( bottomNavigationBar: Material(
color: kForegroundColor, color: kForegroundColor,
child: Column( child: Column(
@ -35,7 +52,9 @@ class _CameraViewState extends State<CameraView> {
title: '重拍', title: '重拍',
onPressed: () async { onPressed: () async {
File file = await camFile(); File file = await camFile();
if (file == null) Navigator.pop(context); if (file == null)
Navigator.pop(context);
else
Navigator.pushReplacement(context, PageRouteBuilder( Navigator.pushReplacement(context, PageRouteBuilder(
pageBuilder: (context, animation, secondAnimation) { pageBuilder: (context, animation, secondAnimation) {
return FadeTransition( return FadeTransition(

@ -0,0 +1,46 @@
part of ansu_ui;
class PhotoViewer extends StatefulWidget {
final File file;
final String tag;
PhotoViewer({Key key, this.file, this.tag}) : super(key: key);
@override
_PhotoViewerState createState() => _PhotoViewerState();
}
class _PhotoViewerState extends State<PhotoViewer> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black54,
body: GestureDetector(
onTap: () => Navigator.pop(context),
child: Center(
child: InteractiveViewer(
boundaryMargin: 100.edge,
child: Hero(
tag: widget.tag,
child: Image.file(widget.file),
),
),
),
),
);
}
}
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