login Enhancements and add search to forget password

This commit is contained in:
mohammad
2024-09-03 08:58:48 +03:00
parent 418f5d5406
commit 8130acc392
2 changed files with 128 additions and 143 deletions

View File

@ -1,3 +1,4 @@
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
@ -148,44 +149,7 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
const SizedBox(height: 10),
SizedBox(
child: DropdownButtonFormField<String>(
validator: forgetBloc.validateRegion,
icon: const Icon(
Icons.keyboard_arrow_down_outlined,
),
decoration:
textBoxDecoration()!.copyWith(
hintText: null,
),
hint: SizedBox(
width: size.width * 0.12,
child: const Align(
alignment: Alignment.centerLeft,
child: Text(
'Select your region/country',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
),
),
),
isDense: true,
style: const TextStyle(
color: Colors.black),
items: forgetBloc.regionList!
.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id,
child: SizedBox(
width: size.width * 0.06,
child: Text(region.name)),
);
}).toList(),
onChanged: (String? value) {
forgetBloc.add(SelectRegionEvent(
val: value!,
));
},
),
child: _buildDropdownField(context, forgetBloc, size)
)
],
),
@ -411,4 +375,109 @@ class ForgetPasswordWebPage extends StatelessWidget {
),
));
}
Widget _buildDropdownField(
BuildContext context, AuthBloc loginBloc, Size size) {
final TextEditingController textEditingController = TextEditingController();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"Country/Region",
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
Container(
height: 50,
decoration: const BoxDecoration(
color: ColorsManager.boxColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
),
width: size.width * 0.9,
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
style: TextStyle(color: Colors.black),
isExpanded: true,
hint: Text(
'Select your region/country',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
overflow: TextOverflow.ellipsis,
),
items: loginBloc.regionList!.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id, // Use region.id as the value
child: Text(
region.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
);
}).toList(),
value: loginBloc.regionList!.any(
(region) => region.id == loginBloc.regionUuid,)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
if (value != null) {
loginBloc.add(SelectRegionEvent(
val: value,
));
}
},
buttonStyleData: const ButtonStyleData(
padding: EdgeInsets.symmetric(horizontal: 16),
height: 40,
width: double.infinity,
),
dropdownStyleData: DropdownStyleData(
maxHeight: size.height * 0.70,
),
menuItemStyleData: const MenuItemStyleData(
height: 40,
),
dropdownSearchData: DropdownSearchData(
searchController: textEditingController,
searchInnerWidgetHeight: 50,
searchInnerWidget: Container(
height: 50,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: TextFormField(
style: const TextStyle(color: Colors.black),
controller: textEditingController,
decoration: textBoxDecoration()!.copyWith(
errorStyle: const TextStyle(height: 0),
contentPadding: const EdgeInsets.symmetric(
vertical: 12,
horizontal: 10,
),
),
),
),
searchMatchFn: (item, searchValue) {
// Use the item's child text (region name) for searching.
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
final search = searchValue.toLowerCase().trim();
// Debugging print statement to ensure values are captured correctly.
// Return true if the region name contains the search term.
return regionName.contains(search);
},
),
onMenuStateChange: (isOpen) {
if (!isOpen) {
textEditingController.clear();
}
},
),
),
),
],
);
}
}

View File

@ -181,87 +181,6 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}
// Widget _buildDropdownField(BuildContext context, AuthBloc loginBloc, Size size) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Text(
// "Country/Region",
// style: Theme.of(context)
// .textTheme
// .bodySmall!
// .copyWith(fontSize: 14, fontWeight: FontWeight.w400),
// ),
// const SizedBox(height: 10),
// SizedBox(
// width: size.width * 0.8,
// child: LayoutBuilder(
// builder: (context, constraints) {
// return DropdownButtonFormField<String>(
// value: loginBloc.regionList!.any((region) => region.id == loginBloc.regionUuid)
// ? loginBloc.regionUuid
// : null,
// validator: loginBloc.validateRegion,
// icon: const Icon(
// Icons.keyboard_arrow_down_outlined,
// size: 20,
// ),
// decoration: textBoxDecoration()!.copyWith(
// errorStyle: const TextStyle(height: 0),
// contentPadding: const EdgeInsets.symmetric(
// vertical: 12,
// horizontal: 10,
// ),
// ),
// hint: Text(
// 'Select your region/country',
// style: Theme.of(context)
// .textTheme
// .bodySmall!
// .copyWith(color: ColorsManager.grayColor, fontWeight: FontWeight.w400),
// overflow: TextOverflow.ellipsis,
// ),
// isDense: true,
// style: const TextStyle(color: Colors.black),
// items: loginBloc.regionList!.map((RegionModel region) {
// return DropdownMenuItem<String>(
// value: region.id,
// child: Container(
// constraints: BoxConstraints(maxWidth: constraints.maxWidth - 40),
// child: Text(
// region.name,
// overflow: TextOverflow.ellipsis,
// maxLines: 1,
// ),
// ),
// );
// }).toList(),
// onChanged: (String? value) {
// loginBloc.add(CheckEnableEvent());
// loginBloc.add(SelectRegionEvent(val: value!));
// },
// dropdownColor: Colors.white,
// menuMaxHeight: size.height * 0.45,
// selectedItemBuilder: (context) {
// return loginBloc.regionList!.map<Widget>((region) {
// return Container(
// constraints: BoxConstraints(maxWidth: constraints.maxWidth - 40),
// child: Text(
// region.name,
// overflow: TextOverflow.ellipsis,
// maxLines: 1,
// ),
// );
// }).toList();
// },
// );
// },
// ),
// ),
// ],
// );
// }
Widget _buildDropdownField(
BuildContext context, AuthBloc loginBloc, Size size) {
@ -273,31 +192,33 @@ class _LoginWebPageState extends State<LoginWebPage>
Text(
"Country/Region",
style: Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
),
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
const SizedBox(height: 10),
Container(
height: size.height * 0.05,
decoration:const BoxDecoration(
color: ColorsManager.boxColor,
borderRadius: BorderRadius.all(Radius.circular(8))),
height: 50,
decoration: const BoxDecoration(
color: ColorsManager.boxColor,
borderRadius: BorderRadius.all(Radius.circular(8)),
),
width: size.width * 0.9,
child: DropdownButtonHideUnderline(
child: DropdownButton2<String>(
style: TextStyle(color: Colors.black),
isExpanded: true,
hint: Text(
'Select your region/country',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
color: ColorsManager.grayColor,
fontWeight: FontWeight.w400,
),
overflow: TextOverflow.ellipsis,
),
items: loginBloc.regionList!.map((RegionModel region) {
return DropdownMenuItem<String>(
value: region.id,
value: region.id, // Use region.id as the value
child: Text(
region.name,
overflow: TextOverflow.ellipsis,
@ -306,8 +227,7 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}).toList(),
value: loginBloc.regionList!.any(
(region) => region.id == loginBloc.regionUuid,
)
(region) => region.id == loginBloc.regionUuid,)
? loginBloc.regionUuid
: null,
onChanged: (String? value) {
@ -322,7 +242,7 @@ class _LoginWebPageState extends State<LoginWebPage>
width: double.infinity,
),
dropdownStyleData: DropdownStyleData(
maxHeight: size.height * 0.45,
maxHeight: size.height * 0.70,
),
menuItemStyleData: const MenuItemStyleData(
height: 40,
@ -334,7 +254,7 @@ class _LoginWebPageState extends State<LoginWebPage>
height: 50,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: TextFormField(
style: TextStyle(color: Colors.black),
style: const TextStyle(color: Colors.black),
controller: textEditingController,
decoration: textBoxDecoration()!.copyWith(
errorStyle: const TextStyle(height: 0),
@ -345,19 +265,14 @@ class _LoginWebPageState extends State<LoginWebPage>
),
),
),
searchMatchFn: (item, searchValue) {
// Ensure both item value and search value are compared in lowercase for a case-insensitive match.
final itemValue = item.value?.toLowerCase() ?? '';
// Use the item's child text (region name) for searching.
final regionName = (item.child as Text).data?.toLowerCase() ?? '';
final search = searchValue.toLowerCase().trim();
// Debugging print statement to ensure values are captured correctly.
print('searchValue == $search');
// Return true if the item value contains the search term.
return itemValue.contains(search);
// Return true if the region name contains the search term.
return regionName.contains(search);
},
),
onMenuStateChange: (isOpen) {
if (!isOpen) {
@ -371,6 +286,7 @@ class _LoginWebPageState extends State<LoginWebPage>
);
}
Widget _buildEmailField(BuildContext context, AuthBloc loginBloc) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,