123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import 'package:cpt_services/components/status_card_item.dart';
- import 'package:cs_resources/theme/app_colors_theme.dart';
- import 'package:domain/entity/paid_service_detail_entity.dart';
- import 'package:flutter/material.dart';
- import 'package:auto_route/auto_route.dart';
- import 'package:flutter_hooks/flutter_hooks.dart';
- import 'package:hooks_riverpod/hooks_riverpod.dart';
- import 'package:shared/utils/color_utils.dart';
- import 'package:shared/utils/log_utils.dart';
- import 'package:widgets/my_button.dart';
- import 'package:widgets/my_text_view.dart';
- import 'package:widgets/widget_export.dart';
- import 'package:widgets/my_cart_num.dart';
- import 'chooseHouseCleanContent_state.dart';
- import 'chooseHouseCleanContent_vm.dart';
- class ChooseHouseCleanContent extends HookConsumerWidget {
- final int id;
- final String cleanServiceType;
- final String? useScence;
- final List<PaidServiceDetailProducts> products;
- const ChooseHouseCleanContent({Key? key,required this.id, required this.cleanServiceType, required this.products, this.useScence}) : super(key: key);
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final vm = ref.read(chooseHouseCleanContentVmProvider.notifier);
- List<HouseCleanContentItem>? houseCleanList = ref.watch(chooseHouseCleanContentVmProvider.select((state) => state.houseCleanList));
- useEffect((){
- vm.setInitPageData(context, {
- 'id': id,
- 'cleanServiceType': cleanServiceType,
- 'products': products,
- 'useScence': useScence,
- });
- // 组件挂载时执行 - 执行接口请求
- // Future.microtask(() => vm.initPageData());
- return () {
- // 组件卸载时执行
- };
- },[]);
- return Container(
- padding: EdgeInsets.only(left: 0, right: 0, top: 10, bottom: 10),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: houseCleanList != null && houseCleanList.isNotEmpty? List.generate(houseCleanList!.length, (index){
- HouseCleanContentItem currentItem = houseCleanList![index];
- // 如何用ref 去watch state中的 houseCleanList中的第index 变化
- return _buildItem(context, currentItem, index, vm);
- }): [],
- ),
- );
- }
- Widget _buildItem(BuildContext context, HouseCleanContentItem HouseCleanItem, int index, ChooseHouseCleanContentVm vm){
- final title = HouseCleanItem.name??'';
- final areaSizeRange = HouseCleanItem.areaSizeRange??'';
- final num = HouseCleanItem.num?? 1;
- final price = HouseCleanItem.price?? 0;
- bool isChecked = HouseCleanItem.isChecked??false;
- bool disabled = HouseCleanItem.isDisable??false;
- if(useScence !=null){
- disabled = true;
- }else {
- disabled = false;
- }
- final isCheckedState = useState<bool>(isChecked);
- final isDisable = useState<bool>(disabled);
- return Container(
- padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
- margin: EdgeInsets.only(left: 15, right: 15, top: 0, bottom: 0),
- color: ColorUtils.string2Color('#F8F8F8'),
- child: Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- mainAxisSize: MainAxisSize.max,
- children: [
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- MyTextView(
- title,
- fontSize: 16,
- isFontMedium: true,
- textColor: context.appColors.textBlack,
- ),
- MyTextView(
- areaSizeRange,
- fontSize: 15,
- isFontRegular: true,
- textColor: context.appColors.textDarkGray999,
- marginTop: 5,
- ),
- ],
- ),
- ),
- // MyCartNum(onChange: (value){
- // vm.handlerChangeNum(context, value, index);
- // })
- // MyButton(
- // text: '\$$price',
- // onPressed: (){
- // // vm.handlerChangeNum(context, value, index);
- // },
- // fontSize: 19,
- // fontWeight: FontWeight.w500,
- // )
- Container(
- child: MyButton(
- text: '\$$price',
- onPressed: (){
- if(!isDisable.value){
- isCheckedState.value = !isCheckedState.value;
- vm.handlerChangeItemChecked(context, isCheckedState.value, index);
- }
- },
- minWidth: 80,
- minHeight: 40,
- fontSize: 19,
- fontWeight: FontWeight.w500,
- // enable: !isDisable.value,
- textColor: isCheckedState.value? context.appColors.textWhite: context.appColors.textPrimary,
- backgroundColor: isCheckedState.value ? context.appColors.textPrimary:context.appColors.textWhite,
- disabledBackgroundColor: context.appColors.disEnableGray,
- disabledTextColor: context.appColors.textWhite,
- ),
- ),
- ],
- ),
- // Divider(),
- ],
- ),
- );
- }
- }
|