mirror of
https://github.com/foss42/apidash.git
synced 2025-05-28 04:08:39 +08:00
Update support for new popup menu
This commit is contained in:
@ -7,50 +7,21 @@ class CodegenPopupMenu extends StatelessWidget {
|
||||
super.key,
|
||||
required this.value,
|
||||
this.onChanged,
|
||||
this.items,
|
||||
});
|
||||
|
||||
final CodegenLanguage value;
|
||||
final void Function(CodegenLanguage? value)? onChanged;
|
||||
final List<CodegenLanguage>? items;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double boxLength = context.isCompactWindow ? 150 : 220;
|
||||
return PopupMenuButton<CodegenLanguage>(
|
||||
final double width = context.isCompactWindow ? 150 : 220;
|
||||
return ADPopupMenu<CodegenLanguage>(
|
||||
value: value.label,
|
||||
values: CodegenLanguage.values.map((e) => (e, e.label)),
|
||||
width: width,
|
||||
tooltip: "Select Code Generation Language",
|
||||
surfaceTintColor: kColorTransparent,
|
||||
constraints: BoxConstraints(minWidth: boxLength),
|
||||
itemBuilder: (BuildContext context) => items!
|
||||
.map((item) => PopupMenuItem<CodegenLanguage>(
|
||||
value: item,
|
||||
child: Text(
|
||||
item.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onSelected: onChanged,
|
||||
child: Container(
|
||||
width: boxLength,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
isOutlined: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,70 +3,39 @@ import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import '../consts.dart';
|
||||
|
||||
class EnvironmentPopupMenu extends StatelessWidget {
|
||||
const EnvironmentPopupMenu({
|
||||
super.key,
|
||||
this.value,
|
||||
this.options,
|
||||
this.onChanged,
|
||||
this.items,
|
||||
});
|
||||
|
||||
final EnvironmentModel? value;
|
||||
final void Function(EnvironmentModel? value)? onChanged;
|
||||
final List<EnvironmentModel>? items;
|
||||
final EnvironmentModel? noneEnvironmentModel = null;
|
||||
final List<EnvironmentModel>? options;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final valueName = getEnvironmentTitle(value?.name);
|
||||
final double boxLength = context.isCompactWindow ? 100 : 130;
|
||||
return PopupMenuButton(
|
||||
final double width = context.isCompactWindow ? 100 : 130;
|
||||
|
||||
return ADPopupMenu<EnvironmentModel?>(
|
||||
value: (value == null || value?.id == kGlobalEnvironmentId)
|
||||
? "None"
|
||||
: getEnvironmentTitle(value?.name),
|
||||
values: options?.map((e) => (
|
||||
e,
|
||||
(e.id == kGlobalEnvironmentId)
|
||||
? "None"
|
||||
: getEnvironmentTitle(e.name).clip(30)
|
||||
)) ??
|
||||
[],
|
||||
width: width,
|
||||
tooltip: "Select Environment",
|
||||
surfaceTintColor: kColorTransparent,
|
||||
constraints: BoxConstraints(minWidth: boxLength),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
value: noneEnvironmentModel,
|
||||
onTap: () {
|
||||
onChanged?.call(null);
|
||||
},
|
||||
child: const Text("None"),
|
||||
),
|
||||
...items!.map((EnvironmentModel environment) {
|
||||
final name = getEnvironmentTitle(environment.name).clip(30);
|
||||
return PopupMenuItem(
|
||||
value: environment,
|
||||
child: Text(
|
||||
name,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
})
|
||||
];
|
||||
},
|
||||
onSelected: onChanged,
|
||||
child: Container(
|
||||
width: boxLength,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value == null ? "None" : valueName,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
isOutlined: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,57 +5,23 @@ import 'package:apidash/consts.dart';
|
||||
class HistoryRetentionPopupMenu extends StatelessWidget {
|
||||
const HistoryRetentionPopupMenu({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
this.items,
|
||||
this.value,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
final HistoryRetentionPeriod value;
|
||||
final void Function(HistoryRetentionPeriod value) onChanged;
|
||||
final List<HistoryRetentionPeriod>? items;
|
||||
final HistoryRetentionPeriod? value;
|
||||
final void Function(HistoryRetentionPeriod? value)? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const double boxLength = 120;
|
||||
return PopupMenuButton(
|
||||
const double width = 120;
|
||||
return ADPopupMenu<HistoryRetentionPeriod>(
|
||||
value: value?.label,
|
||||
values: HistoryRetentionPeriod.values.map((e) => (e, e.label)),
|
||||
width: width,
|
||||
tooltip: "Select retention period",
|
||||
surfaceTintColor: kColorTransparent,
|
||||
constraints: const BoxConstraints(minWidth: boxLength),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return [
|
||||
...items!.map((period) {
|
||||
return PopupMenuItem(
|
||||
value: period,
|
||||
child: Text(
|
||||
period.label,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
);
|
||||
})
|
||||
];
|
||||
},
|
||||
onSelected: onChanged,
|
||||
child: Container(
|
||||
width: boxLength,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
onChanged: onChanged,
|
||||
isOutlined: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +1,27 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:apidash_design_system/apidash_design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class URIPopupMenu extends StatelessWidget {
|
||||
const URIPopupMenu({
|
||||
class DefaultUriSchemePopupMenu extends StatelessWidget {
|
||||
const DefaultUriSchemePopupMenu({
|
||||
super.key,
|
||||
required this.value,
|
||||
this.value,
|
||||
this.onChanged,
|
||||
this.items,
|
||||
});
|
||||
|
||||
final String value;
|
||||
final void Function(String? value)? onChanged;
|
||||
final List<String>? items;
|
||||
final SupportedUriSchemes? value;
|
||||
final void Function(SupportedUriSchemes? value)? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double boxLength = context.isCompactWindow ? 90 : 110;
|
||||
return PopupMenuButton(
|
||||
tooltip: "Select URI Scheme",
|
||||
surfaceTintColor: kColorTransparent,
|
||||
constraints: BoxConstraints(minWidth: boxLength),
|
||||
itemBuilder: (BuildContext context) => items!
|
||||
.map((item) => PopupMenuItem(
|
||||
value: item,
|
||||
child: Text(
|
||||
item,
|
||||
style: kTextStylePopupMenuItem,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
onSelected: onChanged,
|
||||
child: Container(
|
||||
width: boxLength,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
final double width = context.isCompactWindow ? 90 : 110;
|
||||
return ADPopupMenu<SupportedUriSchemes>(
|
||||
value: value?.name,
|
||||
values: SupportedUriSchemes.values.map((e) => (e, e.name)),
|
||||
width: width,
|
||||
tooltip: "Select Default URI Scheme",
|
||||
onChanged: onChanged,
|
||||
isOutlined: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user