mirror of
https://github.com/foss42/apidash.git
synced 2025-05-30 05:21:15 +08:00
Migrate DropdownButton => ADDropdownButton
This commit is contained in:
@ -14,39 +14,12 @@ class DropdownButtonCodegenLanguage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<CodegenLanguage>(
|
||||
isExpanded: true,
|
||||
focusColor: surfaceColor,
|
||||
return ADDropdownButton<CodegenLanguage>(
|
||||
value: codegenLanguage,
|
||||
icon: const Icon(
|
||||
Icons.unfold_more_rounded,
|
||||
size: 16,
|
||||
),
|
||||
elevation: 4,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
underline: Container(
|
||||
height: 0,
|
||||
),
|
||||
values: CodegenLanguage.values.map((e) => (e, e.label)),
|
||||
onChanged: onChanged,
|
||||
borderRadius: kBorderRadius12,
|
||||
items: CodegenLanguage.values
|
||||
.map<DropdownMenuItem<CodegenLanguage>>((CodegenLanguage value) {
|
||||
return DropdownMenuItem<CodegenLanguage>(
|
||||
value: value,
|
||||
child: Padding(
|
||||
padding: kPs8,
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStyleButton,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
iconSize: 16,
|
||||
isExpanded: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,36 +14,11 @@ class DropdownButtonContentType extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<ContentType>(
|
||||
focusColor: surfaceColor,
|
||||
return ADDropdownButton<ContentType>(
|
||||
value: contentType,
|
||||
icon: const Icon(
|
||||
Icons.unfold_more_rounded,
|
||||
size: 16,
|
||||
),
|
||||
elevation: 4,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
underline: Container(
|
||||
height: 0,
|
||||
),
|
||||
values: ContentType.values.map((e) => (e, e.name)),
|
||||
onChanged: onChanged,
|
||||
borderRadius: kBorderRadius12,
|
||||
items: ContentType.values
|
||||
.map<DropdownMenuItem<ContentType>>((ContentType value) {
|
||||
return DropdownMenuItem<ContentType>(
|
||||
value: value,
|
||||
child: Padding(
|
||||
padding: kPs8,
|
||||
child: Text(
|
||||
value.name,
|
||||
style: kTextStyleButton,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
iconSize: 16,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,35 +14,11 @@ class DropdownButtonFormData extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<FormDataType>(
|
||||
dropdownColor: surfaceColor,
|
||||
focusColor: surfaceColor,
|
||||
return ADDropdownButton<FormDataType>(
|
||||
value: formDataType,
|
||||
icon: const Icon(
|
||||
Icons.unfold_more_rounded,
|
||||
size: 16,
|
||||
),
|
||||
elevation: 4,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
underline: const IgnorePointer(),
|
||||
values: FormDataType.values.map((e) => (e, e.name)),
|
||||
onChanged: onChanged,
|
||||
borderRadius: kBorderRadius12,
|
||||
items: FormDataType.values
|
||||
.map<DropdownMenuItem<FormDataType>>((FormDataType value) {
|
||||
return DropdownMenuItem<FormDataType>(
|
||||
value: value,
|
||||
child: Padding(
|
||||
padding: kPs8,
|
||||
child: Text(
|
||||
value.name,
|
||||
style: kTextStyleButton,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
iconSize: 16,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -16,35 +16,19 @@ class DropdownButtonHttpMethod extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<HTTPVerb>(
|
||||
focusColor: surfaceColor,
|
||||
return ADDropdownButton<HTTPVerb>(
|
||||
value: method,
|
||||
icon: const Icon(Icons.unfold_more_rounded),
|
||||
elevation: 4,
|
||||
underline: Container(
|
||||
height: 0,
|
||||
),
|
||||
borderRadius: kBorderRadius12,
|
||||
values: HTTPVerb.values.map((e) => (e, e.name.toUpperCase())),
|
||||
onChanged: onChanged,
|
||||
items: HTTPVerb.values.map<DropdownMenuItem<HTTPVerb>>((HTTPVerb value) {
|
||||
return DropdownMenuItem<HTTPVerb>(
|
||||
value: value,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: context.isMediumWindow ? 8 : 16),
|
||||
child: Text(
|
||||
value.name.toUpperCase(),
|
||||
style: kCodeStyle.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getHTTPMethodColor(
|
||||
value,
|
||||
brightness: Theme.of(context).brightness,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
dropdownMenuItemPadding:
|
||||
EdgeInsets.only(left: context.isMediumWindow ? 8 : 16),
|
||||
dropdownMenuItemtextStyle: (HTTPVerb v) => kCodeStyle.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getHTTPMethodColor(
|
||||
v,
|
||||
brightness: Theme.of(context).brightness,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,39 +14,11 @@ class DropdownButtonImportFormat extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final surfaceColor = Theme.of(context).colorScheme.surface;
|
||||
return DropdownButton<ImportFormat>(
|
||||
isExpanded: false,
|
||||
focusColor: surfaceColor,
|
||||
return ADDropdownButton<ImportFormat>(
|
||||
value: importFormat,
|
||||
icon: const Icon(
|
||||
Icons.unfold_more_rounded,
|
||||
size: 16,
|
||||
),
|
||||
elevation: 4,
|
||||
style: kCodeStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
underline: Container(
|
||||
height: 0,
|
||||
),
|
||||
values: ImportFormat.values.map((e) => (e, e.label)),
|
||||
onChanged: onChanged,
|
||||
borderRadius: kBorderRadius12,
|
||||
items: ImportFormat.values
|
||||
.map<DropdownMenuItem<ImportFormat>>((ImportFormat value) {
|
||||
return DropdownMenuItem<ImportFormat>(
|
||||
value: value,
|
||||
child: Padding(
|
||||
padding: kPs8,
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStyleButton,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
iconSize: 16,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
library apidash_design_system;
|
||||
|
||||
export 'package:google_fonts/google_fonts.dart';
|
||||
export 'widgets/widgets.dart';
|
||||
export 'consts.dart';
|
||||
|
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(),
|
||||
);
|
||||
}
|
||||
}
|
1
packages/apidash_design_system/lib/widgets/widgets.dart
Normal file
1
packages/apidash_design_system/lib/widgets/widgets.dart
Normal file
@ -0,0 +1 @@
|
||||
export 'dropdown.dart';
|
Reference in New Issue
Block a user