174 lines
5.6 KiB
Dart
174 lines
5.6 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';
|
|
|
|
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(32),
|
|
);
|
|
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.1),
|
|
Color(0xFFFFFFFF).withOpacity(0.05),
|
|
],
|
|
stops: [
|
|
0.1,
|
|
1,
|
|
]),
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(
|
|
color: Color(0xffFEF3F8),
|
|
),
|
|
color: Color(0xFFFFFFFF).withOpacity(0.05),
|
|
),
|
|
elevation: 0,
|
|
),
|
|
iconStyleData: IconStyleData(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_down,
|
|
),
|
|
iconSize: 23.sp,
|
|
iconEnabledColor: Color(0xFF9A0000),
|
|
iconDisabledColor: Color(0xFF9A0000),
|
|
),
|
|
dropdownStyleData: DropdownStyleData(
|
|
maxHeight: 200,
|
|
width: 350,
|
|
padding: null,
|
|
// padding: EdgeInsets.symmetric(horizontal: 16.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(
|
|
color: Color(0xffCCCCCC),
|
|
),
|
|
color: Color(0xFF9A0000).withOpacity(0.9),
|
|
),
|
|
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),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|