You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansu_ui/lib/utils/as_grid_image_view.dart

99 lines
2.9 KiB

3 years ago
import 'dart:io';
import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/cupertino.dart';
3 years ago
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;
final void Function(dynamic value)? onDelete;
final double? iconSize;
3 years ago
const AsGridImageView.fromFile({Key? key,
required this.files,
this.placeholder,
this.onDelete,
this.iconSize})
3 years ago
: nets = null,
super(key: key);
const AsGridImageView.fromNets({Key? key,
required this.nets,
this.placeholder,
this.onDelete,
this.iconSize})
3 years ago
: files = null,
super(key: key);
@override
Widget build(BuildContext context) {
var size = iconSize ?? 16.w;
3 years ago
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) =>
GestureDetector(
onTap: () =>
PhotoViewer.fromNet(
context,
tag: e,
net: e,
),
child: Stack(
children: [
Hero(
tag: e,
child: FadeInImage.assetNetwork(
placeholder: placeholder ?? '', image: e),
),
if(onDelete != null) Positioned(
top: size / 2,
right: size / 2,
child: GestureDetector(
onTap: () {
onDelete!(e);
},
child: Icon(
CupertinoIcons.xmark_circle_fill,
color: Colors.black45,
),
))
],
),
))
.toList()
: files!
.map((e) =>
Stack(children: [
if(onDelete != null) Positioned(
top: 0,
right: 0,
child: GestureDetector(
onTap: () {
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());
3 years ago
}
}