Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
contact_selector.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';
6import '../../../../../../core/ui/theme/color_palette.dart';
7import '../../../../domain/entities/res/res_collection_contact_entity.dart';
8import '../../../bloc/collections_information_bloc/collections_information_bloc.dart';
9
10class ContactSelector extends StatelessWidget {
12 final ValueChanged<int?> onChanged;
13
15 super.key,
16 this.selectedContactId,
17 required this.onChanged,
18 });
19
20 @override
21 Widget build(BuildContext context) {
22 return BlocBuilder<CollectionsInformationBloc, CollectionsInformationState>(
23 buildWhen: (previous, current) =>
24 current is CollectionContactListLoading ||
25 current is CollectionContactListLoaded ||
27 builder: (context, state) {
28 if (state is CollectionContactListLoading) {
29 return _buildShimmer();
30 }
31
33 // return Text(
34 // 'Error loading contacts',
35 // style: TextStyle(color: Colors.red, fontSize: 14.sp),
36 // );
37 return const SizedBox.shrink();
38 }
39
41 if (state.contacts.isEmpty) {
42 return const SizedBox.shrink();
43 }
44
45 return _buildSelector(state.contacts);
46 }
47
48 return const SizedBox.shrink();
49 },
50 );
51 }
52
53 Widget _buildShimmer() {
54 return Column(
55 crossAxisAlignment: CrossAxisAlignment.start,
56 children: [
57 Shimmer.fromColors(
58 baseColor: Colors.grey[300]!,
59 highlightColor: Colors.grey[100]!,
60 child: Container(
61 width: 60.sp,
62 height: 16.sp,
63 decoration: BoxDecoration(
64 color: Colors.white,
65 borderRadius: BorderRadius.circular(4.sp),
66 ),
67 ),
68 ),
69 SizedBox(height: 8.sp),
70 Shimmer.fromColors(
71 baseColor: Colors.grey[300]!,
72 highlightColor: Colors.grey[100]!,
73 child: Container(
74 height: 48.sp,
75 decoration: BoxDecoration(
76 color: Colors.white,
77 borderRadius: BorderRadius.circular(20.sp),
78 ),
79 ),
80 ),
81 ],
82 );
83 }
84
85 Widget _buildSelector(List<ResCollectionContactEntity> contacts) {
86 final validContacts = contacts.where((contact) =>
87 contact.reference != null && contact.reference!.isNotEmpty
88 ).toList();
89
90 return Column(
91 crossAxisAlignment: CrossAxisAlignment.start,
92 children: [
93 Text(
94 'full_fill_collection.contact'.tr(),
95 style: TextStyle(
96 fontSize: 14.sp,
98 ),
99 ),
100 SizedBox(height: 8.sp),
101 Container(
102 decoration: BoxDecoration(
103 borderRadius: BorderRadius.circular(20.sp),
104 border: Border.all(color: ColorPalette.grey.withValues(alpha: 0.2)),
105 color: Colors.white,
106 ),
107 child: DropdownButtonHideUnderline(
108 child: DropdownButton<int>(
109 isExpanded: true,
111 hint: Text(
112 'full_fill_collection.select_contact'.tr(),
113 style: TextStyle(fontSize: 14.sp),
114 ),
115 icon: const Icon(Icons.keyboard_arrow_down, color: ColorPalette.grey),
116 padding: EdgeInsets.symmetric(horizontal: 16.sp),
117 borderRadius: BorderRadius.circular(8.sp),
118 items: validContacts.map((contact) {
119 return DropdownMenuItem<int>(
120 value: contact.id, // Using contact ID as the value
121 child: Text(
122 contact.reference ?? '',
123 style: TextStyle(fontSize: 14.sp),
124 ),
125 );
126 }).toList(),
128 ),
129 ),
130 ),
131 ],
132 );
133 }
134}
static const grey
final List< DashboardItem > items
final CollectionsState state
final Widget child
final ValueChanged< int?> onChanged
const ContactSelector({ super.key, this.selectedContactId, required this.onChanged, })
override Widget build(BuildContext context)
Widget _buildSelector(List< ResCollectionContactEntity > contacts)
final EdgeInsets padding
const CollectionContactListError({required this.failure})
const CollectionContactListLoaded({required this.contacts})
class CollectionPaymentError extends CollectionsInformationState contacts
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,),),),],)