123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import 'dart:math';
- import 'package:confetti/confetti.dart';
- import 'package:flutter/material.dart';
- import 'package:photos/core/constants.dart';
- import "package:photos/models/search/button_result.dart";
- import 'package:photos/ui/common/loading_widget.dart';
- import 'package:photos/ui/common/progress_dialog.dart';
- import 'package:photos/ui/components/action_sheet_widget.dart';
- import 'package:photos/ui/components/button_widget.dart';
- import 'package:photos/ui/components/dialog_widget.dart';
- import 'package:photos/ui/components/models/button_type.dart';
- typedef DialogBuilder = DialogWidget Function(BuildContext context);
- ///Will return null if dismissed by tapping outside
- Future<ButtonAction?> showErrorDialog(
- BuildContext context,
- String title,
- String? body, {
- bool isDismissable = true,
- }) async {
- return showDialogWidget(
- context: context,
- title: title,
- body: body,
- isDismissible: isDismissable,
- buttons: const [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: "OK",
- isInAlert: true,
- buttonAction: ButtonAction.first,
- ),
- ],
- );
- }
- ///Will return null if dismissed by tapping outside
- Future<ButtonAction?> showGenericErrorDialog({
- required BuildContext context,
- bool isDismissible = true,
- }) async {
- return showDialogWidget(
- context: context,
- title: "Error",
- icon: Icons.error_outline_outlined,
- body:
- "It looks like something went wrong. Please retry after some time. If the error persists, please contact our support team.",
- isDismissible: isDismissible,
- buttons: const [
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: "OK",
- isInAlert: true,
- ),
- ],
- );
- }
- DialogWidget choiceDialog({
- required String title,
- String? body,
- required String firstButtonLabel,
- String secondButtonLabel = "Cancel",
- ButtonType firstButtonType = ButtonType.neutral,
- ButtonType secondButtonType = ButtonType.secondary,
- ButtonAction firstButtonAction = ButtonAction.first,
- ButtonAction secondButtonAction = ButtonAction.cancel,
- FutureVoidCallback? firstButtonOnTap,
- FutureVoidCallback? secondButtonOnTap,
- bool isCritical = false,
- IconData? icon,
- }) {
- final buttons = [
- ButtonWidget(
- buttonType: isCritical ? ButtonType.critical : firstButtonType,
- labelText: firstButtonLabel,
- isInAlert: true,
- onTap: firstButtonOnTap,
- buttonAction: firstButtonAction,
- ),
- ButtonWidget(
- buttonType: secondButtonType,
- labelText: secondButtonLabel,
- isInAlert: true,
- onTap: secondButtonOnTap,
- buttonAction: secondButtonAction,
- ),
- ];
- return DialogWidget(title: title, body: body, buttons: buttons, icon: icon);
- }
- ///Will return null if dismissed by tapping outside
- Future<ButtonAction?> showChoiceDialog(
- BuildContext context, {
- required String title,
- String? body,
- required String firstButtonLabel,
- String secondButtonLabel = "Cancel",
- ButtonType firstButtonType = ButtonType.neutral,
- ButtonType secondButtonType = ButtonType.secondary,
- ButtonAction firstButtonAction = ButtonAction.first,
- ButtonAction secondButtonAction = ButtonAction.cancel,
- FutureVoidCallback? firstButtonOnTap,
- FutureVoidCallback? secondButtonOnTap,
- bool isCritical = false,
- IconData? icon,
- bool isDismissible = true,
- }) async {
- final buttons = [
- ButtonWidget(
- buttonType: isCritical ? ButtonType.critical : firstButtonType,
- labelText: firstButtonLabel,
- isInAlert: true,
- onTap: firstButtonOnTap,
- buttonAction: firstButtonAction,
- ),
- ButtonWidget(
- buttonType: secondButtonType,
- labelText: secondButtonLabel,
- isInAlert: true,
- onTap: secondButtonOnTap,
- buttonAction: secondButtonAction,
- ),
- ];
- return showDialogWidget(
- context: context,
- title: title,
- body: body,
- buttons: buttons,
- icon: icon,
- isDismissible: isDismissible,
- );
- }
- ///Will return null if dismissed by tapping outside
- Future<ButtonResult?> showChoiceActionSheet(
- BuildContext context, {
- required String title,
- String? body,
- required String firstButtonLabel,
- String secondButtonLabel = "Cancel",
- ButtonType firstButtonType = ButtonType.neutral,
- ButtonType secondButtonType = ButtonType.secondary,
- ButtonAction firstButtonAction = ButtonAction.first,
- ButtonAction secondButtonAction = ButtonAction.cancel,
- FutureVoidCallback? firstButtonOnTap,
- FutureVoidCallback? secondButtonOnTap,
- bool isCritical = false,
- IconData? icon,
- bool isDismissible = true,
- }) async {
- final buttons = [
- ButtonWidget(
- buttonType: isCritical ? ButtonType.critical : firstButtonType,
- labelText: firstButtonLabel,
- isInAlert: true,
- onTap: firstButtonOnTap,
- buttonAction: firstButtonAction,
- shouldStickToDarkTheme: true,
- ),
- ButtonWidget(
- buttonType: secondButtonType,
- labelText: secondButtonLabel,
- isInAlert: true,
- onTap: secondButtonOnTap,
- buttonAction: secondButtonAction,
- shouldStickToDarkTheme: true,
- ),
- ];
- return showActionSheet(
- context: context,
- title: title,
- body: body,
- buttons: buttons,
- isDismissible: isDismissible,
- );
- }
- ProgressDialog createProgressDialog(
- BuildContext context,
- String message, {
- isDismissible = false,
- }) {
- final dialog = ProgressDialog(
- context,
- type: ProgressDialogType.normal,
- isDismissible: isDismissible,
- barrierColor: Colors.black12,
- );
- dialog.style(
- message: message,
- messageTextStyle: Theme.of(context).textTheme.caption,
- backgroundColor: Theme.of(context).dialogTheme.backgroundColor,
- progressWidget: const EnteLoadingWidget(),
- borderRadius: 10,
- elevation: 10.0,
- insetAnimCurve: Curves.easeInOut,
- );
- return dialog;
- }
- Future<ButtonAction?> showConfettiDialog<T>({
- required BuildContext context,
- required DialogBuilder dialogBuilder,
- bool barrierDismissible = true,
- Color? barrierColor,
- bool useSafeArea = true,
- bool useRootNavigator = true,
- RouteSettings? routeSettings,
- Alignment confettiAlignment = Alignment.center,
- }) {
- final widthOfScreen = MediaQuery.of(context).size.width;
- final isMobileSmall = widthOfScreen <= mobileSmallThreshold;
- final pageBuilder = Builder(
- builder: dialogBuilder,
- );
- final ConfettiController confettiController =
- ConfettiController(duration: const Duration(seconds: 1));
- confettiController.play();
- return showDialog(
- context: context,
- builder: (BuildContext buildContext) {
- return Padding(
- padding: EdgeInsets.symmetric(horizontal: isMobileSmall ? 8 : 0),
- child: Stack(
- children: [
- Align(alignment: Alignment.center, child: pageBuilder),
- Align(
- alignment: confettiAlignment,
- child: ConfettiWidget(
- confettiController: confettiController,
- blastDirection: pi / 2,
- emissionFrequency: 0,
- numberOfParticles: 100,
- // a lot of particles at once
- gravity: 1,
- blastDirectionality: BlastDirectionality.explosive,
- ),
- ),
- ],
- ),
- );
- },
- barrierDismissible: barrierDismissible,
- barrierColor: barrierColor,
- useSafeArea: useSafeArea,
- useRootNavigator: useRootNavigator,
- routeSettings: routeSettings,
- );
- }
|