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/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash/providers/providers.dart'; import 'package:apidash/providers/providers.dart';
import 'package:apidash/widgets/widgets.dart'; import 'package:apidash/widgets/widgets.dart';
import 'package:apidash/consts.dart';
class EnvironmentDropdown extends ConsumerWidget { class EnvironmentDropdown extends ConsumerWidget {
const EnvironmentDropdown({super.key}); const EnvironmentDropdown({super.key});
@ -11,28 +10,25 @@ class EnvironmentDropdown extends ConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final environments = ref.watch(environmentsStateNotifierProvider); final environments = ref.watch(environmentsStateNotifierProvider);
final environmentsList = environments?.values.toList(); final environmentSequence = ref.watch(environmentSequenceProvider);
environmentsList final environmentsList = environmentSequence
?.removeWhere((element) => element.id == kGlobalEnvironmentId); .map((e) => environments?[e])
.whereNotNull()
.toList();
final activeEnvironment = ref.watch(activeEnvironmentIdStateProvider); final activeEnvironment = ref.watch(activeEnvironmentIdStateProvider);
return Container( return EnvironmentPopupMenu(
decoration: BoxDecoration( value: environments?[activeEnvironment],
border: Border.all( options: environmentsList,
color: Theme.of(context).colorScheme.outlineVariant, onChanged: (value) {
), if (value != null) {
borderRadius: kBorderRadius8, ref.read(activeEnvironmentIdStateProvider.notifier).state = value.id;
), ref
child: EnvironmentPopupMenu( .read(settingsProvider.notifier)
value: environments?[activeEnvironment], .update(activeEnvironmentId: value.id);
items: environmentsList, ref.read(hasUnsavedChangesProvider.notifier).state = true;
onChanged: (value) { }
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/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:apidash_design_system/apidash_design_system.dart';
import '../providers/providers.dart'; import '../providers/providers.dart';
import '../services/services.dart'; import '../services/services.dart';
import '../utils/utils.dart'; import '../utils/utils.dart';
@ -67,43 +66,25 @@ class SettingsPage extends ConsumerWidget {
title: const Text('Default URI Scheme'), title: const Text('Default URI Scheme'),
subtitle: Text( subtitle: Text(
'$kDefaultUri${settings.defaultUriScheme}://$kDefaultUri'), '$kDefaultUri${settings.defaultUriScheme}://$kDefaultUri'),
trailing: Container( trailing: DefaultUriSchemePopupMenu(
decoration: BoxDecoration( value: settings.defaultUriScheme,
border: Border.all( onChanged: (value) {
color: Theme.of(context).colorScheme.onSurface, ref
), .read(settingsProvider.notifier)
borderRadius: kBorderRadius8, .update(defaultUriScheme: value);
), },
child: URIPopupMenu(
value: settings.defaultUriScheme,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultUriScheme: value);
},
items: kSupportedUriSchemes,
),
), ),
), ),
ListTile( ListTile(
hoverColor: kColorTransparent, hoverColor: kColorTransparent,
title: const Text('Default Code Generator'), title: const Text('Default Code Generator'),
trailing: Container( trailing: CodegenPopupMenu(
decoration: BoxDecoration( value: settings.defaultCodeGenLang,
border: Border.all( onChanged: (value) {
color: Theme.of(context).colorScheme.onSurface, ref
), .read(settingsProvider.notifier)
borderRadius: kBorderRadius8, .update(defaultCodeGenLang: value);
), },
child: CodegenPopupMenu(
value: settings.defaultCodeGenLang,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultCodeGenLang: value);
},
items: CodegenLanguage.values,
),
), ),
), ),
CheckboxListTile( CheckboxListTile(
@ -152,22 +133,13 @@ class SettingsPage extends ConsumerWidget {
title: const Text('History Retention Period'), title: const Text('History Retention Period'),
subtitle: Text( subtitle: Text(
'Your request history will be retained${settings.historyRetentionPeriod == HistoryRetentionPeriod.forever ? "" : " for"} ${settings.historyRetentionPeriod.label}'), 'Your request history will be retained${settings.historyRetentionPeriod == HistoryRetentionPeriod.forever ? "" : " for"} ${settings.historyRetentionPeriod.label}'),
trailing: Container( trailing: HistoryRetentionPopupMenu(
decoration: BoxDecoration( value: settings.historyRetentionPeriod,
border: Border.all( onChanged: (value) {
color: Theme.of(context).colorScheme.onSurface, ref
), .read(settingsProvider.notifier)
borderRadius: kBorderRadius8, .update(historyRetentionPeriod: value);
), },
child: HistoryRetentionPopupMenu(
value: settings.historyRetentionPeriod,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(historyRetentionPeriod: value);
},
items: HistoryRetentionPeriod.values,
),
), ),
), ),
ListTile( ListTile(

View File

@ -7,50 +7,21 @@ class CodegenPopupMenu extends StatelessWidget {
super.key, super.key,
required this.value, required this.value,
this.onChanged, this.onChanged,
this.items,
}); });
final CodegenLanguage value; final CodegenLanguage value;
final void Function(CodegenLanguage? value)? onChanged; final void Function(CodegenLanguage? value)? onChanged;
final List<CodegenLanguage>? items;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double boxLength = context.isCompactWindow ? 150 : 220; final double width = context.isCompactWindow ? 150 : 220;
return PopupMenuButton<CodegenLanguage>( return ADPopupMenu<CodegenLanguage>(
value: value.label,
values: CodegenLanguage.values.map((e) => (e, e.label)),
width: width,
tooltip: "Select Code Generation Language", tooltip: "Select Code Generation Language",
surfaceTintColor: kColorTransparent, onChanged: onChanged,
constraints: BoxConstraints(minWidth: boxLength), isOutlined: true,
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,
)
],
),
),
); );
} }
} }

View File

@ -3,70 +3,39 @@ import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:apidash/models/models.dart'; import 'package:apidash/models/models.dart';
import 'package:apidash/utils/utils.dart'; import 'package:apidash/utils/utils.dart';
import '../consts.dart';
class EnvironmentPopupMenu extends StatelessWidget { class EnvironmentPopupMenu extends StatelessWidget {
const EnvironmentPopupMenu({ const EnvironmentPopupMenu({
super.key, super.key,
this.value, this.value,
this.options,
this.onChanged, this.onChanged,
this.items,
}); });
final EnvironmentModel? value; final EnvironmentModel? value;
final void Function(EnvironmentModel? value)? onChanged; final void Function(EnvironmentModel? value)? onChanged;
final List<EnvironmentModel>? items; final List<EnvironmentModel>? options;
final EnvironmentModel? noneEnvironmentModel = null;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final valueName = getEnvironmentTitle(value?.name); final double width = context.isCompactWindow ? 100 : 130;
final double boxLength = context.isCompactWindow ? 100 : 130;
return PopupMenuButton( 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", tooltip: "Select Environment",
surfaceTintColor: kColorTransparent, onChanged: onChanged,
constraints: BoxConstraints(minWidth: boxLength), isOutlined: true,
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,
)
],
),
),
); );
} }
} }

View File

@ -5,57 +5,23 @@ import 'package:apidash/consts.dart';
class HistoryRetentionPopupMenu extends StatelessWidget { class HistoryRetentionPopupMenu extends StatelessWidget {
const HistoryRetentionPopupMenu({ const HistoryRetentionPopupMenu({
super.key, super.key,
required this.value, this.value,
required this.onChanged, this.onChanged,
this.items,
}); });
final HistoryRetentionPeriod value; final HistoryRetentionPeriod? value;
final void Function(HistoryRetentionPeriod value) onChanged; final void Function(HistoryRetentionPeriod? value)? onChanged;
final List<HistoryRetentionPeriod>? items;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const double boxLength = 120; const double width = 120;
return PopupMenuButton( return ADPopupMenu<HistoryRetentionPeriod>(
value: value?.label,
values: HistoryRetentionPeriod.values.map((e) => (e, e.label)),
width: width,
tooltip: "Select retention period", tooltip: "Select retention period",
surfaceTintColor: kColorTransparent, onChanged: onChanged,
constraints: const BoxConstraints(minWidth: boxLength), isOutlined: true,
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,
)
],
),
),
); );
} }
} }

View File

@ -1,55 +1,27 @@
import 'package:apidash_core/apidash_core.dart';
import 'package:apidash_design_system/apidash_design_system.dart'; import 'package:apidash_design_system/apidash_design_system.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class URIPopupMenu extends StatelessWidget { class DefaultUriSchemePopupMenu extends StatelessWidget {
const URIPopupMenu({ const DefaultUriSchemePopupMenu({
super.key, super.key,
required this.value, this.value,
this.onChanged, this.onChanged,
this.items,
}); });
final String value; final SupportedUriSchemes? value;
final void Function(String? value)? onChanged; final void Function(SupportedUriSchemes? value)? onChanged;
final List<String>? items;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double boxLength = context.isCompactWindow ? 90 : 110; final double width = context.isCompactWindow ? 90 : 110;
return PopupMenuButton( return ADPopupMenu<SupportedUriSchemes>(
tooltip: "Select URI Scheme", value: value?.name,
surfaceTintColor: kColorTransparent, values: SupportedUriSchemes.values.map((e) => (e, e.name)),
constraints: BoxConstraints(minWidth: boxLength), width: width,
itemBuilder: (BuildContext context) => items! tooltip: "Select Default URI Scheme",
.map((item) => PopupMenuItem( onChanged: onChanged,
value: item, isOutlined: true,
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,
)
],
),
),
); );
} }
} }