InteractionManager class abstract
The InteractionManager allows you to display dialogs and push Routes
from
anywhere in your code even from places where this is normally not possible because
you might not have a BuildContext
available like from your business logic.
To make this possible you have to register builder functions for your dialogs and
add an InteractionConnector widget directly above
your Material/CupertinoApp
like
return MaterialApp(
theme: ThemeData(
brightness: Brightness.dark,
accentColor: Colors.white,
home: InteractionConnector(
dialogsInitFunction: registerDialogs,
appInitFunction: () async => registerBackend(),
child: StartUpPage()),
Use dialogsInitFunction
to register your own dialogs
The function that you pass to appInitFunction
will be called after
the InteractionManager is initialized so it can be used inside of appInitFunction
InteractionManager registers itself inside GetIt
(https://pub.dev/packages/get_it) so
you can access it from anywhere in your app when you add GetIt
to your project like it
this example that displays a QueryDialog
MessageDialogResults result =
await GetIt.I<InteractionManager>().showQueryDialog(
'This is a query dialog!',
title: 'Query Dialog',
);
This was also an example for the available standard dialogs that you can directly use:
- MessageDialog
- QueryDialog
- LoginDialog
- NetworkConfigurationDialog
- FormDialog
More details in the documentation of the methods and classes below.
Constructors
Properties
- allowReassigningDialogs ↔ bool
-
Dialogs are registered with a name. In most cases registering more
than one dialog with the same name is probably a bug. Therefore an
assertion will be thrown if you try.
If you really need to replace a registered dialog set allowReassigningDialogs
to
true
.getter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
closeDialog<
TResult> ([TResult? result]) → void -
If the InteractionManager has open dialog(s) this will close the top one. You can pass an optional
argument
result
that will be received at the place where the dialog was opened as if the dialog popped itself with it -
navigateTo allows you to push a named
Route
from anywhere in your app. The route name will be passed to the root navigator'sonGenerateRoute
callback . The returned route will be pushed into the navigator. The new route and the previous route (if any) are notified (see Route.didPush and Route.didChangeNext). If the Navigator has any Navigator.observers, they will be notified as well (see NavigatorObserver.didPush). Ongoing gestures within the current route are canceled when a new route is pushed. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerCustomDialog<
DialogDataType> (DialogBuilderFunc< DialogDataType> builder, String dialogName) → void -
If you want to display your own dialog you have to register them first in the InteractionManager
you do this by passing a builder function to registerCustomDialog that returns the content of
the dialog. It will be displayed internally with
showDialog
.DialogDataType
is the type of data that you can pass to your dialog when calling Yout dialog can return data by passing it to theNavigator.pop
method. showRegisteredDialog to show the dialog.dialogName
is the id with that the dialog can be referenced when showing it. Best place to register dialogs is in a function passed asdialogsInitFunction
to the constructor of the InteractionConnector -
If you don't want to use the InteractionConnector you have to set the
NavigatorState
of your root navigator with this method. -
showLoginDialog(
{String title = 'Login', String okButtonText = 'OK', String? cancelButtonText, String usernameLabel = 'User name', String passwordLabel = 'Password', String? header, String? usernameValidator(String)?, String? passwordValidator(String)?, bool barrierDismissible = false}) → Future< UserCredentials?> -
displays a configurable login dialog with an
Ok
and an optionalCancel
button.header
optional texts before/after the input fieldsloginValidator/passwordValidator
optional field validators that get called with the field values when the user presses theOk
button. If the function returns a nonnull
String it gets displayed as warning below the fields and the dialog isn't closed.onValidationError
optional callback that is called when one of the validators returns an error message. IfbarrierDismissible
is set totrue
a tap outside the dialog will pop it. Returned is aUserCredential
object with the name and the password if the user has pressed the "Ok" button otherwise it returnsnull
-
showMessageDialog(
String message, {String? title, String closeButtonText = 'OK', bool barrierDismissible = false}) → Future -
--------- Convenience predefined Dialogs ----------------
displays a simple message dialog with one close button
If
barrierDismissible
is set totrue
a tap outside the dialog will pop it. -
showNetworkConfigurationDialog(
{String title = 'Connection Settings', String? message, String serverAdressLabel = 'Server Address', String portLabel = 'Server Port', String sslLabel = 'Use SSL', bool showProtocolSelection = true, String portFormatErrorMessage = 'Only Numbers', String okButtonText = 'Ok', String? cancelButtonText, NetworkConfiguration networkConfiguration, bool barrierDismissible = false}) → Future< NetworkConfiguration?> -
showQueryDialog(
String message, {String? title, Map< MessageDialogResults, String> buttonDefinitions = const {MessageDialogResults.yes : 'Yes', MessageDialogResults.no : 'No'}, bool barrierDismissible = false}) → Future<MessageDialogResults> -
displays a message dialog with a row of configurable buttons
You define the buttons by passing a
Map<MessageDialogResults,String>
asbuttonDefinitions
where the key of a map entry defines the the value that is returned when the button is pressed, the String value is the label of the button. IfbarrierDismissible
is set totrue
a tap outside the dialog will pop it. -
showRegisteredDialog<
DialogDataType, ResultType> ({required String dialogName, required DialogDataType data, bool barrierDismissible = false}) → Future< ResultType?> -
showRegisteredDialog displays a registered dialog. The dialog is platform aware so that on Android a
Material- and on iOS a Cupertino dialog is displayed.
dialogName
the name the dialog was registered withdata
that gets passed to the dialogs builder function IfbarrierDismissible
is set totrue
a tap outside the dialog will pop it.ResultType
defines which type the data has that the dialog returns when it gets popped -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited