diff --git a/lib/ui/viewer/actions/picker_widget.dart b/lib/ui/viewer/actions/picker_widget.dart index 5dd72c945..ef3da5f6f 100644 --- a/lib/ui/viewer/actions/picker_widget.dart +++ b/lib/ui/viewer/actions/picker_widget.dart @@ -72,11 +72,13 @@ class ItemsWidget extends StatefulWidget { class _ItemsWidgetState extends State { late int currentDeviceLimit; + late int initialDeviceLimit; List items = []; bool isCustomLimit = false; @override void initState() { currentDeviceLimit = widget.collection.publicURLs!.first!.deviceLimit; + initialDeviceLimit = currentDeviceLimit; if (!deviceLimits.contains(currentDeviceLimit)) { isCustomLimit = true; } @@ -88,43 +90,12 @@ class _ItemsWidgetState extends State { items.clear(); if (isCustomLimit) { items.add( - MenuItemWidget( - key: ValueKey(currentDeviceLimit), - menuItemColor: getEnteColorScheme(context).fillFaint, - captionedTextWidget: CaptionedTextWidget( - title: "$currentDeviceLimit", - ), - trailingIcon: Icons.check, - alignCaptionedTextToLeft: true, - isTopBorderRadiusRemoved: true, - isBottomBorderRadiusRemoved: true, - ), + _menuItemForPicker(initialDeviceLimit), ); - isCustomLimit = false; } for (int deviceLimit in deviceLimits) { items.add( - MenuItemWidget( - key: ValueKey(deviceLimit), - menuItemColor: getEnteColorScheme(context).fillFaint, - captionedTextWidget: CaptionedTextWidget( - title: "$deviceLimit", - ), - trailingIcon: currentDeviceLimit == deviceLimit ? Icons.check : null, - alignCaptionedTextToLeft: true, - isTopBorderRadiusRemoved: true, - isBottomBorderRadiusRemoved: true, - showOnlyLoadingState: true, - onTap: () async { - await _updateUrlSettings(context, { - 'deviceLimit': deviceLimit, - }).then( - (value) => setState(() { - currentDeviceLimit = deviceLimit; - }), - ); - }, - ), + _menuItemForPicker(deviceLimit), ); } items = addSeparators( @@ -140,6 +111,30 @@ class _ItemsWidgetState extends State { ); } + Widget _menuItemForPicker(int deviceLimit) { + return MenuItemWidget( + key: ValueKey(deviceLimit), + menuItemColor: getEnteColorScheme(context).fillFaint, + captionedTextWidget: CaptionedTextWidget( + title: "$deviceLimit", + ), + trailingIcon: currentDeviceLimit == deviceLimit ? Icons.check : null, + alignCaptionedTextToLeft: true, + isTopBorderRadiusRemoved: true, + isBottomBorderRadiusRemoved: true, + showOnlyLoadingState: true, + onTap: () async { + await _updateUrlSettings(context, { + 'deviceLimit': deviceLimit, + }).then( + (value) => setState(() { + currentDeviceLimit = deviceLimit; + }), + ); + }, + ); + } + Future _updateUrlSettings( BuildContext context, Map prop,