134 lines
4.2 KiB
Dart
134 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:niogu_app/core/constants/app_color.dart';
|
|
import 'package:niogu_app/core/constants/app_font_size.dart';
|
|
import 'package:sizer/sizer.dart';
|
|
|
|
class DropdownWithAction extends StatelessWidget {
|
|
final String label;
|
|
final String? value;
|
|
final List<dynamic> items;
|
|
final Function(String?)? onChanged;
|
|
final VoidCallback? onAdd;
|
|
final VoidCallback? onEdit;
|
|
|
|
const DropdownWithAction({
|
|
super.key,
|
|
required this.label,
|
|
required this.value,
|
|
required this.items,
|
|
this.onChanged,
|
|
this.onAdd,
|
|
this.onEdit,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isTablet = 100.w >= 600;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: isTablet ? AppFontSize.medium.sp : AppFontSize.small.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
SizedBox(height: 1.h),
|
|
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: DropdownButtonFormField<String>(
|
|
value: value,
|
|
isExpanded: true,
|
|
items: items
|
|
.map(
|
|
(item) => DropdownMenuItem(
|
|
value: item.id.toString(),
|
|
child: FittedBox(
|
|
child: Text(
|
|
item.name.toString(),
|
|
style: isTablet
|
|
? null
|
|
: TextStyle(fontSize: AppFontSize.small.sp),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.toList(),
|
|
onChanged: onChanged,
|
|
icon: const Icon(Icons.keyboard_arrow_down_rounded),
|
|
decoration: InputDecoration(
|
|
filled: true,
|
|
fillColor: Colors.white,
|
|
contentPadding: EdgeInsets.symmetric(
|
|
horizontal: 4.w,
|
|
vertical: 1.8.h,
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
borderSide: const BorderSide(
|
|
color: AppColor.primaryColor,
|
|
width: 1.5,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
SizedBox(width: 3.w),
|
|
|
|
InkWell(
|
|
onTap: onAdd,
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
child: Container(
|
|
width: 13.w,
|
|
height: 13.w,
|
|
decoration: BoxDecoration(
|
|
color: AppColor.primaryColor,
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColor.primaryColor.withOpacity(0.3),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Icon(Icons.add, color: Colors.white, size: 7.w),
|
|
),
|
|
),
|
|
SizedBox(width: 3.w),
|
|
|
|
InkWell(
|
|
onTap: onEdit,
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
child: Container(
|
|
width: 13.w,
|
|
height: 13.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.teal,
|
|
borderRadius: BorderRadius.circular(2.5.w),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.teal.withOpacity(0.3),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Icon(Icons.edit, color: Colors.white, size: 7.w),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|