Files
apidash/lib/widgets/dropdowns.dart
2023-12-24 16:49:31 +05:30

141 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:apidash/utils/utils.dart';
import 'package:apidash/consts.dart';
class DropdownButtonHttpMethod extends StatelessWidget {
const DropdownButtonHttpMethod({
super.key,
this.method,
this.onChanged,
});
final HTTPVerb? method;
final void Function(HTTPVerb? value)? onChanged;
@override
Widget build(BuildContext context) {
final surfaceColor = Theme.of(context).colorScheme.surface;
return DropdownButton<HTTPVerb>(
focusColor: surfaceColor,
value: method,
icon: const Icon(Icons.unfold_more_rounded),
elevation: 4,
underline: Container(
height: 0,
),
borderRadius: kBorderRadius12,
onChanged: onChanged,
items: HTTPVerb.values.map<DropdownMenuItem<HTTPVerb>>((HTTPVerb value) {
return DropdownMenuItem<HTTPVerb>(
value: value,
child: Padding(
padding: const EdgeInsets.only(left: 16),
child: Text(
value.name.toUpperCase(),
style: kCodeStyle.copyWith(
fontWeight: FontWeight.bold,
color: getHTTPMethodColor(
value,
brightness: Theme.of(context).brightness,
),
),
),
),
);
}).toList(),
);
}
}
class DropdownButtonContentType extends StatelessWidget {
const DropdownButtonContentType({
super.key,
this.contentType,
this.onChanged,
});
final ContentType? contentType;
final void Function(ContentType?)? onChanged;
@override
Widget build(BuildContext context) {
final surfaceColor = Theme.of(context).colorScheme.surface;
return DropdownButton<ContentType>(
focusColor: surfaceColor,
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,
),
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(),
);
}
}
class DropdownButtonCodegenLanguage extends StatelessWidget {
const DropdownButtonCodegenLanguage({
super.key,
this.codegenLanguage,
this.onChanged,
});
final CodegenLanguage? codegenLanguage;
final void Function(CodegenLanguage?)? onChanged;
@override
Widget build(BuildContext context) {
final surfaceColor = Theme.of(context).colorScheme.surface;
return DropdownButton<CodegenLanguage>(
focusColor: surfaceColor,
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,
),
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,
),
),
);
}).toList(),
);
}
}