Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Migrate text input dialogs to bottom sheets

ashilkn16233a09b66e
diff --git a/mobile/apps/photos/lib/ui/components/dialog_widget.dart b/mobile/apps/photos/lib/ui/components/dialog_widget.dart
index 2e57ddbeaa..858024742a 100644
--- a/mobile/apps/photos/lib/ui/components/dialog_widget.dart
+++ b/mobile/apps/photos/lib/ui/components/dialog_widget.dart
@@ -1,19 +1,14 @@
-import 'dart:math';
+import 'dart:async';
import "package:ente_components/ente_components.dart";
import 'package:flutter/material.dart';
import "package:flutter/services.dart";
-import 'package:photos/core/constants.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/models/button_result.dart';
import 'package:photos/models/typedefs.dart';
import 'package:photos/theme/colors.dart';
-import 'package:photos/theme/effects.dart';
-import 'package:photos/theme/ente_theme.dart';
import "package:photos/ui/components/buttons/button_component_adapter.dart";
import 'package:photos/ui/components/buttons/button_widget.dart';
-import 'package:photos/ui/components/models/button_type.dart';
-import 'package:photos/ui/components/text_input_widget.dart';
///Will return null if dismissed by tapping outside
Future<ButtonResult?> showDialogWidget({
@@ -98,37 +93,6 @@ class _DialogBody extends StatelessWidget {
}
}
-class _ContentContainer extends StatelessWidget {
- final String title;
- final String? body;
- final IconData? icon;
- const _ContentContainer({required this.title, this.body, this.icon});
-
- @override
- Widget build(BuildContext context) {
- final textTheme = getEnteTextTheme(context);
- final colorScheme = getEnteColorScheme(context);
- return Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- icon == null
- ? const SizedBox.shrink()
- : Row(children: [Icon(icon, size: 32)]),
- icon == null ? const SizedBox.shrink() : const SizedBox(height: 19),
- Text(title, style: textTheme.largeBold),
- body != null ? const SizedBox(height: 19) : const SizedBox.shrink(),
- body != null
- ? Text(
- body!,
- style: textTheme.body.copyWith(color: colorScheme.textMuted),
- )
- : const SizedBox.shrink(),
- ],
- );
- }
-}
-
class TextInputDialog extends StatefulWidget {
final String title;
final String? body;
@@ -179,12 +143,16 @@ class TextInputDialog extends StatefulWidget {
}
class _TextInputDialogState extends State<TextInputDialog> {
- //the value of this ValueNotifier has no significance
- final _submitNotifier = ValueNotifier(false);
- late final ValueNotifier<bool> _inputIsEmptyNotifier;
+ static const _loadingSurfaceDelay = Duration(milliseconds: 300);
+ static const _successDisplayDuration = Duration(seconds: 1);
+
late final TextEditingController _textEditingController;
late final bool _ownsTextEditingController;
late final VoidCallback _textEditingControllerListener;
+ Timer? _inputErrorResetTimer;
+ var _hasInput = false;
+ var _hasInputError = false;
+ var _isSubmitting = false;
@override
void initState() {
@@ -192,12 +160,21 @@ class _TextInputDialogState extends State<TextInputDialog> {
_ownsTextEditingController = widget.textEditingController == null;
_textEditingController =
widget.textEditingController ?? TextEditingController();
- _inputIsEmptyNotifier = widget.initialValue?.isEmpty ?? true
- ? ValueNotifier(true)
- : ValueNotifier(false);
+ if (widget.initialValue != null) {
+ final initialText = _formatInitialValue(widget.initialValue!);
+ _textEditingController.value = TextEditingValue(
+ text: initialText,
+ selection: TextSelection.collapsed(offset: initialText.length),
+ );
+ }
+ _hasInput = _textEditingController.text.isNotEmpty;
_textEditingControllerListener = () {
- if (_textEditingController.text.isEmpty != _inputIsEmptyNotifier.value) {
- _inputIsEmptyNotifier.value = _textEditingController.text.isEmpty;
+ final hasInput = _textEditingController.text.isNotEmpty;
+ if (hasInput != _hasInput || _hasInputError) {
+ setState(() {
+ _hasInput = hasInput;
+ _hasInputError = false;
+ });
}
};
_textEditingController.addListener(_textEditingControllerListener);
@@ -205,97 +182,190 @@ class _TextInputDialogState extends State<TextInputDialog> {
@override
void dispose() {
+ _inputErrorResetTimer?.cancel();
_textEditingController.removeListener(_textEditingControllerListener);
if (_ownsTextEditingController) {
_textEditingController.dispose();
}
- _submitNotifier.dispose();
- _inputIsEmptyNotifier.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
- final widthOfScreen = MediaQuery.sizeOf(context).width;
- final isMobileSmall = widthOfScreen <= mobileSmallThreshold;
- final colorScheme = getEnteColorScheme(context);
- return Container(
- width: min(widthOfScreen, 320),
- padding: isMobileSmall
- ? const EdgeInsets.all(0)
- : const EdgeInsets.fromLTRB(6, 8, 6, 6),
- decoration: BoxDecoration(
- color: colorScheme.backgroundElevated,
- boxShadow: shadowFloatLight,
- borderRadius: const BorderRadius.all(Radius.circular(8)),
- ),
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- _ContentContainer(
- title: widget.title,
- body: widget.body,
- icon: widget.icon,
- ),
- Padding(
- padding: const EdgeInsets.only(top: 19),
- child: TextInputWidget(
- label: widget.label,
- message: widget.message,
- hintText: widget.hintText,
- prefixIcon: widget.prefixIcon,
- initialValue: widget.initialValue,
- alignMessage: widget.alignMessage,
- autoFocus: true,
- maxLength: widget.maxLength,
- submitNotifier: _submitNotifier,
- onSubmit: widget.onSubmit,
- popNavAfterSubmission: widget.popnavAfterSubmission,
- showOnlyLoadingState: widget.showOnlyLoadingState,
- textCapitalization: widget.textCapitalization,
- alwaysShowSuccessState: widget.alwaysShowSuccessState,
- isPasswordInput: widget.isPasswordInput,
- textEditingController: _textEditingController,
- textInputFormatter: widget.textInputFormatter,
- keyboardType: widget.textInputType,
- ),
- ),
- const SizedBox(height: 36),
- Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Expanded(
- child: ButtonWidget(
- buttonType: ButtonType.secondary,
- buttonSize: ButtonSize.small,
- labelText: AppLocalizations.of(context).cancel,
- isInAlert: true,
- ),
- ),
- const SizedBox(width: 8),
- Expanded(
- child: ValueListenableBuilder(
- valueListenable: _inputIsEmptyNotifier,
- builder: (context, bool value, _) {
- return ButtonWidget(
- buttonSize: ButtonSize.small,
- buttonType: ButtonType.neutral,
- labelText: widget.submitButtonLabel,
- isDisabled: value,
- onTap: () async {
- _submitNotifier.value = !_submitNotifier.value;
- },
- );
- },
- ),
- ),
- ],
- ),
- ],
+ final colors = context.componentColors;
+ return BottomSheetComponent(
+ title: widget.title,
+ illustration: widget.icon == null
+ ? null
+ : Icon(widget.icon, size: 48, color: colors.iconColor),
+ content: _TextInputDialogContent(
+ body: widget.body,
+ input: TextInputComponent(
+ controller: _textEditingController,
+ label: widget.label,
+ message: widget.alignMessage == null ? widget.message : null,
+ messageType: _hasInputError
+ ? TextInputComponentMessageType.error
+ : TextInputComponentMessageType.helper,
+ hintText: widget.hintText,
+ autofocus: true,
+ maxLength: widget.maxLength,
+ onSubmit: (_) => _submit(),
+ textCapitalization:
+ widget.textCapitalization ?? TextCapitalization.none,
+ isPasswordInput: widget.isPasswordInput,
+ isClearable: !widget.isPasswordInput,
+ inputFormatters: widget.textInputFormatter,
+ keyboardType: widget.textInputType,
+ prefix: widget.prefixIcon == null
+ ? null
+ : Icon(widget.prefixIcon, size: IconSizes.small),
),
+ alignedMessage: widget.alignMessage == null ? null : widget.message,
+ alignedMessageAlignment: widget.alignMessage,
),
+ actions: [
+ ButtonComponent(
+ label: AppLocalizations.of(context).cancel,
+ variant: ButtonComponentVariant.secondary,
+ shouldSurfaceExecutionStates: false,
+ onTap: () => Navigator.of(context).pop(ButtonResult()),
+ ),
+ ButtonComponent(
+ label: widget.submitButtonLabel,
+ isDisabled: !_hasInput,
+ shouldShowSuccessState: !widget.showOnlyLoadingState,
+ shouldShowSuccessConfirmation:
+ !widget.showOnlyLoadingState && widget.alwaysShowSuccessState,
+ onTap: _hasInput ? () => _submit(throwOnError: true) : null,
+ ),
+ ],
+ isKeyboardAware: true,
+ showCloseButton: false,
+ );
+ }
+
+ Future<void> _submit({bool throwOnError = false}) async {
+ if (_isSubmitting || !_hasInput) {
+ return;
+ }
+
+ _isSubmitting = true;
+ final stopwatch = Stopwatch()..start();
+ try {
+ await widget.onSubmit(_textEditingController.text);
+ } catch (error) {
+ final exception = error is Exception
+ ? error
+ : Exception(error.toString());
+ _isSubmitting = false;
+ if (error.toString().contains("Incorrect password") && mounted) {
+ _surfaceInputError();
+ }
+ if (widget.popnavAfterSubmission && mounted) {
+ Navigator.of(context).pop(exception);
+ }
+ if (throwOnError) {
+ throw exception;
+ }
+ return;
+ } finally {
+ stopwatch.stop();
+ }
+
+ if (!mounted) {
+ _isSubmitting = false;
+ return;
+ }
+ if (!widget.popnavAfterSubmission) {
+ _isSubmitting = false;
+ return;
+ }
+
+ unawaited(
+ Future<void>.delayed(_popDelay(stopwatch.elapsed), () {
+ if (mounted) {
+ Navigator.of(context).pop();
+ }
+ }),
+ );
+ }
+
+ Duration _popDelay(Duration elapsed) {
+ if (widget.showOnlyLoadingState) {
+ return Duration.zero;
+ }
+ if (widget.alwaysShowSuccessState || elapsed >= _loadingSurfaceDelay) {
+ return _successDisplayDuration;
+ }
+ return Duration.zero;
+ }
+
+ void _surfaceInputError() {
+ HapticFeedback.vibrate();
+ setState(() => _hasInputError = true);
+ _inputErrorResetTimer?.cancel();
+ _inputErrorResetTimer = Timer(const Duration(seconds: 1), () {
+ if (mounted) {
+ setState(() => _hasInputError = false);
+ }
+ });
+ }
+
+ String _formatInitialValue(String initialValue) {
+ var formattedValue = initialValue;
+ final formatters = widget.textInputFormatter;
+ if (formatters == null) {
+ return formattedValue;
+ }
+ for (final formatter in formatters) {
+ formattedValue = formatter
+ .formatEditUpdate(
+ TextEditingValue.empty,
+ TextEditingValue(text: formattedValue),
+ )
+ .text;
+ }
+ return formattedValue;
+ }
+}
+
+class _TextInputDialogContent extends StatelessWidget {
+ const _TextInputDialogContent({
+ required this.input,
+ this.body,
+ this.alignedMessage,
+ this.alignedMessageAlignment,
+ });
+
+ final Widget input;
+ final String? body;
+ final String? alignedMessage;
+ final Alignment? alignedMessageAlignment;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (body != null) ...[
+ Text(body!, style: TextStyles.body.copyWith(color: colors.textLight)),
+ const SizedBox(height: Spacing.lg),
+ ],
+ input,
+ if (alignedMessage != null) ...[
+ const SizedBox(height: Spacing.sm),
+ Align(
+ alignment: alignedMessageAlignment ?? Alignment.centerLeft,
+ child: Text(
+ alignedMessage!,
+ style: TextStyles.mini.copyWith(color: colors.textLight),
+ ),
+ ),
+ ],
+ ],
);
}
}
diff --git a/mobile/apps/photos/lib/utils/dialog_util.dart b/mobile/apps/photos/lib/utils/dialog_util.dart
index cccc372019..09710cc150 100644
--- a/mobile/apps/photos/lib/utils/dialog_util.dart
+++ b/mobile/apps/photos/lib/utils/dialog_util.dart
@@ -1,4 +1,5 @@
import "package:dio/dio.dart";
+import "package:ente_components/ente_components.dart";
import "package:flutter/foundation.dart";
import 'package:flutter/material.dart';
import "package:flutter/services.dart";
@@ -342,7 +343,7 @@ ProgressDialog createProgressDialog(
return dialog;
}
-///Can return ButtonResult? from ButtonWidget or Exception? from TextInputDialog
+/// Returns null on successful submit, ButtonResult on cancel, and Exception on submit failure.
Future<dynamic> showTextInputDialog(
BuildContext context, {
required String title,
@@ -367,39 +368,32 @@ Future<dynamic> showTextInputDialog(
bool useRootNavigator = false,
bool popnavAfterSubmission = true,
}) {
- return showDialog(
+ return showBottomSheetComponent<dynamic>(
barrierColor: backdropFaintDark,
context: context,
useRootNavigator: useRootNavigator,
- builder: (context) {
- final bottomInset = MediaQuery.of(context).viewInsets.bottom;
- final isKeyboardUp = bottomInset > 100;
- return Center(
- child: Padding(
- padding: EdgeInsets.only(bottom: isKeyboardUp ? bottomInset : 0),
- child: TextInputDialog(
- title: title,
- message: message,
- label: label,
- body: body,
- icon: icon,
- submitButtonLabel: submitButtonLabel,
- onSubmit: onSubmit,
- hintText: hintText,
- prefixIcon: prefixIcon,
- initialValue: initialValue,
- alignMessage: alignMessage,
- maxLength: maxLength,
- showOnlyLoadingState: showOnlyLoadingState,
- textCapitalization: textCapitalization,
- alwaysShowSuccessState: alwaysShowSuccessState,
- isPasswordInput: isPasswordInput,
- textEditingController: textEditingController,
- textInputFormatter: textInputFormatter,
- textInputType: textInputType,
- popnavAfterSubmission: popnavAfterSubmission,
- ),
- ),
+ builder: (_) {
+ return TextInputDialog(
+ title: title,
+ message: message,
+ label: label,
+ body: body,
+ icon: icon,
+ submitButtonLabel: submitButtonLabel,
+ onSubmit: onSubmit,
+ hintText: hintText,
+ prefixIcon: prefixIcon,
+ initialValue: initialValue,
+ alignMessage: alignMessage,
+ maxLength: maxLength,
+ showOnlyLoadingState: showOnlyLoadingState,
+ textCapitalization: textCapitalization,
+ alwaysShowSuccessState: alwaysShowSuccessState,
+ isPasswordInput: isPasswordInput,
+ textEditingController: textEditingController,
+ textInputFormatter: textInputFormatter,
+ textInputType: textInputType,
+ popnavAfterSubmission: popnavAfterSubmission,
);
},
);
diff --git a/mobile/apps/photos/test/ui/components/dialog_widget_test.dart b/mobile/apps/photos/test/ui/components/dialog_widget_test.dart
index 88d41d1314..e52331981c 100644
--- a/mobile/apps/photos/test/ui/components/dialog_widget_test.dart
+++ b/mobile/apps/photos/test/ui/components/dialog_widget_test.dart
@@ -1,11 +1,14 @@
import "package:ente_components/ente_components.dart";
import "package:flutter/material.dart";
+import "package:flutter/services.dart";
import "package:flutter_test/flutter_test.dart";
import "package:photos/ente_theme_data.dart";
+import "package:photos/generated/l10n.dart";
import "package:photos/models/button_result.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/dialog_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
+import "package:photos/ui/components/text_input_widget.dart";
import "package:photos/utils/dialog_util.dart";
void main() {
@@ -203,6 +206,258 @@ void main() {
expect(result?.action, ButtonAction.cancel);
expect(find.byType(BottomSheetComponent), findsNothing);
});
+
+ group("showTextInputDialog", () {
+ testWidgets("renders the migrated text input sheet", (tester) async {
+ await _pumpLauncher(
+ tester,
+ (context) => showTextInputDialog(
+ context,
+ title: "Rename file",
+ body: "Choose a short name.",
+ submitButtonLabel: "Rename",
+ icon: Icons.edit_outlined,
+ label: "Name",
+ hintText: "Enter file name",
+ prefixIcon: Icons.drive_file_rename_outline,
+ initialValue: "IMG_001",
+ message: ".JPG",
+ alignMessage: Alignment.centerRight,
+ onSubmit: (_) async {},
+ ),
+ );
+
+ await _openLauncher(tester);
+
+ expect(find.byType(BottomSheetComponent), findsOneWidget);
+ expect(find.byType(TextInputComponent), findsOneWidget);
+ expect(find.byType(ButtonComponent), findsNWidgets(2));
+ expect(find.byType(TextInputWidget), findsNothing);
+ expect(find.byType(Dialog), findsNothing);
+ expect(find.text("Rename file"), findsOneWidget);
+ expect(find.text("Choose a short name."), findsOneWidget);
+ expect(find.text("Name"), findsOneWidget);
+ expect(find.text(".JPG"), findsOneWidget);
+ expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
+ expect(find.byIcon(Icons.drive_file_rename_outline), findsOneWidget);
+
+ final input = tester.widget<TextField>(find.byType(TextField));
+ expect(input.controller?.text, "IMG_001");
+ });
+
+ testWidgets("submits entered text and closes with a null result", (
+ tester,
+ ) async {
+ dynamic result;
+ var submitted = "";
+
+ await _pumpLauncher(tester, (context) async {
+ result = await showTextInputDialog(
+ context,
+ title: "New album",
+ submitButtonLabel: "Create",
+ hintText: "Enter album name",
+ onSubmit: (value) async {
+ submitted = value;
+ },
+ );
+ });
+
+ await _openLauncher(tester);
+
+ var submitButton = tester.widget<ButtonComponent>(
+ find.widgetWithText(ButtonComponent, "Create"),
+ );
+ expect(submitButton.isDisabled, isTrue);
+
+ await tester.enterText(find.byType(TextField), "Road trip");
+ await tester.pump();
+
+ submitButton = tester.widget<ButtonComponent>(
+ find.widgetWithText(ButtonComponent, "Create"),
+ );
+ expect(submitButton.isDisabled, isFalse);
+
+ await tester.tap(find.text("Create"));
+ await tester.pumpAndSettle();
+
+ expect(submitted, "Road trip");
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ });
+
+ testWidgets("submits from the keyboard action", (tester) async {
+ dynamic result;
+ var submitted = "";
+
+ await _pumpLauncher(tester, (context) async {
+ result = await showTextInputDialog(
+ context,
+ title: "New album",
+ submitButtonLabel: "Create",
+ onSubmit: (value) async {
+ submitted = value;
+ },
+ );
+ });
+
+ await _openLauncher(tester);
+ await tester.enterText(find.byType(TextField), "Keyboard album");
+ await tester.testTextInput.receiveAction(TextInputAction.done);
+ await tester.pumpAndSettle();
+
+ expect(submitted, "Keyboard album");
+ expect(result, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ });
+
+ testWidgets("returns a ButtonResult when cancelled", (tester) async {
+ dynamic result;
+
+ await _pumpLauncher(tester, (context) async {
+ result = await showTextInputDialog(
+ context,
+ title: "Rename album",
+ submitButtonLabel: "Rename",
+ initialValue: "Archive",
+ onSubmit: (_) async {},
+ );
+ });
+
+ await _openLauncher(tester);
+ await tester.tap(find.text("Cancel"));
+ await tester.pumpAndSettle();
+
+ expect(result, isA<ButtonResult>());
+ expect((result as ButtonResult).action, isNull);
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ });
+
+ testWidgets("returns an exception when submit fails", (tester) async {
+ dynamic result;
+
+ await _pumpLauncher(tester, (context) async {
+ result = await showTextInputDialog(
+ context,
+ title: "Rename album",
+ submitButtonLabel: "Rename",
+ initialValue: "Archive",
+ onSubmit: (_) async {
+ throw StateError("boom");
+ },
+ );
+ });
+
+ await _openLauncher(tester);
+ await tester.tap(find.text("Rename"));
+ await tester.pumpAndSettle();
+
+ expect(result, isA<Exception>());
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ });
+
+ testWidgets("keeps incorrect password errors in the sheet", (tester) async {
+ await _pumpLauncher(
+ tester,
+ (context) => showTextInputDialog(
+ context,
+ title: "Enter password",
+ submitButtonLabel: "Unlock",
+ initialValue: "bad-password",
+ isPasswordInput: true,
+ popnavAfterSubmission: false,
+ onSubmit: (_) async {
+ throw Exception("Incorrect password");
+ },
+ ),
+ );
+
+ await _openLauncher(tester);
+ await tester.tap(find.text("Unlock"));
+ await tester.pump();
+
+ expect(find.byType(BottomSheetComponent), findsOneWidget);
+ final input = tester.widget<TextInputComponent>(
+ find.byType(TextInputComponent),
+ );
+ expect(input.messageType, TextInputComponentMessageType.error);
+ });
+
+ testWidgets(
+ "allows manual navigation when popnavAfterSubmission is false",
+ (tester) async {
+ dynamic result;
+
+ await _pumpLauncher(tester, (context) async {
+ result = await showTextInputDialog(
+ context,
+ title: "Collect photos",
+ submitButtonLabel: "Create",
+ initialValue: "May 25",
+ popnavAfterSubmission: false,
+ onSubmit: (value) async {
+ Navigator.of(context).pop("created:$value");
+ },
+ );
+ });
+
+ await _openLauncher(tester);
+ await tester.tap(find.text("Create"));
+ await tester.pumpAndSettle();
+
+ expect(result, "created:May 25");
+ expect(find.byType(BottomSheetComponent), findsNothing);
+ },
+ );
+
+ testWidgets("preserves password mode and input formatters", (tester) async {
+ await _pumpLauncher(
+ tester,
+ (context) => showTextInputDialog(
+ context,
+ title: "Pair with TV",
+ submitButtonLabel: "Pair",
+ initialValue: "a1b2",
+ isPasswordInput: true,
+ textInputFormatter: [FilteringTextInputFormatter.digitsOnly],
+ onSubmit: (_) async {},
+ ),
+ );
+
+ await _openLauncher(tester);
+
+ final input = tester.widget<TextField>(find.byType(TextField));
+ expect(input.obscureText, isTrue);
+ expect(input.controller?.text, "12");
+ expect(
+ find.byKey(const ValueKey("text-field-password-toggle")),
+ findsOneWidget,
+ );
+ });
+
+ testWidgets("showOnlyLoadingState suppresses button success state", (
+ tester,
+ ) async {
+ await _pumpLauncher(
+ tester,
+ (context) => showTextInputDialog(
+ context,
+ title: "New album",
+ submitButtonLabel: "Create",
+ initialValue: "Album",
+ showOnlyLoadingState: true,
+ onSubmit: (_) async {},
+ ),
+ );
+
+ await _openLauncher(tester);
+
+ final button = tester.widget<ButtonComponent>(
+ find.widgetWithText(ButtonComponent, "Create"),
+ );
+ expect(button.shouldShowSuccessState, isFalse);
+ });
+ });
}
Future<void> _pumpLauncher(
@@ -212,6 +467,8 @@ Future<void> _pumpLauncher(
await tester.pumpWidget(
MaterialApp(
theme: darkThemeData,
+ localizationsDelegates: AppLocalizations.localizationsDelegates,
+ supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: Builder(
builder: (context) {
diff --git a/mobile/apps/photos/test/utils/delete_file_util_test.dart b/mobile/apps/photos/test/utils/delete_file_util_test.dart
index 0ea3ebaad2..78e5afc6ea 100644
--- a/mobile/apps/photos/test/utils/delete_file_util_test.dart
+++ b/mobile/apps/photos/test/utils/delete_file_util_test.dart
@@ -22,6 +22,7 @@ void main() {
prefs,
Dio(),
Dio(),
+ Dio(),
PackageInfo(
appName: 'Photos',
packageName: 'photos',
diff --git a/mobile/packages/ente_components/lib/components/buttons/button_component.dart b/mobile/packages/ente_components/lib/components/buttons/button_component.dart
index 2770157e4c..779daeaf80 100644
--- a/mobile/packages/ente_components/lib/components/buttons/button_component.dart
+++ b/mobile/packages/ente_components/lib/components/buttons/button_component.dart
@@ -36,6 +36,7 @@ class ButtonComponent extends StatefulWidget {
this.size = ButtonComponentSize.large,
this.isDisabled = false,
this.shouldSurfaceExecutionStates = true,
+ this.shouldShowSuccessState = true,
this.shouldShowSuccessConfirmation = false,
this.progressStatus,
this.leading,
@@ -47,6 +48,7 @@ class ButtonComponent extends StatefulWidget {
final ButtonComponentSize size;
final bool isDisabled;
final bool shouldSurfaceExecutionStates;
+ final bool shouldShowSuccessState;
final bool shouldShowSuccessConfirmation;
final ValueListenable<String>? progressStatus;
final Widget? leading;
@@ -387,7 +389,10 @@ class _ButtonComponentState extends State<ButtonComponent>
bool get _showLoading =>
widget.shouldSurfaceExecutionStates && _isExecuting && _loadingVisible;
- bool get _showSuccess => widget.shouldSurfaceExecutionStates && _isSuccessful;
+ bool get _showSuccess =>
+ widget.shouldSurfaceExecutionStates &&
+ widget.shouldShowSuccessState &&
+ _isSuccessful;
Future<void> _handleTap() async {
final callback = widget.onTap;
@@ -420,6 +425,7 @@ class _ButtonComponentState extends State<ButtonComponent>
final shouldShowSuccess =
widget.shouldSurfaceExecutionStates &&
+ widget.shouldShowSuccessState &&
(loadingSurfaced ||
(loadingPending && widget.shouldShowSuccessConfirmation));
diff --git a/mobile/packages/ente_components/test/components/button_test.dart b/mobile/packages/ente_components/test/components/button_test.dart
index 8c46f8447e..908c0084ec 100644
--- a/mobile/packages/ente_components/test/components/button_test.dart
+++ b/mobile/packages/ente_components/test/components/button_test.dart
@@ -199,6 +199,34 @@ void main() {
},
);
+ testWidgets("ButtonComponent can surface loading without success", (
+ tester,
+ ) async {
+ final completer = Completer<void>();
+
+ await tester.pumpWidget(
+ _wrap(
+ ButtonComponent(
+ label: "Saving",
+ shouldShowSuccessState: false,
+ onTap: () => completer.future,
+ ),
+ ),
+ );
+
+ await tester.tap(find.text("Saving"));
+ await tester.pump(const Duration(milliseconds: 300));
+
+ expect(find.byKey(const ValueKey('loading')), findsOneWidget);
+
+ completer.complete();
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 200));
+
+ expect(find.byKey(const ValueKey('success')), findsNothing);
+ expect(find.text("Saving"), findsOneWidget);
+ });
+
testWidgets(
"ButtonComponent can hide execution visuals while still blocking taps",
(tester) async {