Skip to content

AFib Utilities

Accessing App Platform Information

All current project styles call context.executeStandardAFibStartup in their startup queries. That call executes an internal AFib query which loads version and platform-related information into your state.

You can access that information using spi.context.accessAppPlatformInfo(). Note that this information does not need to be in your state view, as all of it is constant for the entire execution of your app.

Standard Dialogs

AFib provides standard dialogs with the following calls:

context.showDialogErrorText(...);
context.showDialogWarningText(...);
context.showDialogInfoText(...);
context.showDialogChoice(...)
context.showDialogChoiceText(...)

Anytime afib has a ...Text function variant, it just indiciates that parameters which would normally be widgets (allowing you to configure their appearance arbitrarily), have been replaced with parameters that can accept either hard-coded string text, or Widget or Translation IDs.

Using UI Methods from Queries

Almost all the utilities mentioned here are available on both the AFBuildContext found within the SPI, and on the AFFinishQuerySuccessContext found within a query. Howeer, while the UI context has a theme (which is used to provide styling for the UI), the query context does not. Instead, it has a required themeOrId parameter, to which you should specify XXXThemeID.defaultTheme.

In-App Notifications

AFib provides a way to show simple in-app notifications:

context.showInAppNotification(...);
context.showInAppNotificationText(...);

Snackbars

You can show a snackbar (a material design transient popup confirmation), using:

context.showSnackBarText(...);
context.showSnackbar(...);

The Standard Back Button

AFib provides utilities for placing a standard 'Back' icon at the top left of a screen. You can achieve this in two ways.

For more control, you can explicitly construct an app bar, and supply a shouldContinueCheck function, as shown below. Note that this function can be async, allowing you to wait on a user input before returning a value.

Scaffold(
    ...
    appBar: t.childAppBar(
        ...
        leading: t.childButtonStandardBack(spi, screen: screenId, shouldContinueCheck: () async {
            // or AFShouldContinue.noStop
            return AFShouldContinue.yesContinue;
        });
    );

If you want to show a standardized should continue dialog, you can use this syntax for the 'leading' parameter instead:

    leading: t.childButtonStandardBack(spi, screen: screenId, shouldContinueCheck: t.standardShouldContinueAlertCheck(
        spi: spi,
        navigate: AFShouldContinueDialog.navigatePush(),
        shouldAsk: spi.yourShouldAskBoolean,
    ));

spi.yourShouldAskBoolean would typically be a value indicating whether their were unsaved changes on the screen.

Should continue is disabled in UI prototypes

In UI prototypes, this alert is intentionally disabled, and the back button will take you out of the prototype by default.

The Unimplemented Screen

AFib provides a standard way of navigating to an unimplemented screen. This is especially useful in libraries:

context.navigateToUnimplementedScreen(...);

Rich Text Builder

AFRichTextBuilder is a simple utility for building flowing text with multiple styles. It supports normal, bold, tapable, and muted text. You can provide custom styles which indicate what each of those styles is. You then convert it to a widget using its toWidget() method.

Handling App Lifecycle Events

If you are looking for a way to detect app lifecycle events or monitor all query executions, see the end of the section on accessing external state, as lifecycle events are handled via a query.