fixed device type counts

This commit is contained in:
hannathkadher
2024-11-20 20:41:12 +04:00
parent 60710c383f
commit 6fd845a9fc
2 changed files with 165 additions and 62 deletions

View File

@ -10,8 +10,10 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
class AddDeviceWidget extends StatefulWidget {
final List<ProductModel>? products;
final ValueChanged<Map<String, int>>? onProductsSelected;
final Map<String, int>? initialSelectedProducts;
const AddDeviceWidget({super.key, this.products, this.onProductsSelected});
const AddDeviceWidget(
{super.key, this.products, this.initialSelectedProducts, this.onProductsSelected});
@override
_AddDeviceWidgetState createState() => _AddDeviceWidgetState();
@ -25,11 +27,9 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
void initState() {
super.initState();
_scrollController = ScrollController();
if (widget.products != null) {
for (var product in widget.products!) {
productCounts[product.uuid] = 0;
}
print(widget.initialSelectedProducts);
if (widget.initialSelectedProducts != null && widget.initialSelectedProducts!.isNotEmpty) {
productCounts = widget.initialSelectedProducts!;
}
}
@ -161,7 +161,7 @@ class _AddDeviceWidgetState extends State<AddDeviceWidget> {
const SizedBox(height: 8),
// The custom counter widget aligned at the bottom
CounterWidget(
initialCount: 0,
initialCount: productCounts[deviceType!.uuid] ?? 0,
onCountChanged: (newCount) {
setState(() {
if (newCount > 0) {