Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add routeSettings, transitionBuilder and navigatorKey Parameters to Dialog Methods #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions example/lib/ui/views/dialog_view.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:stacked_services_example/ui/setup_dialog_ui.dart';

import '../../app/app.locator.dart';
import 'package:flutter/material.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:stacked_services_example/ui/setup_dialog_ui.dart';

import '../../app/app.locator.dart';
import '../../enums/dialog_type.dart';

class DialogView extends StatelessWidget {
Expand Down Expand Up @@ -31,6 +30,7 @@ class DialogView extends StatelessWidget {
await _dialogService.showDialog(
title: 'Test Dialog Title',
description: 'Test Dialog Description',
//routeSettings: RouteSettings(name: '/materialDialog'),
);
},
child: Text(
Expand All @@ -50,9 +50,10 @@ class DialogView extends StatelessWidget {
OutlinedButton(
onPressed: () async {
await _dialogService.showDialog(
title: 'Test Dialog Title',
// description: 'Test Dialog Description',
);
title: 'Test Dialog Title',
// description: 'Test Dialog Description',
routeSettings: RouteSettings(name: '/materialDialog'),
navigatorKey: StackedService.navigatorKey);
},
child: Text(
'Show Material Dialog',
Expand All @@ -73,6 +74,7 @@ class DialogView extends StatelessWidget {
await _dialogService.showDialog(
// title: 'Test Dialog Title',
description: 'Test Dialog Description',
routeSettings: RouteSettings(name: '/materialDialog'),
);
},
child: Text(
Expand All @@ -89,13 +91,23 @@ class DialogView extends StatelessWidget {
OutlinedButton(
onPressed: () async {
await _dialogService.showCustomDialog(
variant: DialogType.Basic,
title: 'This is a custom UI with Text as main button',
description:
'Sheck out the builder in the dialog_ui_register.dart file',
mainButtonTitle: 'Ok',
showIconInMainButton: false,
barrierDismissible: true);
variant: DialogType.Basic,
title: 'This is a custom UI with Text as main button',
description: 'Sheck out the builder in the dialog_ui_register.dart file',
mainButtonTitle: 'Ok',
showIconInMainButton: false,
barrierDismissible: true,
routeSettings: RouteSettings(name: '/customDialogWithTransition'),
transitionBuilder: (context, animation, secondaryAnimation, child) => SlideTransition(
position: animation.drive(
Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: const Offset(0.0, 0.0),
),
),
child: child,
),
);
},
child: Text(
'Show Custom Text Dialog',
Expand All @@ -110,17 +122,15 @@ class DialogView extends StatelessWidget {
),
OutlinedButton(
onPressed: () async {
final response = await _dialogService.showCustomDialog<
GenericDialogResponse, GenericDialogRequest>(
final response = await _dialogService.showCustomDialog<GenericDialogResponse, GenericDialogRequest>(
variant: DialogType.Generic,
title:
'This is a custom Generic UI with Text as main button',
description:
'Sheck out the builder in the dialog_ui_register.dart file',
title: 'This is a custom Generic UI with Text as main button',
description: 'Sheck out the builder in the dialog_ui_register.dart file',
mainButtonTitle: 'Ok',
showIconInMainButton: false,
barrierDismissible: true,
data: GenericDialogRequest(),
routeSettings: RouteSettings(name: '/customDialog'),
);

print(response?.data?.message ?? '');
Expand All @@ -134,9 +144,9 @@ class DialogView extends StatelessWidget {
await _dialogService.showCustomDialog(
variant: DialogType.Basic,
title: 'This is a custom UI with icon',
description:
'Sheck out the builder in the dialog_ui_register.dart file',
description: 'Sheck out the builder in the dialog_ui_register.dart file',
showIconInMainButton: true,
routeSettings: RouteSettings(name: '/customDialog'),
);
},
child: Text(
Expand All @@ -156,6 +166,7 @@ class DialogView extends StatelessWidget {
title: 'Test Confirmation Dialog Title',
description: 'Test Confirmation Dialog Description',
barrierDismissible: true,
routeSettings: RouteSettings(name: '/materialConfirmationDialog'),
);
},
child: Text(
Expand All @@ -175,6 +186,7 @@ class DialogView extends StatelessWidget {
dialogPlatform: DialogPlatform.Cupertino,
title: 'Test Confirmation Dialog Title',
description: 'Test Dialog Description',
routeSettings: RouteSettings(name: '/materialDialog'),
);
},
child: Text(
Expand All @@ -198,6 +210,7 @@ class DialogView extends StatelessWidget {
title: 'Test Confirmation Dialog Title',
description: 'Test Confirmation Dialog Description',
barrierDismissible: true,
routeSettings: RouteSettings(name: '/materialConfirmationDialog'),
);
},
child: Text(
Expand Down
53 changes: 31 additions & 22 deletions lib/src/dialog/dialog_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ class DialogService {
_dialogBuilders = {...?_dialogBuilders, ...builders};
}

Map<dynamic, DialogBuilder> _customDialogBuilders =
Map<dynamic, DialogBuilder>();
Map<dynamic, DialogBuilder> _customDialogBuilders = Map<dynamic, DialogBuilder>();

@Deprecated(
'Prefer to use the StackedServices.navigatorKey instead of using this key. This will be removed in the next major version update for stacked.')
@Deprecated('Prefer to use the StackedServices.navigatorKey instead of using this key. This will be removed in the next major version update for stacked.')
get navigatorKey {
return Get.key;
}
Expand All @@ -47,9 +45,7 @@ class DialogService {
)
void registerCustomDialogBuilder({
required dynamic variant,
required Widget Function(
BuildContext, DialogRequest, Function(DialogResponse))
builder,
required Widget Function(BuildContext, DialogRequest, Function(DialogResponse)) builder,
}) {
_customDialogBuilders[variant] = builder;
}
Expand All @@ -68,6 +64,8 @@ class DialogService {
String buttonTitle = 'Ok',
Color? buttonTitleColor,
bool barrierDismissible = false,
RouteSettings? routeSettings,
GlobalKey<NavigatorState>? navigatorKey,

/// Indicates which [DialogPlatform] to show.
///
Expand All @@ -84,11 +82,11 @@ class DialogService {
buttonTitleColor: buttonTitleColor,
dialogPlatform: dialogPlatform,
barrierDismissible: barrierDismissible,
routeSettings: routeSettings,
navigatorKey: navigatorKey,
);
} else {
var _dialogType = GetPlatform.isAndroid
? DialogPlatform.Material
: DialogPlatform.Cupertino;
var _dialogType = GetPlatform.isAndroid ? DialogPlatform.Material : DialogPlatform.Cupertino;
return _showDialog(
title: title,
description: description,
Expand All @@ -98,6 +96,8 @@ class DialogService {
buttonTitleColor: buttonTitleColor,
dialogPlatform: _dialogType,
barrierDismissible: barrierDismissible,
routeSettings: routeSettings,
navigatorKey: navigatorKey,
);
}
}
Expand All @@ -111,6 +111,8 @@ class DialogService {
Color? buttonTitleColor,
DialogPlatform dialogPlatform = DialogPlatform.Material,
bool barrierDismissible = false,
RouteSettings? routeSettings,
GlobalKey<NavigatorState>? navigatorKey,
}) {
var isConfirmationDialog = cancelTitle != null;
return Get.dialog<DialogResponse>(
Expand Down Expand Up @@ -153,6 +155,8 @@ class DialogService {
],
),
barrierDismissible: barrierDismissible,
routeSettings: routeSettings,
navigatorKey: navigatorKey,
);
}

Expand Down Expand Up @@ -185,9 +189,10 @@ class DialogService {
bool barrierDismissible = false,
String barrierLabel = '',
bool useSafeArea = true,
@Deprecated(
'Prefer to use `data` and pass in a generic type. customData doesn\'t work anymore')
dynamic customData,
RouteSettings? routeSettings,
GlobalKey<NavigatorState>? navigatorKey,
RouteTransitionsBuilder? transitionBuilder,
@Deprecated('Prefer to use `data` and pass in a generic type. customData doesn\'t work anymore') dynamic customData,
R? data,
}) {
assert(
Expand All @@ -207,6 +212,9 @@ class DialogService {
transitionDuration: const Duration(milliseconds: 200),
barrierDismissible: barrierDismissible,
barrierLabel: barrierLabel,
routeSettings: routeSettings,
navigatorKey: navigatorKey,
transitionBuilder: transitionBuilder,
pageBuilder: (BuildContext buildContext, _, __) {
final child = Builder(
key: useSafeArea ? null : Key('dialog_view'),
Expand Down Expand Up @@ -245,22 +253,23 @@ class DialogService {
String confirmationTitle = 'Ok',
Color? confirmationTitleColor,
bool barrierDismissible = false,
RouteSettings? routeSettings,

/// Indicates which [DialogPlatform] to show.
///
/// When not set a Platform specific dialog will be shown
DialogPlatform? dialogPlatform,
}) =>
showDialog(
title: title,
description: description,
buttonTitle: confirmationTitle,
buttonTitleColor: confirmationTitleColor,
cancelTitle: cancelTitle,
cancelTitleColor: cancelTitleColor,
dialogPlatform: dialogPlatform,
barrierDismissible: barrierDismissible,
);
title: title,
description: description,
buttonTitle: confirmationTitle,
buttonTitleColor: confirmationTitleColor,
cancelTitle: cancelTitle,
cancelTitleColor: cancelTitleColor,
dialogPlatform: dialogPlatform,
barrierDismissible: barrierDismissible,
routeSettings: routeSettings);

/// Completes the dialog and passes the [response] to the caller
void completeDialog(DialogResponse response) {
Expand Down
Loading