照片预览添加删除按钮

master
张萌 3 years ago
parent 04b44e65f0
commit ac6c97ee8c

@ -1,7 +1,8 @@
import 'package:ansu_ui/painters/as_numeric_painter.dart';
import 'package:ansu_ui/styles/as_colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ansu_ui/styles/as_colors.dart';
///##
class ASNumericButton extends StatefulWidget {
@ -131,6 +132,7 @@ class _ASNumericButtonState extends State<ASNumericButton> {
alignment: Alignment.center,
child: IntrinsicWidth(
child: TextField(
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
keyboardType: TextInputType.number,
controller: _controller,
onChanged: (text) {

@ -1,4 +1,5 @@
import 'package:ansu_ui/extension/num_extension.dart';
import 'package:ansu_ui/list_tile/as_list_tile.dart';
import 'package:flutter/material.dart';
extension SeparateExt on List<Widget> {
@ -12,7 +13,10 @@ extension SeparateExt on List<Widget> {
}
if (element.runtimeType == Visibility) {
return (element as Visibility).visible;
return !(element as Visibility).visible;
}
if (element.runtimeType == ASListTile) {
return !(element as ASListTile).visible;
}
return false;
});

@ -31,27 +31,30 @@ class ASOptionTile extends StatelessWidget {
int get length => items!.length;
List<Widget> get _widgets => leading == null
? (items ?? [])
: <Widget>[
Container(
alignment: Alignment.centerLeft,
child: this.leading is String
? Padding(
padding:
EdgeInsets.symmetric(vertical: 14.w, horizontal: 10.w),
child: Text(
this.leading,
style: TextStyle(
color: kTextColor,
fontSize: 16.sp,
fontWeight: FontWeight.bold),
),
)
: this.leading,
),
...(items ?? []),
];
List<Widget> get _widgets {
var list = <Widget>[];
if (leading == null) {
return list = items ?? [];
} else {
list.add(Container(
alignment: Alignment.centerLeft,
child: leading is String
? Padding(
padding: EdgeInsets.symmetric(vertical: 14.w, horizontal: 10.w),
child: Text(
this.leading,
style: TextStyle(
color: kTextColor,
fontSize: 16.sp,
fontWeight: FontWeight.bold),
),
)
: leading,
));
list.addAll((items ?? []));
return list;
}
}
@override
Widget build(BuildContext context) {
@ -66,7 +69,7 @@ class ASOptionTile extends StatelessWidget {
child: item ??
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: items!.sepWidget(
children: _widgets.sepWidget(
separate: this.padding == null
? ASDivider(
indent: 10.w,

@ -1,6 +1,7 @@
import 'dart:io';
import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -8,19 +9,30 @@ class AsGridImageView extends StatelessWidget {
final List<File>? files;
final List<String>? nets;
final String? placeholder;
final void Function(dynamic value)? onDelete;
final double? iconSize;
const AsGridImageView.fromFile(
{Key? key, required this.files, this.placeholder})
{Key? key,
required this.files,
this.placeholder,
this.onDelete,
this.iconSize})
: nets = null,
super(key: key);
const AsGridImageView.fromNets(
{Key? key, required this.nets, this.placeholder})
{Key? key,
required this.nets,
this.placeholder,
this.onDelete,
this.iconSize})
: files = null,
super(key: key);
@override
Widget build(BuildContext context) {
var size = iconSize ?? 16.w;
return GridView(
padding: EdgeInsets.all(10.w),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
@ -37,19 +49,52 @@ class AsGridImageView extends StatelessWidget {
tag: e,
net: e,
),
child: Hero(
tag: e,
child: FadeInImage.assetNetwork(
placeholder: placeholder ?? '', image: e),
child: Stack(
children: [
Hero(
tag: e,
child: FadeInImage.assetNetwork(
placeholder: placeholder ?? '', image: e),
),
Positioned(
top: size / 2,
right: size / 2,
child: GestureDetector(
onTap: () {
if (onDelete == null) {
onDelete!(e);
}
},
child: Icon(
CupertinoIcons.xmark_circle_fill,
color: Colors.black45,
),
))
],
),
))
.toList()
: files!
.map((e) => GestureDetector(
onTap: () =>
PhotoViewer.fromFile(context, tag: e.path, file: e),
child: Hero(tag: e.path, child: Image.file(e)),
))
.map((e) => Stack(children: [
Positioned(
top: 0,
right: 0,
child: GestureDetector(
onTap: () {
if (onDelete != null) {
onDelete!(e);
}
},
child: Icon(
CupertinoIcons.xmark_circle_fill,
color: Colors.black45,
),
)),
GestureDetector(
onTap: () => PhotoViewer.fromFile(context,
tag: e.path, file: e),
child: Hero(tag: e.path, child: Image.file(e)))
]))
.toList());
}
}

Loading…
Cancel
Save