From ac6c97ee8cbb25f696e048f440c15e9c4322d1e3 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Mon, 25 Oct 2021 09:56:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=85=A7=E7=89=87=E9=A2=84=E8=A7=88=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/buttons/as_numeric_button.dart | 4 +- lib/extension/list_extension.dart | 6 ++- lib/list_tile/as_option_tile.dart | 47 +++++++++++---------- lib/utils/as_grid_image_view.dart | 67 +++++++++++++++++++++++++----- 4 files changed, 89 insertions(+), 35 deletions(-) diff --git a/lib/buttons/as_numeric_button.dart b/lib/buttons/as_numeric_button.dart index a581314..e133ba3 100644 --- a/lib/buttons/as_numeric_button.dart +++ b/lib/buttons/as_numeric_button.dart @@ -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 { alignment: Alignment.center, child: IntrinsicWidth( child: TextField( + inputFormatters: [FilteringTextInputFormatter.digitsOnly], keyboardType: TextInputType.number, controller: _controller, onChanged: (text) { diff --git a/lib/extension/list_extension.dart b/lib/extension/list_extension.dart index 172bb6a..65e929c 100644 --- a/lib/extension/list_extension.dart +++ b/lib/extension/list_extension.dart @@ -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 { @@ -12,7 +13,10 @@ extension SeparateExt on List { } 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; }); diff --git a/lib/list_tile/as_option_tile.dart b/lib/list_tile/as_option_tile.dart index 13f98b6..9a4ea74 100644 --- a/lib/list_tile/as_option_tile.dart +++ b/lib/list_tile/as_option_tile.dart @@ -31,27 +31,30 @@ class ASOptionTile extends StatelessWidget { int get length => items!.length; - List get _widgets => leading == null - ? (items ?? []) - : [ - 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 get _widgets { + var list = []; + 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, diff --git a/lib/utils/as_grid_image_view.dart b/lib/utils/as_grid_image_view.dart index 24e7245..4adba26 100644 --- a/lib/utils/as_grid_image_view.dart +++ b/lib/utils/as_grid_image_view.dart @@ -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? files; final List? 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()); } }