show static method

FutureOr<void> show({
  1. required Widget child,
  2. required BuildContext context,
  3. double? top,
  4. double? left,
  5. double? right,
  6. VoidCallback? onTap,
  7. Duration duration = const Duration(seconds: 10),
  8. Curve curve = Curves.easeOutCubic,
  9. Curve dismissCurve = Curves.easeOutCubic,
  10. bool useRootNavigator = false,
  11. @visibleForTesting FutureOr notificationCreatedCallback()?,
})

Shows specified Widget as notification.

child is required, this will be displayed as notification body. context is required, this is used to get internally used notification controller class which is subclass of InheritedWidget.

Showing and hiding notifications is managed by animation, and the process is as follows.

  1. Execute this method, start animation via call state's show method internally.
  2. Then the notification appear, it will stay at specified duration.
  3. After the duration has elapsed, play the animation in reverse and dispose the notification.

This method will awaits an animation that showing the notification.

Implementation

static FutureOr<void> show({
  required Widget child,
  required BuildContext context,
  double? top,
  double? left,
  double? right,
  VoidCallback? onTap,
  Duration duration = const Duration(seconds: 10),
  Curve curve = Curves.easeOutCubic,
  Curve dismissCurve = Curves.easeOutCubic,
  bool useRootNavigator = false,
  // ignore: strict_raw_type
  @visibleForTesting FutureOr Function()? notificationCreatedCallback,
}) async {
  final controller = _NotificationController.of(context);

  assert(controller != null, 'Not found InAppNotification controller.');

  await controller!.create(
    child: child,
    context: context,
    onTap: onTap,
    top: top ?? 0.0,
    left: left,
    right: right,
    useRootNavigator: useRootNavigator,
  );
  if (kDebugMode) {
    await notificationCreatedCallback?.call();
  }
  await controller.show(
    duration: duration,
    curve: curve,
    dismissCurve: dismissCurve,
    top: top ?? 0.0,
  );
}