mirror of
https://github.com/foss42/apidash.git
synced 2025-12-16 02:44:08 +08:00
Migrate DropdownButton => ADDropdownButton
This commit is contained in:
61
packages/apidash_design_system/lib/widgets/dropdown.dart
Normal file
61
packages/apidash_design_system/lib/widgets/dropdown.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
class ADDropdownButton<T> extends StatelessWidget {
|
||||
const ADDropdownButton({
|
||||
super.key,
|
||||
this.value,
|
||||
required this.values,
|
||||
this.onChanged,
|
||||
this.isExpanded = false,
|
||||
this.iconSize,
|
||||
this.dropdownMenuItemPadding = kPs8,
|
||||
this.dropdownMenuItemtextStyle,
|
||||
});
|
||||
|
||||
final T? value;
|
||||
final Iterable<(T, String?)> values;
|
||||
final void Function(T?)? onChanged;
|
||||
final bool isExpanded;
|
||||
final double? iconSize;
|
||||
final EdgeInsetsGeometry dropdownMenuItemPadding;
|
||||
final TextStyle? Function(T)? dropdownMenuItemtextStyle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<T>(
|
||||
isExpanded: isExpanded,
|
||||
focusColor: surfaceColor,
|
||||
value: value,
|
||||
icon: Icon(
|
||||
Icons.unfold_more_rounded,
|
||||
size: iconSize,
|
||||
),
|
||||
elevation: 4,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
underline: Container(
|
||||
height: 0,
|
||||
),
|
||||
onChanged: onChanged,
|
||||
borderRadius: kBorderRadius12,
|
||||
items: values.map<DropdownMenuItem<T>>(((T, String?) value) {
|
||||
return DropdownMenuItem<T>(
|
||||
value: value.$1,
|
||||
child: Padding(
|
||||
padding: dropdownMenuItemPadding,
|
||||
child: Text(
|
||||
value.$2 ?? value.$1.toString(),
|
||||
style:
|
||||
dropdownMenuItemtextStyle?.call(value.$1) ?? kTextStyleButton,
|
||||
overflow: isExpanded ? TextOverflow.ellipsis : null,
|
||||
maxLines: isExpanded ? 1 : null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user