delete packages

This commit is contained in:
quantulr
2024-06-18 17:26:27 +08:00
parent 1238802598
commit 2570b09033

View File

@ -309,6 +309,22 @@ class _LogisticsState extends State<Logistics> {
_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<String, dynamic> package;
final int index;
final Function(String) onLogisticsChanged;
final int totalPackagesCount;
@override
State<PackageCard> createState() => _PackageCardState();
@ -424,6 +444,24 @@ class _PackageCardState extends State<PackageCard> {
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,
)
],
),
),