flash method

void flash({
  1. required String key,
  2. required String message,
  3. FlashMessageType type = .message,
})

Stores a flash message or temporary session value for the next request cycle.

This method also initializes the internal _flashTrips counter used by the framework to determine when flashed data should be removed.

By default, the value is stored in flashMessages, but it can also be written to data or errors depending on type.

Parameters:

  • key: The session key to store.
  • message: The flashed value.
  • type: The flash storage target. Defaults to FlashMessageType.message.

Example:

request.flash(
  key: 'status',
  message: 'Welcome back!',
);

request.flash(
  key: 'email',
  message: 'The email has already been taken.',
  type: FlashMessageType.error,
);

Implementation

void flash({required String key, required String message, FlashMessageType type = .message}) {


  final flashTrip = App().container.tryMake<int>(name: '_flashTrips');

  if(flashTrip == null) {
    App().container.bindInstance<int>(name: "_flashTrips", 1);

    switch(type) {
      case .data:
        thisSession?.data.addAll({key: message});
      case .error:
        thisSession?.errors.addAll({key: message});
      case .message:
        thisSession?.flashMessages.addAll({key: message});
    }
  }
}