Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
payment_method_section.dart
Go to the documentation of this file.
1import 'package:easy_localization/easy_localization.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:flutter_screenutil/flutter_screenutil.dart';
5import 'package:shimmer/shimmer.dart';
6
7import '../../../../../../core/ui/theme/color_palette.dart';
8import '../../../../domain/entities/res/res_partner_payment_entity.dart';
9import '../../../bloc/collections_information_bloc/collections_information_bloc.dart';
10
11class PaymentMethodSection extends StatelessWidget {
12 final int restaurantId;
14 final ValueChanged<String?> onChanged;
15
17 super.key,
18 required this.restaurantId,
19 required this.selectedPaymentMethod,
20 required this.onChanged,
21 });
22
23 @override
24 Widget build(BuildContext context) {
25 return Column(
26 crossAxisAlignment: CrossAxisAlignment.start,
27 children: [
28 Text(
29 'full_fill_collection.payment_methods'.tr(),
30 style: Theme.of(context).textTheme.titleSmall?.copyWith(
32 ),
33 ),
34 SizedBox(height: 8.sp),
35 BlocBuilder<CollectionsInformationBloc, CollectionsInformationState>(
36 buildWhen: (previous, current) =>
38 current is CollectionPaymentModeListLoading ||
39 current is CollectionPaymentModeListError,
40 builder: (context, state) {
41 if (state is CollectionPaymentModeListInitial) {
42 context.read<CollectionsInformationBloc>().add(
45 );
46 return _buildShimmer();
47 }
48
49 if (state is CollectionPaymentModeListLoading) {
50 return _buildShimmer();
51 }
52
53 if (state is CollectionPaymentModeListError) {
54 // return _buildErrorContainer(state.failure.message);
55 return _buildDropdown([]);
56 }
57
59 return _buildDropdown(state.paymentModes);
60 }
61
62 return const SizedBox.shrink();
63 },
64 ),
65 ],
66 );
67 }
68
69 Widget _buildShimmer() {
70 return Shimmer.fromColors(
71 baseColor: Colors.grey[300]!,
72 highlightColor: Colors.grey[100]!,
73 child: Container(
74 height: 48.sp,
75 decoration: BoxDecoration(
76 borderRadius: BorderRadius.circular(20.sp),
77 color: Colors.white,
78 ),
79 ),
80 );
81 }
82
83 // Widget _buildErrorContainer(String message) {
84 // return Container(
85 // padding: EdgeInsets.all(16.sp),
86 // decoration: BoxDecoration(
87 // borderRadius: BorderRadius.circular(20.sp),
88 // border: Border.all(color: Colors.red.withValues(alpha: 0.5)),
89 // ),
90 // child: Row(
91 // children: [
92 // Icon(Icons.error_outline, color: Colors.red, size: 20.sp),
93 // SizedBox(width: 8.sp),
94 // Expanded(
95 // child: Text(
96 // message,
97 // style: TextStyle(
98 // color: Colors.red,
99 // fontSize: 14.sp,
100 // ),
101 // ),
102 // ),
103 // ],
104 // ),
105 // );
106 // }
107
108 Widget _buildDropdown(List<ResPartnerPaymentEntity> paymentModes) {
109 // Check if the list is empty
110 if (paymentModes.isEmpty) {
111 return Container(
112 padding: EdgeInsets.symmetric(horizontal: 16.sp),
113 height: 48.sp,
114 decoration: BoxDecoration(
115 borderRadius: BorderRadius.circular(20.sp),
116 border: Border.all(color: ColorPalette.grey.withValues(alpha: 0.2)),
117 color: Colors.white,
118 ),
119 child: Center(
120 child: Text('full_fill_collection.deffered_payment'.tr()),
121 ),
122 );
123 }
124
125 // Verify if selectedPaymentMethod exists in the items
126 final bool valueExists = selectedPaymentMethod == null
127 ? true
128 : paymentModes.any((payment) =>
129 payment.paymentModeId.id.toString() == selectedPaymentMethod);
130
131 // If selected value doesn't exist, use null
132 final String? validValue = valueExists ? selectedPaymentMethod : null;
133
134 return Container(
135 decoration: BoxDecoration(
136 borderRadius: BorderRadius.circular(20.sp),
137 border: Border.all(color: ColorPalette.grey.withValues(alpha: 0.2)),
138 color: Colors.white,
139 ),
140 child: DropdownButtonHideUnderline(
141 child: DropdownButton<String>(
142 isExpanded: true,
143 value: validValue,
144 hint: Text('full_fill_collection.select_payment_method'.tr()),
145 icon: const Icon(Icons.keyboard_arrow_down, color: ColorPalette.grey),
146 padding: EdgeInsets.symmetric(horizontal: 16.sp),
147 borderRadius: BorderRadius.circular(8.sp),
148 items: paymentModes.map((payment) {
149 return DropdownMenuItem<String>(
150 value: payment.paymentModeId.id
151 .toString(), // Use ID instead of name as value
152 child: Text(
153 payment.paymentModeId.name, // Still display the name
154 style: TextStyle(fontSize: 14.sp),
155 ),
156 );
157 }).toList(),
159 ),
160 ),
161 );
162 }
163}
static const grey
final List< DashboardItem > items
final CollectionsState state
const PaymentMethodSection({ super.key, required this.restaurantId, required this.selectedPaymentMethod, required this.onChanged, })
final Widget child
final ValueChanged< int?> onChanged
override Widget build(BuildContext context)
Widget _buildDropdown(List< ResPartnerPaymentEntity > paymentModes)
final EdgeInsets padding
const GetCollectionPaymentModeListEvent({ required this.restaurentId, })
class GetCollectionContactListEvent extends CollectionsInformationEvent restaurentId
class CollectionLowRatingReasonsError extends CollectionsInformationState paymentModes
const CollectionPaymentModeListLoaded({required this.paymentModes})
class Partner String
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)