Update support for new popup menu

This commit is contained in:
Ashita Prasad
2024-12-15 07:39:28 +05:30
parent c24fddddd4
commit f186f5401b
6 changed files with 97 additions and 251 deletions

View File

@ -1,9 +1,8 @@
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:apidash_core/apidash_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/consts.dart';
class EnvironmentDropdown extends ConsumerWidget {
const EnvironmentDropdown({super.key});
@ -11,28 +10,25 @@ class EnvironmentDropdown extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final environments = ref.watch(environmentsStateNotifierProvider);
final environmentsList = environments?.values.toList();
environmentsList
?.removeWhere((element) => element.id == kGlobalEnvironmentId);
final environmentSequence = ref.watch(environmentSequenceProvider);
final environmentsList = environmentSequence
.map((e) => environments?[e])
.whereNotNull()
.toList();
final activeEnvironment = ref.watch(activeEnvironmentIdStateProvider);
return Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.outlineVariant,
),
borderRadius: kBorderRadius8,
),
child: EnvironmentPopupMenu(
value: environments?[activeEnvironment],
items: environmentsList,
onChanged: (value) {
ref.read(activeEnvironmentIdStateProvider.notifier).state =
value?.id;
ref
.read(settingsProvider.notifier)
.update(activeEnvironmentId: value?.id);
ref.read(hasUnsavedChangesProvider.notifier).state = true;
},
));
return EnvironmentPopupMenu(
value: environments?[activeEnvironment],
options: environmentsList,
onChanged: (value) {
if (value != null) {
ref.read(activeEnvironmentIdStateProvider.notifier).state = value.id;
ref
.read(settingsProvider.notifier)
.update(activeEnvironmentId: value.id);
ref.read(hasUnsavedChangesProvider.notifier).state = true;
}
},
);
}
}

View File

@ -1,7 +1,6 @@
import 'package:apidash_core/apidash_core.dart';
import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash_design_system/apidash_design_system.dart';
import '../providers/providers.dart';
import '../services/services.dart';
import '../utils/utils.dart';
@ -67,43 +66,25 @@ class SettingsPage extends ConsumerWidget {
title: const Text('Default URI Scheme'),
subtitle: Text(
'$kDefaultUri${settings.defaultUriScheme}://$kDefaultUri'),
trailing: Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.onSurface,
),
borderRadius: kBorderRadius8,
),
child: URIPopupMenu(
value: settings.defaultUriScheme,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultUriScheme: value);
},
items: kSupportedUriSchemes,
),
trailing: DefaultUriSchemePopupMenu(
value: settings.defaultUriScheme,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultUriScheme: value);
},
),
),
ListTile(
hoverColor: kColorTransparent,
title: const Text('Default Code Generator'),
trailing: Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.onSurface,
),
borderRadius: kBorderRadius8,
),
child: CodegenPopupMenu(
value: settings.defaultCodeGenLang,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultCodeGenLang: value);
},
items: CodegenLanguage.values,
),
trailing: CodegenPopupMenu(
value: settings.defaultCodeGenLang,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultCodeGenLang: value);
},
),
),
CheckboxListTile(
@ -152,22 +133,13 @@ class SettingsPage extends ConsumerWidget {
title: const Text('History Retention Period'),
subtitle: Text(
'Your request history will be retained${settings.historyRetentionPeriod == HistoryRetentionPeriod.forever ? "" : " for"} ${settings.historyRetentionPeriod.label}'),
trailing: Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.onSurface,
),
borderRadius: kBorderRadius8,
),
child: HistoryRetentionPopupMenu(
value: settings.historyRetentionPeriod,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(historyRetentionPeriod: value);
},
items: HistoryRetentionPeriod.values,
),
trailing: HistoryRetentionPopupMenu(
value: settings.historyRetentionPeriod,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(historyRetentionPeriod: value);
},
),
),
ListTile(

View File

@ -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,
);
}
}

View File

@ -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,
);
}
}

View File

@ -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,
);
}
}

View File

@ -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,
);
}
}