Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use shared button widget in Auth

Neeraj Guptab7a30cb7a281
diff --git a/mobile/apps/auth/lib/models/execution_states.dart b/mobile/apps/auth/lib/models/execution_states.dart
deleted file mode 100644
index 037b6f0f6a..0000000000
--- a/mobile/apps/auth/lib/models/execution_states.dart
+++ /dev/null
@@ -1 +0,0 @@
-enum ExecutionState { idle, inProgress, error, successful }
diff --git a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
index b645f71dfc..447fa620fd 100644
--- a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart
@@ -14,8 +14,6 @@ import 'package:ente_auth/locale.dart';
import 'package:ente_auth/theme/colors.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/account/logout_dialog.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_auth/ui/home/widgets/rounded_action_buttons.dart';
import 'package:ente_auth/ui/home_page.dart';
import 'package:ente_auth/ui/settings/developer_settings_widget.dart';
@@ -28,6 +26,8 @@ import 'package:ente_components/ente_components.dart';
import 'package:ente_events/event_bus.dart';
import 'package:ente_strings/ente_strings.dart';
import 'package:ente_ui/components/alert_bottom_sheet.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_svg/flutter_svg.dart';
diff --git a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
index 1ba45b6031..13f814d29f 100644
--- a/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
+++ b/mobile/apps/auth/lib/onboarding/view/setup_enter_secret_key_page.dart
@@ -5,9 +5,7 @@ import 'package:ente_auth/models/all_icon_data.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/models/code_display.dart';
import 'package:ente_auth/store/code_display_store.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/custom_icon_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_auth/ui/custom_icon_page.dart';
import 'package:ente_auth/ui/settings/components/auth_settings_page_scaffold.dart';
import 'package:ente_auth/ui/utils/icon_utils.dart';
@@ -17,6 +15,8 @@ import 'package:ente_auth/utils/totp_util.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_events/event_bus.dart';
import "package:ente_strings/ente_strings.dart";
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
import "package:flutter/material.dart";
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/lib/ui/components/action_sheet_widget.dart b/mobile/apps/auth/lib/ui/components/action_sheet_widget.dart
index 73517b0721..4826b292e6 100644
--- a/mobile/apps/auth/lib/ui/components/action_sheet_widget.dart
+++ b/mobile/apps/auth/lib/ui/components/action_sheet_widget.dart
@@ -1,10 +1,10 @@
import 'dart:io';
import 'package:ente_auth/ui/components/buttons/button_component_adapter.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
diff --git a/mobile/apps/auth/lib/ui/components/buttons/button_component_adapter.dart b/mobile/apps/auth/lib/ui/components/buttons/button_component_adapter.dart
index 7bbb400319..335718f00f 100644
--- a/mobile/apps/auth/lib/ui/components/buttons/button_component_adapter.dart
+++ b/mobile/apps/auth/lib/ui/components/buttons/button_component_adapter.dart
@@ -1,10 +1,10 @@
import 'dart:async';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
diff --git a/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart b/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart
deleted file mode 100644
index 1deba4b8de..0000000000
--- a/mobile/apps/auth/lib/ui/components/buttons/button_widget.dart
+++ /dev/null
@@ -1,563 +0,0 @@
-import 'package:ente_auth/models/execution_states.dart';
-import 'package:ente_auth/theme/colors.dart';
-import 'package:ente_auth/theme/ente_theme.dart';
-import 'package:ente_auth/theme/text_style.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
-import 'package:ente_auth/ui/components/models/custom_button_style.dart';
-import 'package:ente_auth/utils/debouncer.dart';
-import "package:ente_auth/utils/dialog_util.dart";
-import 'package:ente_base/typedefs.dart';
-import 'package:ente_ui/components/loading_widget.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/scheduler.dart';
-
-enum ButtonSize { small, large }
-
-enum ButtonAction { first, second, third, fourth, cancel, error }
-
-class ButtonWidget extends StatelessWidget {
- final IconData? icon;
- final String? labelText;
- final ButtonType buttonType;
- final FutureVoidCallback? onTap;
- final bool isDisabled;
- final ButtonSize buttonSize;
-
- ///Setting this flag to true will show a success confirmation as a 'check'
- ///icon once the onTap(). This is expected to be used only if time taken to
- ///execute onTap() takes less than debouce time.
- final bool shouldShowSuccessConfirmation;
-
- ///Setting this flag to false will restrict the loading and success states of
- ///the button from surfacing on the UI. The ExecutionState of the button will
- ///change irrespective of the value of this flag. Only that it won't be
- ///surfaced on the UI
- final bool shouldSurfaceExecutionStates;
-
- /// iconColor should only be specified when we do not want to honor the default
- /// iconColor based on buttonType. Most of the items, default iconColor is what
- /// we need unless we want to pop out the icon in a non-primary button type
- final Color? iconColor;
-
- ///Button action will only work if isInAlert is true
- final ButtonAction? buttonAction;
-
- ///setting this flag to true will make the button appear like how it would
- ///on dark theme irrespective of the app's theme.
- final bool shouldStickToDarkTheme;
-
- ///isInAlert is to dismiss the alert if the action on the button is completed.
- ///This should be set to true if the alert which uses this button needs to
- ///return the Button's action.
- final bool isInAlert;
-
- /// progressStatus can be used to display information about the action
- /// progress when ExecutionState is in Progress.
- final ValueNotifier<String>? progressStatus;
-
- const ButtonWidget({
- super.key,
- required this.buttonType,
- this.buttonSize = ButtonSize.large,
- this.icon,
- this.labelText,
- this.onTap,
- this.shouldStickToDarkTheme = false,
- this.isDisabled = false,
- this.buttonAction,
- this.isInAlert = false,
- this.iconColor,
- this.shouldSurfaceExecutionStates = true,
- this.progressStatus,
- this.shouldShowSuccessConfirmation = false,
- });
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = shouldStickToDarkTheme
- ? darkScheme
- : getEnteColorScheme(context);
- final inverseColorScheme = shouldStickToDarkTheme
- ? lightScheme
- : getEnteColorScheme(context, inverse: true);
- final textTheme = shouldStickToDarkTheme
- ? darkTextTheme
- : getEnteTextTheme(context);
- final inverseTextTheme = shouldStickToDarkTheme
- ? lightTextTheme
- : getEnteTextTheme(context, inverse: true);
- final buttonStyle = CustomButtonStyle(
- //Dummy default values since we need to keep these properties non-nullable
- defaultButtonColor: Colors.transparent,
- defaultBorderColor: Colors.transparent,
- defaultIconColor: Colors.transparent,
- defaultLabelStyle: textTheme.body,
- );
- buttonStyle.defaultButtonColor = buttonType.defaultButtonColor(colorScheme);
- buttonStyle.pressedButtonColor = buttonType.pressedButtonColor(colorScheme);
- buttonStyle.disabledButtonColor = buttonType.disabledButtonColor(
- colorScheme,
- buttonSize,
- );
- buttonStyle.defaultBorderColor = buttonType.defaultBorderColor(
- colorScheme,
- buttonSize,
- );
- buttonStyle.pressedBorderColor = buttonType.pressedBorderColor(
- colorScheme: colorScheme,
- buttonSize: buttonSize,
- );
- buttonStyle.disabledBorderColor = buttonType.disabledBorderColor(
- colorScheme,
- buttonSize,
- );
- buttonStyle.defaultIconColor =
- iconColor ??
- buttonType.defaultIconColor(
- colorScheme: colorScheme,
- inverseColorScheme: inverseColorScheme,
- );
- buttonStyle.pressedIconColor = buttonType.pressedIconColor(
- colorScheme,
- buttonSize,
- );
- buttonStyle.disabledIconColor = buttonType.disabledIconColor(
- colorScheme,
- buttonSize,
- );
- buttonStyle.defaultLabelStyle = buttonType.defaultLabelStyle(
- textTheme: textTheme,
- inverseTextTheme: inverseTextTheme,
- );
- buttonStyle.pressedLabelStyle = buttonType.pressedLabelStyle(
- textTheme,
- colorScheme,
- buttonSize,
- );
- buttonStyle.disabledLabelStyle = buttonType.disabledLabelStyle(
- textTheme,
- colorScheme,
- );
- buttonStyle.checkIconColor = buttonType.checkIconColor(colorScheme);
-
- return ButtonChildWidget(
- buttonStyle: buttonStyle,
- buttonType: buttonType,
- isDisabled: isDisabled,
- buttonSize: buttonSize,
- isInAlert: isInAlert,
- onTap: onTap,
- labelText: labelText,
- icon: icon,
- buttonAction: buttonAction,
- shouldSurfaceExecutionStates: shouldSurfaceExecutionStates,
- progressStatus: progressStatus,
- shouldShowSuccessConfirmation: shouldShowSuccessConfirmation,
- );
- }
-}
-
-class ButtonChildWidget extends StatefulWidget {
- final CustomButtonStyle buttonStyle;
- final FutureVoidCallback? onTap;
- final ButtonType buttonType;
- final String? labelText;
- final IconData? icon;
- final bool isDisabled;
- final ButtonSize buttonSize;
- final ButtonAction? buttonAction;
- final bool isInAlert;
- final bool shouldSurfaceExecutionStates;
- final ValueNotifier<String>? progressStatus;
- final bool shouldShowSuccessConfirmation;
-
- const ButtonChildWidget({
- super.key,
- required this.buttonStyle,
- required this.buttonType,
- required this.isDisabled,
- required this.buttonSize,
- required this.isInAlert,
- required this.shouldSurfaceExecutionStates,
- required this.shouldShowSuccessConfirmation,
- this.progressStatus,
- this.onTap,
- this.labelText,
- this.icon,
- this.buttonAction,
- });
-
- @override
- State<ButtonChildWidget> createState() => _ButtonChildWidgetState();
-}
-
-class _ButtonChildWidgetState extends State<ButtonChildWidget> {
- late Color buttonColor;
- late Color borderColor;
- late Color iconColor;
- late TextStyle labelStyle;
- late Color checkIconColor;
- late Color loadingIconColor;
- ValueNotifier<String>? progressStatus;
-
- ///This is used to store the width of the button in idle state (small button)
- ///to be used as width for the button when the loading/succes states comes.
- double? widthOfButton;
- final _debouncer = Debouncer(const Duration(milliseconds: 300));
- ExecutionState executionState = ExecutionState.idle;
- Exception? _exception;
-
- @override
- void initState() {
- _setButtonTheme();
- super.initState();
- }
-
- @override
- void didUpdateWidget(covariant ButtonChildWidget oldWidget) {
- _setButtonTheme();
- super.didUpdateWidget(oldWidget);
- }
-
- @override
- Widget build(BuildContext context) {
- if (executionState == ExecutionState.successful) {
- Future.delayed(Duration(seconds: widget.isInAlert ? 1 : 2), () {
- setState(() {
- executionState = ExecutionState.idle;
- });
- });
- }
- return GestureDetector(
- onTap: _shouldRegisterGestures ? _onTap : null,
- onTapDown: _shouldRegisterGestures ? _onTapDown : null,
- onTapUp: _shouldRegisterGestures ? _onTapUp : null,
- onTapCancel: _shouldRegisterGestures ? _onTapCancel : null,
- child: Container(
- decoration: BoxDecoration(
- borderRadius: const BorderRadius.all(Radius.circular(4)),
- border: widget.buttonType == ButtonType.tertiaryCritical
- ? Border.all(color: borderColor)
- : null,
- ),
- child: AnimatedContainer(
- duration: const Duration(milliseconds: 16),
- width: widget.buttonSize == ButtonSize.large ? double.infinity : null,
- decoration: BoxDecoration(
- borderRadius: const BorderRadius.all(Radius.circular(4)),
- color: buttonColor,
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 16),
- child: AnimatedSwitcher(
- duration: const Duration(milliseconds: 175),
- switchInCurve: Curves.easeInOutExpo,
- switchOutCurve: Curves.easeInOutExpo,
- child:
- executionState == ExecutionState.idle ||
- !widget.shouldSurfaceExecutionStates
- ? widget.buttonType.hasTrailingIcon
- ? Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- widget.labelText == null
- ? const SizedBox.shrink()
- : Flexible(
- child: Padding(
- padding: widget.icon == null
- ? const EdgeInsets.symmetric(
- horizontal: 8,
- )
- : const EdgeInsets.only(right: 16),
- child: Text(
- widget.labelText!,
- overflow: TextOverflow.ellipsis,
- maxLines: 2,
- style: labelStyle,
- ),
- ),
- ),
- widget.icon == null
- ? const SizedBox.shrink()
- : Icon(
- widget.icon,
- size: 20,
- color: iconColor,
- ),
- ],
- )
- : Builder(
- builder: (context) {
- SchedulerBinding.instance.addPostFrameCallback((
- timeStamp,
- ) {
- final box =
- context.findRenderObject() as RenderBox;
- widthOfButton = box.size.width;
- });
- return Row(
- mainAxisSize:
- widget.buttonSize == ButtonSize.large
- ? MainAxisSize.max
- : MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- widget.icon == null
- ? const SizedBox.shrink()
- : Icon(
- widget.icon,
- size: 20,
- color: iconColor,
- ),
- widget.icon == null ||
- widget.labelText == null
- ? const SizedBox.shrink()
- : const SizedBox(width: 8),
- widget.labelText == null
- ? const SizedBox.shrink()
- : Flexible(
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 8,
- ),
- child: Text(
- widget.labelText!,
- style: labelStyle,
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- ],
- );
- },
- )
- : executionState == ExecutionState.inProgress
- ? SizedBox(
- width: widthOfButton,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- mainAxisSize: MainAxisSize.min,
- children: [
- progressStatus == null
- ? const SizedBox.shrink()
- : ValueListenableBuilder<String>(
- valueListenable: progressStatus!,
- builder:
- (
- BuildContext context,
- String value,
- Widget? child,
- ) {
- return Padding(
- padding: const EdgeInsets.only(
- right: 8.0,
- ),
- child: Text(
- value,
- style: lightTextTheme.smallBold,
- ),
- );
- },
- ),
- EnteLoadingWidget(
- padding: 3,
- color: loadingIconColor,
- ),
- ],
- ),
- )
- : executionState == ExecutionState.successful
- ? SizedBox(
- width: widthOfButton,
- child: Icon(
- Icons.check_outlined,
- size: 20,
- color: checkIconColor,
- ),
- )
- : const SizedBox.shrink(), //fallback
- ),
- ),
- ),
- ),
- );
- }
-
- void _setButtonTheme() {
- progressStatus = widget.progressStatus;
- checkIconColor =
- widget.buttonStyle.checkIconColor ??
- widget.buttonStyle.defaultIconColor;
- loadingIconColor = widget.buttonStyle.defaultIconColor;
- if (widget.isDisabled) {
- buttonColor =
- widget.buttonStyle.disabledButtonColor ??
- widget.buttonStyle.defaultButtonColor;
- borderColor =
- widget.buttonStyle.disabledBorderColor ??
- widget.buttonStyle.defaultBorderColor;
- iconColor =
- widget.buttonStyle.disabledIconColor ??
- widget.buttonStyle.defaultIconColor;
- labelStyle =
- widget.buttonStyle.disabledLabelStyle ??
- widget.buttonStyle.defaultLabelStyle;
- } else {
- buttonColor = widget.buttonStyle.defaultButtonColor;
- borderColor = widget.buttonStyle.defaultBorderColor;
- iconColor = widget.buttonStyle.defaultIconColor;
- labelStyle = widget.buttonStyle.defaultLabelStyle;
- }
- }
-
- bool get _shouldRegisterGestures =>
- !widget.isDisabled && executionState == ExecutionState.idle;
-
- void _onTap() async {
- if (widget.onTap != null) {
- _debouncer.run(
- () => Future(() {
- setState(() {
- executionState = ExecutionState.inProgress;
- });
- }),
- );
- await widget.onTap!.call().then(
- (value) {
- _exception = null;
- },
- onError: (error, stackTrace) {
- executionState = ExecutionState.error;
- _exception = error as Exception;
- _debouncer.cancelDebounce();
- },
- );
- widget.shouldShowSuccessConfirmation && _debouncer.isActive()
- ? executionState = ExecutionState.successful
- : null;
- _debouncer.cancelDebounce();
- if (executionState == ExecutionState.successful) {
- setState(() {});
- }
-
- // when the time taken by widget.onTap is approximately equal to the debounce
- // time, the callback is getting executed when/after the if condition
- // below is executing/executed which results in execution state stuck at
- // idle state. This Future is for delaying the execution of the if
- // condition so that the calback in the debouncer finishes execution before.
- await Future.delayed(const Duration(milliseconds: 5));
- }
- if (executionState == ExecutionState.inProgress ||
- executionState == ExecutionState.error) {
- if (!mounted) return;
- if (executionState == ExecutionState.inProgress) {
- if (mounted) {
- setState(() {
- executionState = ExecutionState.successful;
- Future.delayed(
- Duration(
- seconds: widget.shouldSurfaceExecutionStates
- ? (widget.isInAlert ? 1 : 2)
- : 0,
- ),
- () {
- if (!mounted) return;
- widget.isInAlert
- ? _popWithButtonAction(
- context,
- buttonAction: widget.buttonAction,
- )
- : null;
- if (mounted) {
- setState(() {
- executionState = ExecutionState.idle;
- });
- }
- },
- );
- });
- }
- }
- if (executionState == ExecutionState.error) {
- setState(() {
- executionState = ExecutionState.idle;
- widget.isInAlert
- ? Future.delayed(const Duration(seconds: 0), () {
- if (!mounted) return;
- _popWithButtonAction(
- context,
- buttonAction: ButtonAction.error,
- exception: _exception,
- );
- })
- : null;
- });
- }
- } else {
- if (widget.isInAlert) {
- Future.delayed(
- Duration(seconds: widget.shouldShowSuccessConfirmation ? 1 : 0),
- () {
- if (!mounted) return;
- _popWithButtonAction(context, buttonAction: widget.buttonAction);
- },
- );
- }
- }
- }
-
- void _popWithButtonAction(
- BuildContext context, {
- required ButtonAction? buttonAction,
- Exception? exception,
- }) {
- if (Navigator.of(context).canPop()) {
- Navigator.of(context).pop(ButtonResult(widget.buttonAction, exception));
- } else if (exception != null) {
- //This is to show the execution was unsuccessful if the dialog is manually
- //closed before the execution completes.
- showGenericErrorDialog(context: context, error: exception);
- }
- }
-
- void _onTapDown(TapDownDetails details) {
- setState(() {
- buttonColor =
- widget.buttonStyle.pressedButtonColor ??
- widget.buttonStyle.defaultButtonColor;
- borderColor =
- widget.buttonStyle.pressedBorderColor ??
- widget.buttonStyle.defaultBorderColor;
- iconColor =
- widget.buttonStyle.pressedIconColor ??
- widget.buttonStyle.defaultIconColor;
- labelStyle =
- widget.buttonStyle.pressedLabelStyle ??
- widget.buttonStyle.defaultLabelStyle;
- });
- }
-
- void _onTapUp(TapUpDetails details) {
- Future.delayed(
- const Duration(milliseconds: 84),
- () => setState(() {
- setAllStylesToDefault();
- }),
- );
- }
-
- void _onTapCancel() {
- setState(() {
- setAllStylesToDefault();
- });
- }
-
- void setAllStylesToDefault() {
- buttonColor = widget.buttonStyle.defaultButtonColor;
- borderColor = widget.buttonStyle.defaultBorderColor;
- iconColor = widget.buttonStyle.defaultIconColor;
- labelStyle = widget.buttonStyle.defaultLabelStyle;
- }
-}
diff --git a/mobile/apps/auth/lib/ui/components/dialog_widget.dart b/mobile/apps/auth/lib/ui/components/dialog_widget.dart
index a0b7d2f9a5..1d7e1781f3 100644
--- a/mobile/apps/auth/lib/ui/components/dialog_widget.dart
+++ b/mobile/apps/auth/lib/ui/components/dialog_widget.dart
@@ -1,11 +1,11 @@
import 'dart:async';
import 'package:ente_auth/ui/components/buttons/button_component_adapter.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_base/typedefs.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
diff --git a/mobile/apps/auth/lib/ui/components/models/button_result.dart b/mobile/apps/auth/lib/ui/components/models/button_result.dart
deleted file mode 100644
index 3d6666e58f..0000000000
--- a/mobile/apps/auth/lib/ui/components/models/button_result.dart
+++ /dev/null
@@ -1,11 +0,0 @@
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-
-class ButtonResult {
- ///action can be null when action for the button that is returned when popping
- ///the widget (dialog, actionSheet) which uses a ButtonWidget isn't
- ///relevant/useful and so is not assigned a value when an instance of
- ///ButtonWidget is created.
- final ButtonAction? action;
- final Exception? exception;
- ButtonResult([this.action, this.exception]);
-}
diff --git a/mobile/apps/auth/lib/ui/components/models/button_type.dart b/mobile/apps/auth/lib/ui/components/models/button_type.dart
deleted file mode 100644
index 2122769d63..0000000000
--- a/mobile/apps/auth/lib/ui/components/models/button_type.dart
+++ /dev/null
@@ -1,205 +0,0 @@
-import 'package:ente_auth/theme/colors.dart';
-import 'package:ente_auth/theme/text_style.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:flutter/material.dart';
-
-enum ButtonType {
- primary,
- secondary,
- neutral,
- trailingIcon,
- critical,
- tertiaryCritical,
- trailingIconPrimary,
- trailingIconSecondary,
- tertiary;
-
- bool get isPrimary =>
- this == ButtonType.primary || this == ButtonType.trailingIconPrimary;
-
- bool get hasTrailingIcon =>
- this == ButtonType.trailingIcon ||
- this == ButtonType.trailingIconPrimary ||
- this == ButtonType.trailingIconSecondary;
-
- bool get isSecondary =>
- this == ButtonType.secondary || this == ButtonType.trailingIconSecondary;
-
- bool get isCritical =>
- this == ButtonType.critical || this == ButtonType.tertiaryCritical;
-
- bool get isNeutral =>
- this == ButtonType.neutral || this == ButtonType.trailingIcon;
-
- Color defaultButtonColor(EnteColorScheme colorScheme) {
- if (isPrimary) {
- return colorScheme.primary400;
- }
- if (isSecondary) {
- return colorScheme.fillFaint;
- }
- if (this == ButtonType.neutral || this == ButtonType.trailingIcon) {
- return colorScheme.fillBase;
- }
- if (this == ButtonType.critical) {
- return colorScheme.warning700;
- }
- if (this == ButtonType.tertiaryCritical) {
- return Colors.transparent;
- }
- return Colors.transparent;
- }
-
- //Returning null to fallback to default color
- Color? pressedButtonColor(EnteColorScheme colorScheme) {
- if (isPrimary) {
- return colorScheme.primary700;
- }
- if (isSecondary) {
- return colorScheme.fillFaintPressed;
- }
- if (isNeutral) {
- return colorScheme.fillBasePressed;
- }
- if (this == ButtonType.critical) {
- return colorScheme.warning800;
- }
- return null;
- }
-
- //Returning null to fallback to default color
- Color? disabledButtonColor(
- EnteColorScheme colorScheme,
- ButtonSize buttonSize,
- ) {
- if (buttonSize == ButtonSize.small &&
- (this == ButtonType.primary ||
- this == ButtonType.neutral ||
- this == ButtonType.critical)) {
- return colorScheme.fillMuted;
- }
- if (isPrimary || this == ButtonType.critical || isNeutral) {
- return colorScheme.fillFaint;
- }
- return null;
- }
-
- Color defaultBorderColor(EnteColorScheme colorScheme, ButtonSize buttonSize) {
- if (this == ButtonType.tertiaryCritical && buttonSize == ButtonSize.large) {
- return colorScheme.warning700;
- }
- return Colors.transparent;
- }
-
- //Returning null to fallback to default color
- Color? pressedBorderColor({
- required EnteColorScheme colorScheme,
- required ButtonSize buttonSize,
- }) {
- if (this == ButtonType.tertiaryCritical && buttonSize == ButtonSize.large) {
- return colorScheme.warning700;
- }
- return null;
- }
-
- //Returning null to fallback to default color
- Color? disabledBorderColor(
- EnteColorScheme colorScheme,
- ButtonSize buttonSize,
- ) {
- if (this == ButtonType.tertiaryCritical && buttonSize == ButtonSize.large) {
- return colorScheme.strokeMuted;
- }
- return null;
- }
-
- Color defaultIconColor({
- required EnteColorScheme colorScheme,
- required EnteColorScheme inverseColorScheme,
- }) {
- if (isPrimary || this == ButtonType.critical) {
- return strokeBaseDark;
- }
- if (this == ButtonType.neutral || this == ButtonType.trailingIcon) {
- return inverseColorScheme.strokeBase;
- }
- if (this == ButtonType.tertiaryCritical) {
- return colorScheme.warning500;
- }
- //fallback
- return colorScheme.strokeBase;
- }
-
- //Returning null to fallback to default color
- Color? pressedIconColor(EnteColorScheme colorScheme, ButtonSize buttonSize) {
- if (this == ButtonType.tertiaryCritical) {
- return colorScheme.warning700;
- }
- if (this == ButtonType.tertiary && buttonSize == ButtonSize.small) {
- return colorScheme.fillBasePressed;
- }
- return null;
- }
-
- //Returning null to fallback to default color
- Color? disabledIconColor(EnteColorScheme colorScheme, ButtonSize buttonSize) {
- if (isPrimary ||
- isSecondary ||
- isNeutral ||
- buttonSize == ButtonSize.small) {
- return colorScheme.strokeMuted;
- }
- if (isCritical) {
- return colorScheme.strokeFaint;
- }
- return null;
- }
-
- TextStyle defaultLabelStyle({
- required EnteTextTheme textTheme,
- required EnteTextTheme inverseTextTheme,
- }) {
- if (isPrimary || this == ButtonType.critical) {
- return textTheme.bodyBold.copyWith(color: textBaseDark);
- }
- if (this == ButtonType.neutral || this == ButtonType.trailingIcon) {
- return inverseTextTheme.bodyBold;
- }
- if (this == ButtonType.tertiaryCritical) {
- return textTheme.bodyBold.copyWith(color: warning500);
- }
- //fallback
- return textTheme.bodyBold;
- }
-
- //Returning null to fallback to default color
- TextStyle? pressedLabelStyle(
- EnteTextTheme textTheme,
- EnteColorScheme colorScheme,
- ButtonSize buttonSize,
- ) {
- if (this == ButtonType.tertiaryCritical) {
- return textTheme.bodyBold.copyWith(color: colorScheme.warning700);
- }
- if (this == ButtonType.tertiary && buttonSize == ButtonSize.small) {
- return textTheme.bodyBold.copyWith(color: colorScheme.fillBasePressed);
- }
- return null;
- }
-
- //Returning null to fallback to default color
- TextStyle? disabledLabelStyle(
- EnteTextTheme textTheme,
- EnteColorScheme colorScheme,
- ) {
- return textTheme.bodyBold.copyWith(color: colorScheme.textFaint);
- }
-
- //Returning null to fallback to default color
- Color? checkIconColor(EnteColorScheme colorScheme) {
- if (isSecondary) {
- return colorScheme.primary500;
- }
- return null;
- }
-}
diff --git a/mobile/apps/auth/lib/ui/components/models/custom_button_style.dart b/mobile/apps/auth/lib/ui/components/models/custom_button_style.dart
deleted file mode 100644
index e30504ab3b..0000000000
--- a/mobile/apps/auth/lib/ui/components/models/custom_button_style.dart
+++ /dev/null
@@ -1,33 +0,0 @@
-import 'package:flutter/material.dart';
-
-class CustomButtonStyle {
- Color defaultButtonColor;
- Color? pressedButtonColor;
- Color? disabledButtonColor;
- Color defaultBorderColor;
- Color? pressedBorderColor;
- Color? disabledBorderColor;
- Color defaultIconColor;
- Color? pressedIconColor;
- Color? disabledIconColor;
- TextStyle defaultLabelStyle;
- TextStyle? pressedLabelStyle;
- TextStyle? disabledLabelStyle;
- Color? checkIconColor;
-
- CustomButtonStyle({
- required this.defaultButtonColor,
- this.pressedButtonColor,
- this.disabledButtonColor,
- required this.defaultBorderColor,
- this.pressedBorderColor,
- this.disabledBorderColor,
- required this.defaultIconColor,
- this.pressedIconColor,
- this.disabledIconColor,
- required this.defaultLabelStyle,
- this.pressedLabelStyle,
- this.disabledLabelStyle,
- this.checkIconColor,
- });
-}
diff --git a/mobile/apps/auth/lib/ui/home_page.dart b/mobile/apps/auth/lib/ui/home_page.dart
index 35bdb77ff7..32d469d2c4 100644
--- a/mobile/apps/auth/lib/ui/home_page.dart
+++ b/mobile/apps/auth/lib/ui/home_page.dart
@@ -25,10 +25,8 @@ import 'package:ente_auth/ui/code_error_widget.dart';
import 'package:ente_auth/ui/code_widget.dart';
import 'package:ente_auth/ui/components/auth_qr_dialog.dart';
import 'package:ente_auth/ui/components/auth_selection_action_button.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
import 'package:ente_auth/ui/components/horizontal_scroll_area.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_auth/ui/components/note_dialog.dart';
import 'package:ente_auth/ui/custom_icon_page.dart';
import 'package:ente_auth/ui/home/add_tag_sheet.dart';
@@ -58,6 +56,8 @@ import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_lock_screen/ui/app_lock.dart';
import 'package:ente_pure_utils/ente_pure_utils.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:ente_ui/components/loading_widget.dart';
import 'package:ente_ui/pages/base_home_page.dart';
import 'package:flutter/foundation.dart';
diff --git a/mobile/apps/auth/lib/ui/settings/data/export_widget.dart b/mobile/apps/auth/lib/ui/settings/data/export_widget.dart
index b886840f07..e4bdbea3c3 100644
--- a/mobile/apps/auth/lib/ui/settings/data/export_widget.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/export_widget.dart
@@ -4,9 +4,7 @@ import 'dart:io';
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/models/export/ente.dart';
import 'package:ente_auth/store/code_store.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_auth/ui/settings/data/html_export.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/share_utils.dart' as auth_share;
@@ -14,6 +12,8 @@ import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_crypto_api/ente_crypto_api.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:ente_utils/ente_utils.dart';
import 'package:file_saver/file_saver.dart';
import 'package:flutter/material.dart';
diff --git a/mobile/apps/auth/lib/ui/settings/data/import/import_flow.dart b/mobile/apps/auth/lib/ui/settings/data/import/import_flow.dart
index d74f23b8b8..2aa72f95d7 100644
--- a/mobile/apps/auth/lib/ui/settings/data/import/import_flow.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/import/import_flow.dart
@@ -4,11 +4,11 @@ import 'dart:convert';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/store/code_store.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/settings/data/import/import_instruction_sheet.dart';
import 'package:ente_auth/ui/settings/data/import/import_success.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
import 'package:ente_ui/components/progress_dialog.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart
index 66b128081e..61fc342653 100644
--- a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart
+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart
@@ -4,11 +4,11 @@ import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/services/local_backup_service.dart';
import 'package:ente_auth/services/security_bookmark_service.dart';
import 'package:ente_auth/theme/ente_theme.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
diff --git a/mobile/apps/auth/lib/ui/settings/security_settings_page.dart b/mobile/apps/auth/lib/ui/settings/security_settings_page.dart
index e73c3e54f3..8d9693c7b7 100644
--- a/mobile/apps/auth/lib/ui/settings/security_settings_page.dart
+++ b/mobile/apps/auth/lib/ui/settings/security_settings_page.dart
@@ -6,8 +6,6 @@ import 'package:ente_accounts/pages/sessions_page.dart';
import 'package:ente_accounts/services/passkey_service.dart';
import 'package:ente_accounts/services/user_service.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
import 'package:ente_auth/ui/settings/components/auth_settings_page_scaffold.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
@@ -17,6 +15,8 @@ import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_lock_screen/lock_screen_settings.dart';
import 'package:ente_lock_screen/ui/lock_screen_options.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
import 'package:flutter/material.dart';
import 'package:hugeicons/hugeicons.dart';
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/lib/ui/settings_page.dart b/mobile/apps/auth/lib/ui/settings_page.dart
index 2d70e10c35..e51310baa6 100644
--- a/mobile/apps/auth/lib/ui/settings_page.dart
+++ b/mobile/apps/auth/lib/ui/settings_page.dart
@@ -5,7 +5,6 @@ import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/onboarding/view/onboarding_page.dart';
import 'package:ente_auth/services/review_service.dart';
import 'package:ente_auth/store/code_store.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/settings/about_settings_page.dart';
import 'package:ente_auth/ui/settings/account_settings_page.dart';
import 'package:ente_auth/ui/settings/components/auth_settings_navigation.dart';
@@ -23,6 +22,7 @@ import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
import 'package:ente_ui/components/settings/app_engagement_section.dart';
import 'package:ente_ui/components/settings/app_version_widget.dart';
import 'package:ente_ui/components/settings/social_icons_row.dart';
diff --git a/mobile/apps/auth/lib/ui/tools/debug/raw_codes_viewer.dart b/mobile/apps/auth/lib/ui/tools/debug/raw_codes_viewer.dart
index fa921e38d4..167fcf7b6c 100644
--- a/mobile/apps/auth/lib/ui/tools/debug/raw_codes_viewer.dart
+++ b/mobile/apps/auth/lib/ui/tools/debug/raw_codes_viewer.dart
@@ -5,11 +5,11 @@ import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/services/local_backup_service.dart';
import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/theme/ente_theme.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_lock_screen/local_authentication_service.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
diff --git a/mobile/apps/auth/lib/utils/debouncer.dart b/mobile/apps/auth/lib/utils/debouncer.dart
deleted file mode 100644
index fe1d300cbf..0000000000
--- a/mobile/apps/auth/lib/utils/debouncer.dart
+++ /dev/null
@@ -1,34 +0,0 @@
-import 'dart:async';
-
-import 'package:flutter/material.dart';
-
-class Debouncer {
- final Duration _duration;
- final ValueNotifier<bool> _debounceActiveNotifier = ValueNotifier(false);
- Timer? _debounceTimer;
-
- Debouncer(this._duration);
-
- void run(Future<void> Function() fn) {
- if (isActive()) {
- _debounceTimer!.cancel();
- }
- _debounceTimer = Timer(_duration, () async {
- await fn();
- _debounceActiveNotifier.value = false;
- });
- _debounceActiveNotifier.value = true;
- }
-
- void cancelDebounce() {
- if (_debounceTimer != null) {
- _debounceTimer!.cancel();
- }
- }
-
- bool isActive() => _debounceTimer != null && _debounceTimer!.isActive;
-
- ValueNotifier<bool> get debounceActiveNotifier {
- return _debounceActiveNotifier;
- }
-}
diff --git a/mobile/apps/auth/lib/utils/dialog_util.dart b/mobile/apps/auth/lib/utils/dialog_util.dart
index 649c5c760b..1240edbc5c 100644
--- a/mobile/apps/auth/lib/utils/dialog_util.dart
+++ b/mobile/apps/auth/lib/utils/dialog_util.dart
@@ -4,16 +4,16 @@ import 'dart:math';
import 'package:confetti/confetti.dart';
import "package:dio/dio.dart";
import 'package:ente_auth/ui/components/action_sheet_widget.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/components_constants.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_auth/utils/email_util.dart';
import 'package:ente_auth/utils/platform_util.dart';
import 'package:ente_base/typedefs.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:ente_ui/components/loading_widget.dart';
import 'package:ente_ui/components/progress_dialog.dart';
import 'package:flutter/foundation.dart';
diff --git a/mobile/apps/auth/lib/utils/email_util.dart b/mobile/apps/auth/lib/utils/email_util.dart
index f4ac49cbe4..34ca014d8c 100644
--- a/mobile/apps/auth/lib/utils/email_util.dart
+++ b/mobile/apps/auth/lib/utils/email_util.dart
@@ -3,9 +3,7 @@ import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:email_validator/email_validator.dart';
import 'package:ente_auth/core/configuration.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_auth/ui/tools/debug/log_file_viewer.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/directory_utils.dart' as auth_dir;
@@ -13,6 +11,8 @@ import 'package:ente_auth/utils/share_utils.dart' as auth_share;
import 'package:ente_auth/utils/toast_util.dart';
import 'package:ente_logging/logging.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:ente_utils/ente_utils.dart';
import 'package:file_saver/file_saver.dart';
import 'package:flutter/material.dart';
diff --git a/mobile/apps/auth/lib/utils/share_utils.dart b/mobile/apps/auth/lib/utils/share_utils.dart
index 1507acc6bd..9376f89479 100644
--- a/mobile/apps/auth/lib/utils/share_utils.dart
+++ b/mobile/apps/auth/lib/utils/share_utils.dart
@@ -1,9 +1,9 @@
import 'dart:io';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:share_plus/share_plus.dart';
diff --git a/mobile/apps/auth/test/ui/components/component_dialog_adapters_test.dart b/mobile/apps/auth/test/ui/components/component_dialog_adapters_test.dart
index 029f218bf4..b16a849709 100644
--- a/mobile/apps/auth/test/ui/components/component_dialog_adapters_test.dart
+++ b/mobile/apps/auth/test/ui/components/component_dialog_adapters_test.dart
@@ -1,11 +1,11 @@
import 'package:ente_auth/ui/components/action_sheet_widget.dart';
-import 'package:ente_auth/ui/components/buttons/button_widget.dart';
import 'package:ente_auth/ui/components/dialog_widget.dart';
-import 'package:ente_auth/ui/components/models/button_result.dart';
-import 'package:ente_auth/ui/components/models/button_type.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_components/ente_components.dart';
import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/components/buttons/button_widget.dart';
+import 'package:ente_ui/components/buttons/models/button_result.dart';
+import 'package:ente_ui/components/buttons/models/button_type.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';