diff --git a/lib/widgets/dropdown_codegen.dart b/lib/widgets/dropdown_codegen.dart index 30b3dbd9..233da53a 100644 --- a/lib/widgets/dropdown_codegen.dart +++ b/lib/widgets/dropdown_codegen.dart @@ -14,39 +14,12 @@ class DropdownButtonCodegenLanguage extends StatelessWidget { @override Widget build(BuildContext context) { - final surfaceColor = Theme.of(context).colorScheme.surface; - return DropdownButton( - isExpanded: true, - focusColor: surfaceColor, + return ADDropdownButton( 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>((CodegenLanguage value) { - return DropdownMenuItem( - value: value, - child: Padding( - padding: kPs8, - child: Text( - value.label, - style: kTextStyleButton, - overflow: TextOverflow.ellipsis, - maxLines: 1, - ), - ), - ); - }).toList(), + iconSize: 16, + isExpanded: true, ); } } diff --git a/lib/widgets/dropdown_content_type.dart b/lib/widgets/dropdown_content_type.dart index 964029d0..0fbd0f38 100644 --- a/lib/widgets/dropdown_content_type.dart +++ b/lib/widgets/dropdown_content_type.dart @@ -14,36 +14,11 @@ class DropdownButtonContentType extends StatelessWidget { @override Widget build(BuildContext context) { - final surfaceColor = Theme.of(context).colorScheme.surface; - return DropdownButton( - focusColor: surfaceColor, + return ADDropdownButton( 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>((ContentType value) { - return DropdownMenuItem( - value: value, - child: Padding( - padding: kPs8, - child: Text( - value.name, - style: kTextStyleButton, - ), - ), - ); - }).toList(), + iconSize: 16, ); } } diff --git a/lib/widgets/dropdown_formdata.dart b/lib/widgets/dropdown_formdata.dart index fc59e53a..cbb7176e 100644 --- a/lib/widgets/dropdown_formdata.dart +++ b/lib/widgets/dropdown_formdata.dart @@ -14,35 +14,11 @@ class DropdownButtonFormData extends StatelessWidget { @override Widget build(BuildContext context) { - final surfaceColor = Theme.of(context).colorScheme.surface; - return DropdownButton( - dropdownColor: surfaceColor, - focusColor: surfaceColor, + return ADDropdownButton( 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>((FormDataType value) { - return DropdownMenuItem( - value: value, - child: Padding( - padding: kPs8, - child: Text( - value.name, - style: kTextStyleButton, - ), - ), - ); - }).toList(), + iconSize: 16, ); } } diff --git a/lib/widgets/dropdown_http_method.dart b/lib/widgets/dropdown_http_method.dart index fa34e359..044752aa 100644 --- a/lib/widgets/dropdown_http_method.dart +++ b/lib/widgets/dropdown_http_method.dart @@ -16,35 +16,19 @@ class DropdownButtonHttpMethod extends StatelessWidget { @override Widget build(BuildContext context) { - final surfaceColor = Theme.of(context).colorScheme.surface; - return DropdownButton( - focusColor: surfaceColor, + return ADDropdownButton( 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>((HTTPVerb value) { - return DropdownMenuItem( - 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, + ), + ), ); } } diff --git a/lib/widgets/dropdown_import_format.dart b/lib/widgets/dropdown_import_format.dart index 13afd668..263f9f34 100644 --- a/lib/widgets/dropdown_import_format.dart +++ b/lib/widgets/dropdown_import_format.dart @@ -14,39 +14,11 @@ class DropdownButtonImportFormat extends StatelessWidget { @override Widget build(BuildContext context) { - final surfaceColor = Theme.of(context).colorScheme.surface; - return DropdownButton( - isExpanded: false, - focusColor: surfaceColor, + return ADDropdownButton( 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>((ImportFormat value) { - return DropdownMenuItem( - value: value, - child: Padding( - padding: kPs8, - child: Text( - value.label, - style: kTextStyleButton, - overflow: TextOverflow.ellipsis, - maxLines: 1, - ), - ), - ); - }).toList(), + iconSize: 16, ); } } diff --git a/packages/apidash_design_system/lib/apidash_design_system.dart b/packages/apidash_design_system/lib/apidash_design_system.dart index a9d394c4..c8d6ff3e 100644 --- a/packages/apidash_design_system/lib/apidash_design_system.dart +++ b/packages/apidash_design_system/lib/apidash_design_system.dart @@ -1,4 +1,5 @@ library apidash_design_system; export 'package:google_fonts/google_fonts.dart'; +export 'widgets/widgets.dart'; export 'consts.dart'; diff --git a/packages/apidash_design_system/lib/widgets/dropdown.dart b/packages/apidash_design_system/lib/widgets/dropdown.dart new file mode 100644 index 00000000..6bb6eff3 --- /dev/null +++ b/packages/apidash_design_system/lib/widgets/dropdown.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import '../consts.dart'; + +class ADDropdownButton 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( + 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>(((T, String?) value) { + return DropdownMenuItem( + 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(), + ); + } +} diff --git a/packages/apidash_design_system/lib/widgets/widgets.dart b/packages/apidash_design_system/lib/widgets/widgets.dart new file mode 100644 index 00000000..731a8255 --- /dev/null +++ b/packages/apidash_design_system/lib/widgets/widgets.dart @@ -0,0 +1 @@ +export 'dropdown.dart';