562 lines
19 KiB
Dart
562 lines
19 KiB
Dart
// ignore_for_file: prefer_const_constructors
|
|
|
|
import 'dart:ui';
|
|
|
|
import 'package:dropdown_button2/dropdown_button2.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:regroup/Common/CommonWidget.dart';
|
|
import 'package:regroup/Utils/Common/sized_box.dart';
|
|
|
|
class CommonDropdownBtn extends StatefulWidget {
|
|
const CommonDropdownBtn({
|
|
required this.hint,
|
|
required this.items,
|
|
this.isEnabled = true,
|
|
this.islocation = false,
|
|
this.textcolor = false,
|
|
this.onItemSelected,
|
|
bool showAddButton = false,
|
|
super.key,
|
|
});
|
|
final String hint;
|
|
final List<String>? items;
|
|
final void Function(String)? onItemSelected;
|
|
final bool isEnabled;
|
|
final bool islocation;
|
|
final bool textcolor;
|
|
|
|
@override
|
|
State<CommonDropdownBtn> createState() => _CommonDropdownBtnState();
|
|
}
|
|
|
|
class _CommonDropdownBtnState extends State<CommonDropdownBtn> {
|
|
final kInnerDecoration = BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color: Colors.white),
|
|
borderRadius: BorderRadius.circular(30.r),
|
|
);
|
|
late String label;
|
|
final List<String> items = [
|
|
'Item1',
|
|
'Item2',
|
|
'Item3',
|
|
'Item4',
|
|
'Item5',
|
|
'Item6',
|
|
'Item7',
|
|
'Item8',
|
|
];
|
|
String? selectedValue;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownButtonHideUnderline(
|
|
child: Row(
|
|
children: [
|
|
widget.islocation
|
|
? Padding(
|
|
padding: EdgeInsets.only(left: 4.w),
|
|
child: SvgPicture.asset("assets/svg/location.svg"),
|
|
)
|
|
: SizedBox(),
|
|
Expanded(
|
|
child: DropdownButton2(
|
|
isExpanded: true,
|
|
hint: Row(
|
|
children: [
|
|
// SizedBox(
|
|
// width: 4,
|
|
// ),
|
|
// widget.islocation
|
|
// ? SvgPicture.asset("assets/svg/location.svg")
|
|
// : SizedBox(),
|
|
|
|
// widget.islocation ? sizedBoxWidth(4.w) : SizedBox(),
|
|
|
|
Expanded(
|
|
child: Text(
|
|
widget.hint,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontFamily: 'hiragino',
|
|
//fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
items: widget.items!
|
|
.map((item) => DropdownMenuItem<String>(
|
|
value: item,
|
|
child: Text(
|
|
item,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontFamily: 'hiragino',
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
))
|
|
.toList(),
|
|
value: selectedValue,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
selectedValue = value as String;
|
|
});
|
|
},
|
|
buttonStyleData: ButtonStyleData(
|
|
height: 50.h,
|
|
width: double.infinity,
|
|
padding: EdgeInsets.only(left: 12.w, right: 4.w),
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xFFffffff).withOpacity(0.8),
|
|
Color(0xFFFFFFFF).withOpacity(0.8),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderRadius: BorderRadius.circular(30.r),
|
|
border: Border.all(
|
|
color: Color(0xff434A53),
|
|
),
|
|
color: Color(0xFFFFFFFF).withOpacity(0.05),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
iconStyleData: IconStyleData(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_down,
|
|
),
|
|
iconSize: 23.sp,
|
|
iconEnabledColor: Color(0xFFFFFFFF),
|
|
iconDisabledColor: Color(0xFFFFFFFF),
|
|
),
|
|
dropdownStyleData: DropdownStyleData(
|
|
maxHeight: 200,
|
|
width: 350,
|
|
padding: null,
|
|
// padding: EdgeInsets.symmetric(horizontal: 16.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(30),
|
|
// border: Border.all(
|
|
// color: Color(0xffCCCCCC),
|
|
// ),
|
|
color: Color(0xFF222935),
|
|
),
|
|
elevation: 0,
|
|
// offset: const Offset(-20, 0),
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
radius: const Radius.circular(40),
|
|
thickness: MaterialStateProperty.all<double>(6),
|
|
thumbVisibility: MaterialStateProperty.all<bool>(true),
|
|
),
|
|
),
|
|
menuItemStyleData: const MenuItemStyleData(
|
|
height: 40,
|
|
padding: EdgeInsets.only(left: 14, right: 14),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CommonDropdownradioBtn extends StatefulWidget {
|
|
const CommonDropdownradioBtn({
|
|
required this.hint,
|
|
required this.items,
|
|
this.textcolor = false,
|
|
this.onItemSelected,
|
|
super.key,
|
|
});
|
|
|
|
final String hint;
|
|
final List<String>? items;
|
|
final void Function(String)? onItemSelected;
|
|
final bool textcolor;
|
|
|
|
@override
|
|
State<CommonDropdownradioBtn> createState() => _CommonDropdownradioBtnState();
|
|
}
|
|
|
|
class _CommonDropdownradioBtnState extends State<CommonDropdownradioBtn> {
|
|
var selectedValue = ''.obs;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownButtonHideUnderline(
|
|
child: DropdownButton2(
|
|
isExpanded: true,
|
|
hint: Obx(() {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
selectedValue.isEmpty ? widget.hint : selectedValue.value,
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontFamily: 'hiragino',
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
items: widget.items!.asMap().entries.map((entry) {
|
|
int index = entry.key;
|
|
String item = entry.value;
|
|
return DropdownMenuItem<String>(
|
|
value: item,
|
|
child: Column(
|
|
children: [
|
|
InkWell(
|
|
onTap: () {
|
|
selectedValue.value = item;
|
|
if (widget.onItemSelected != null) {
|
|
widget.onItemSelected!(item);
|
|
}
|
|
},
|
|
child: Row(
|
|
children: [
|
|
Obx(() {
|
|
return Radio<String>(
|
|
value: item,
|
|
activeColor: Colors.white,
|
|
groupValue: selectedValue.value,
|
|
onChanged: (value) {
|
|
selectedValue.value = value!;
|
|
if (widget.onItemSelected != null) {
|
|
widget.onItemSelected!(value);
|
|
}
|
|
},
|
|
);
|
|
}),
|
|
SizedBox(width: 8.w),
|
|
Text(
|
|
item,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontFamily: 'hiragino',
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (index != widget.items!.length - 1) commonDivider(),
|
|
],
|
|
),
|
|
);
|
|
}).toList(),
|
|
value: null,
|
|
onChanged: (value) {},
|
|
selectedItemBuilder: (BuildContext context) {
|
|
return widget.items!.map((item) {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Obx(() {
|
|
return Text(
|
|
selectedValue.value,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontFamily: 'hiragino',
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
}).toList();
|
|
},
|
|
buttonStyleData: ButtonStyleData(
|
|
height: 50.h,
|
|
width: double.infinity,
|
|
padding: EdgeInsets.only(left: 12.w, right: 4.w),
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xFFffffff).withOpacity(0.8),
|
|
Color(0xFFFFFFFF).withOpacity(0.8),
|
|
],
|
|
stops: [0.1, 1],
|
|
),
|
|
borderRadius: BorderRadius.circular(30.r),
|
|
border: Border.all(
|
|
color: Color(0xff434A53),
|
|
),
|
|
color: Color(0xFFFFFFFF).withOpacity(0.05),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
iconStyleData: IconStyleData(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_down,
|
|
),
|
|
iconSize: 23.sp,
|
|
iconEnabledColor: Color(0xFFFFFFFF),
|
|
iconDisabledColor: Color(0xFFFFFFFF),
|
|
),
|
|
dropdownStyleData: DropdownStyleData(
|
|
maxHeight: 200,
|
|
width: 400,
|
|
padding: null,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(30),
|
|
color: Color(0xFF222935),
|
|
),
|
|
elevation: 0,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
radius: const Radius.circular(40),
|
|
thickness: MaterialStateProperty.all<double>(6),
|
|
thumbVisibility: MaterialStateProperty.all<bool>(true),
|
|
),
|
|
),
|
|
menuItemStyleData: const MenuItemStyleData(
|
|
height: 50,
|
|
padding: EdgeInsets.only(left: 14, right: 14),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CommonDropdownCheckbox extends StatefulWidget {
|
|
const CommonDropdownCheckbox({
|
|
required this.hint,
|
|
required this.items,
|
|
required this.images,
|
|
this.isEnabled = true,
|
|
this.islocation = false,
|
|
this.textcolor = false,
|
|
this.onItemSelected,
|
|
bool showAddButton = false,
|
|
super.key,
|
|
});
|
|
final String hint;
|
|
final List<String>? items;
|
|
final List<String>? images;
|
|
final void Function(String)? onItemSelected;
|
|
final bool isEnabled;
|
|
final bool islocation;
|
|
final bool textcolor;
|
|
|
|
@override
|
|
State<CommonDropdownCheckbox> createState() => _CommonDropdownCheckboxState();
|
|
}
|
|
|
|
class _CommonDropdownCheckboxState extends State<CommonDropdownCheckbox> {
|
|
var selectedValues = <String>[].obs;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownButtonHideUnderline(
|
|
child: Row(
|
|
children: [
|
|
widget.islocation
|
|
? Padding(
|
|
padding: EdgeInsets.only(left: 4.w),
|
|
child: SvgPicture.asset("assets/svg/location.svg"),
|
|
)
|
|
: SizedBox(),
|
|
Expanded(
|
|
child: DropdownButton2(
|
|
isExpanded: true,
|
|
hint: Obx(() {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
selectedValues.isEmpty
|
|
? widget.hint
|
|
: selectedValues.join(', '),
|
|
style: TextStyle(
|
|
fontSize: 12.sp,
|
|
fontFamily: 'hiragino',
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
items: widget.items!.asMap().entries.map((entry) {
|
|
int index = entry.key;
|
|
String item = entry.value;
|
|
String image = widget.images![index];
|
|
return DropdownMenuItem<String>(
|
|
value: item,
|
|
child: InkWell(
|
|
onTap: () {
|
|
selectedValues.contains(item)
|
|
? selectedValues.remove(item)
|
|
: selectedValues.add(item);
|
|
|
|
if (widget.onItemSelected != null) {
|
|
widget.onItemSelected!(selectedValues.join(', '));
|
|
}
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 40.w,
|
|
height: 40.h,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
image: DecorationImage(
|
|
image: AssetImage(image),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: Text(
|
|
item,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontFamily: 'hiragino',
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
Obx(() {
|
|
return Transform.scale(
|
|
scale: 1,
|
|
child: Checkbox(
|
|
side: BorderSide(color: Color(0xFF434A53)),
|
|
value: selectedValues.contains(item),
|
|
activeColor: Color(0xFF434A53),
|
|
checkColor: Colors.white,
|
|
onChanged: (bool? value) {
|
|
if (value == true) {
|
|
selectedValues.add(item);
|
|
} else {
|
|
selectedValues.remove(item);
|
|
}
|
|
if (widget.onItemSelected != null) {
|
|
widget.onItemSelected!(
|
|
selectedValues.join(', '));
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
SizedBox(height: 5.h),
|
|
if (index != widget.items!.length - 1) commonDivider()
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
value: null, // Set to null to avoid the duplicate value issue
|
|
onChanged: (value) {},
|
|
selectedItemBuilder: (BuildContext context) {
|
|
return widget.items!.map((item) {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Obx(() {
|
|
return Text(
|
|
selectedValues.join(', '),
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontFamily: 'hiragino',
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
}).toList();
|
|
},
|
|
buttonStyleData: ButtonStyleData(
|
|
height: 50.h,
|
|
width: double.infinity,
|
|
padding: EdgeInsets.only(left: 12.w, right: 4.w),
|
|
decoration: BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xFFffffff).withOpacity(0.8),
|
|
Color(0xFFFFFFFF).withOpacity(0.8),
|
|
],
|
|
stops: [0.1, 1],
|
|
),
|
|
borderRadius: BorderRadius.circular(30.r),
|
|
border: Border.all(
|
|
color: Color(0xff434A53),
|
|
),
|
|
color: Color(0xFFFFFFFF).withOpacity(0.05),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
iconStyleData: IconStyleData(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_down,
|
|
),
|
|
iconSize: 23.sp,
|
|
iconEnabledColor: Color(0xFFFFFFFF),
|
|
iconDisabledColor: Color(0xFFFFFFFF),
|
|
),
|
|
dropdownStyleData: DropdownStyleData(
|
|
maxHeight: 200,
|
|
width: 400,
|
|
padding: null,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(30),
|
|
color: Color(0xFF222935),
|
|
),
|
|
elevation: 0,
|
|
scrollbarTheme: ScrollbarThemeData(
|
|
radius: Radius.circular(40),
|
|
thickness: MaterialStateProperty.all<double>(6),
|
|
thumbVisibility: MaterialStateProperty.all<bool>(true),
|
|
),
|
|
),
|
|
menuItemStyleData: const MenuItemStyleData(
|
|
height: 60,
|
|
padding: EdgeInsets.only(left: 14, right: 14),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|