From 2570b09033936fa8408bf4f907dbba34a96594cc Mon Sep 17 00:00:00 2001 From: quantulr <35954003+quantulr@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:26:27 +0800 Subject: [PATCH] delete packages --- lib/logistics.dart | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/logistics.dart b/lib/logistics.dart index 1e05572..4804353 100644 --- a/lib/logistics.dart +++ b/lib/logistics.dart @@ -309,6 +309,22 @@ class _LogisticsState extends State { _activePackage = index; }); }, + onClose: () { + var curId = + _packages[index]["id"]; + setState(() { + _activePackage = + _activePackage >= index + ? _activePackage - 1 + : _activePackage; + _packages = _packages + .where((el) => + el["id"] != curId) + .toList(); + }); + }, + totalPackagesCount: + _packages.length, isActive: _activePackage == index, package: _packages[index], index: index); @@ -357,13 +373,17 @@ class PackageCard extends StatefulWidget { required this.package, required this.index, required this.onLogisticsChanged, + required this.totalPackagesCount, + required this.onClose, }); final bool isActive; final Function() onTap; + final Function() onClose; final Map package; final int index; final Function(String) onLogisticsChanged; + final int totalPackagesCount; @override State createState() => _PackageCardState(); @@ -424,6 +444,24 @@ class _PackageCardState extends State { top: 2, child: Text("包裹${widget.index + 1}"), ), + widget.totalPackagesCount > 1 + ? Positioned( + top: 2, + right: 2, + child: SizedBox( + width: 20, + height: 20, + child: IconButton( + color: Colors.redAccent, + iconSize: 20, + padding: EdgeInsets.zero, + icon: const Icon(Icons.close), + onPressed: widget.onClose, + ), + )) + : const SizedBox( + width: 0, + ) ], ), ),