onufitness_mobile/lib/widgets/Dropdowns/custom_lebel_dropdown.dart
2026-01-13 11:36:24 +05:30

159 lines
5.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:onufitness/constants/color_constant.dart';
import 'package:onufitness/utils/helper_function.dart';
class EnhancedLebelTextDropdown extends StatefulWidget {
final String title;
final String? selectedItem;
final List<String> items;
final ValueChanged<String?>? onChanged;
final Color? borderColor;
final Color? filledColor;
final double? height;
const EnhancedLebelTextDropdown({
super.key,
required this.title,
required this.items,
this.selectedItem,
this.onChanged,
this.borderColor,
this.filledColor,
this.height,
});
@override
EnhancedLebelTextDropdownState createState() =>
EnhancedLebelTextDropdownState();
}
class EnhancedLebelTextDropdownState extends State<EnhancedLebelTextDropdown> {
@override
Widget build(BuildContext context) {
final Color effectiveBorderColor =
widget.borderColor ?? textfieldBorderColorSky1;
bool hasSelectedItem =
widget.selectedItem != null && widget.selectedItem!.isNotEmpty;
return Container(
height: hasSelectedItem ? widget.height : 60.h,
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
decoration: BoxDecoration(
border: Border.all(color: effectiveBorderColor),
borderRadius: BorderRadius.circular(10.r),
color: widget.filledColor ?? textFieldFillColor,
),
child:
hasSelectedItem
? Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.title,
style: TextStyle(
fontSize: (isTablet ? 11.sp : 14.sp),
fontWeight: FontWeight.w500,
color: greyTextColor1,
),
),
SizedBox(height: 4.h),
DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: widget.selectedItem,
hint: Text(
widget.title,
style: TextStyle(
fontSize: isTablet ? 16.sp : 16.sp,
color: greyTextColor1,
),
),
icon: Container(),
isExpanded: true,
isDense: true,
items:
widget.items.map<DropdownMenuItem<String>>((
String value,
) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(
fontSize: isTablet ? 14.sp : 16.sp,
color: Colors.black,
),
),
);
}).toList(),
onChanged: widget.onChanged,
dropdownColor: Colors.white,
borderRadius: BorderRadius.circular(10.r),
menuMaxHeight: 200.h,
underline: Container(),
),
),
],
),
),
Icon(
Icons.keyboard_arrow_down,
color: greyTextColor1,
size: isTablet ? 20.sp : 18.sp,
),
],
)
: Row(
children: [
Expanded(
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: widget.selectedItem,
hint: Text(
widget.title,
style: TextStyle(
fontSize: isTablet ? 15.sp : 16.sp,
color: greyTextColor1,
),
),
icon: Container(),
isExpanded: true,
isDense: true,
items:
widget.items.map<DropdownMenuItem<String>>((
String value,
) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(
fontSize: isTablet ? 14.sp : 16.sp,
color: Colors.black,
),
),
);
}).toList(),
onChanged: widget.onChanged,
dropdownColor: Colors.white,
borderRadius: BorderRadius.circular(10.r),
menuMaxHeight: 200.h,
),
),
),
Icon(
Icons.keyboard_arrow_down,
color: greyTextColor1,
size: isTablet ? 20.sp : 18.sp,
),
],
),
);
}
}