You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
5.5 KiB
Dart
122 lines
5.5 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:car_provider_app/view_models/items_view_model.dart';
|
|
import 'package:car_provider_app/views/branch_management/schedule/widgets/chips_picker_item.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
import 'package:mc_common_app/models/services_models/item_model.dart';
|
|
import 'package:mc_common_app/theme/colors.dart';
|
|
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
import 'package:mc_common_app/widgets/empty_widget.dart';
|
|
import 'package:mc_common_app/widgets/extensions/extensions_widget.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
class SelectItemsSheet extends StatelessWidget {
|
|
final int serviceId;
|
|
final Function(List<ItemData>) onSelectItems;
|
|
final List<PickerItem>? list;
|
|
|
|
const SelectItemsSheet({super.key, required this.serviceId, required this.onSelectItems, this.list});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
context.read<ItemsVM>().getServiceItems(serviceId, list: list);
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
height: MediaQuery.of(context).size.height / 1.4,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: Consumer<ItemsVM>(
|
|
builder: (_, itemsVM, child) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(left: 20, right: 20, top: 6),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: LocaleKeys.selectItems.tr().toText(fontSize: 24, isBold: true),
|
|
),
|
|
Center(
|
|
child: (itemsVM.serviceItems == null ? "0" : itemsVM.serviceItems!.data!.where((element) => element.isUpdateOrSelected == true).toList().length.toString()).toText(
|
|
fontSize: 10,
|
|
isBold: true,
|
|
color: Colors.white,
|
|
),
|
|
).toContainer(
|
|
borderRadius: 100,
|
|
width: 24,
|
|
height: 24,
|
|
paddingAll: 0,
|
|
backgroundColor: MyColors.darkPrimaryColor,
|
|
),
|
|
],
|
|
),
|
|
// 12.height,
|
|
// TxtField(
|
|
// hint: LocaleKeys.searchItems.tr(),
|
|
// onChanged: (v) {},
|
|
// ),
|
|
12.height,
|
|
Expanded(
|
|
child: itemsVM.serviceItems?.data == null
|
|
? const Center(child: CircularProgressIndicator())
|
|
: itemsVM.serviceItems?.data!.length == 0
|
|
? Center(child: EmptyWidget(text: LocaleKeys.noItemsToShow.tr()))
|
|
: ListView.separated(
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return CheckboxListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
title: itemsVM.serviceItems!.data![index].name!.toText(fontSize: 16),
|
|
subtitle: itemsVM.serviceItems!.data![index].price.toString().toText(fontSize: 14, color: MyColors.lightTextColor),
|
|
value: itemsVM.serviceItems!.data![index].isUpdateOrSelected,
|
|
onChanged: (bool? v) {
|
|
itemsVM.serviceItems!.data![index].isUpdateOrSelected = v;
|
|
|
|
log("itemsVM.serviceItems!.data![index].isUpdateOrSelected: ${itemsVM.serviceItems!.data![index].isUpdateOrSelected}");
|
|
itemsVM.notifyListeners();
|
|
},
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return const Divider(height: 1);
|
|
},
|
|
itemCount: itemsVM.serviceItems?.data?.length ?? 0,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
ShowFillButton(
|
|
title: LocaleKeys.addSelectedItems.tr(),
|
|
maxWidth: double.infinity,
|
|
margin: const EdgeInsets.all(20),
|
|
onPressed: () {
|
|
final itemsVM = context.read<ItemsVM>();
|
|
if (itemsVM.serviceItems != null) {
|
|
List<ItemData> list = [];
|
|
for (var element in itemsVM.serviceItems!.data!) {
|
|
if (element.isUpdateOrSelected ?? false) {
|
|
list.add(element);
|
|
}
|
|
}
|
|
onSelectItems(list);
|
|
}
|
|
|
|
Navigator.pop(context);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|