111 lines
3.2 KiB
Dart
111 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class DropdownWidget {
|
|
static Widget normalDropdown({
|
|
String? labelText,
|
|
String? hintText,
|
|
bool required = true,
|
|
String? selectedItem,
|
|
Function(String?)? onChanged,
|
|
void Function()? onTap,
|
|
required List<DropdownMenuItem<String>> list,
|
|
required BuildContext context,
|
|
CrossAxisAlignment align = CrossAxisAlignment.start,
|
|
EdgeInsetsGeometry? padding,
|
|
}) {
|
|
return Padding(
|
|
padding: padding ?? EdgeInsets.symmetric(horizontal: 20),
|
|
child: Column(
|
|
crossAxisAlignment: align,
|
|
children: [
|
|
if (labelText != null)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
labelText,
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w500,
|
|
fontFamily: 'FiraCode',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
dropdown2(
|
|
hint: hintText ?? "",
|
|
list: list,
|
|
onChanged: onChanged,
|
|
required: required,
|
|
onTap: onTap,
|
|
selectedItem: selectedItem,
|
|
context: context,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
static Widget dropdown2({
|
|
required String hint,
|
|
required List<DropdownMenuItem<String>> list,
|
|
bool required = false,
|
|
String? selectedItem,
|
|
Color? dropdownColor,
|
|
void Function()? onTap,
|
|
required Function(String?)? onChanged,
|
|
required BuildContext context,
|
|
}) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: DropdownButton<String>(
|
|
items: list,
|
|
elevation: 0,
|
|
onChanged: (val) {
|
|
onChanged?.call(val);
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
onTap: onTap,
|
|
icon: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 3, 0, 0),
|
|
child: Icon(Icons.keyboard_arrow_down, color: Colors.black, size: 24),
|
|
),
|
|
menuWidth: MediaQuery.of(context).size.width * 0.9,
|
|
borderRadius: BorderRadius.circular(12),
|
|
menuMaxHeight:
|
|
MediaQuery.of(context).size.height * 0.8, // Batasi tinggi menu
|
|
alignment:
|
|
AlignmentDirectional.centerStart, // Pastikan menu di bawah tombol
|
|
// decoration: InputDecoration(
|
|
// border: InputBorder.none, // Hilangkan border default
|
|
// contentPadding: EdgeInsets.zero, // Sesuaikan padding
|
|
// ),
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w400,
|
|
color: Colors.grey,
|
|
fontFamily: 'DMSans',
|
|
),
|
|
isExpanded: true,
|
|
hint: Text(
|
|
hint,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w400,
|
|
color: Colors.grey,
|
|
fontFamily: 'DMSans',
|
|
),
|
|
),
|
|
value: selectedItem,
|
|
underline: Container(), // Menghilangkan garis bawah default
|
|
dropdownColor: Colors.amber,
|
|
),
|
|
);
|
|
}
|
|
}
|