Toastr Flutter

Toast notifications for Flutter with no BuildContext required, smooth animations, Promise API, and keyboard avoidance.

pub package

Install

dependencies:
  toastr_flutter: ^2.5.3
flutter pub get

Quick start

import 'package:toastr_flutter/toastr.dart';

Toastr.success('Profile saved');
Toastr.error('Could not save profile');
Toastr.warning('Check your connection');
Toastr.info('A new version is available');

No setup is required for most apps. For nested navigators, use:

MaterialApp(builder: Toastr.builder, home: const HomeScreen());

Promise API

final profile = await Toastr.promise(
  api.saveProfile(),
  loading: 'Saving profile...',
  success: 'Profile saved',
  error: 'Could not save profile',
);

Or:

await api.saveProfile().withToastr(
  loading: 'Saving...',
  success: 'Saved',
  error: 'Failed',
);

loading and promise show a loader while the operation is pending.

Preset toasts

Preset toasts keep a focused API: message is required and the common semantic controls are named optional parameters.

Toastr.warning(
  'Review the required fields',
  title: 'Attention',
  position: ToastrPosition.topRight,
  duration: const Duration(seconds: 6),
  showProgressBar: true,
  showCloseButton: true,
);

For colors, animations, actions, custom content, gestures, and every other advanced setting, use Toastr.custom(ToastrConfig(...)).

Migration

This release updates the default presentation to make notifications easier to scan: semantic types use full-color surfaces, built-in type icons are opt-in, and toasts are shown one at a time by default.

If your app relied on the previous appearance, make the choice explicit:

Toastr.configure(
  useTypeColors: false, // Keep the translucent-black surface.
  showTypeIcons: true,  // Restore built-in type icons.
);

When several notifications are created together, choose their handling policy:

Toastr.configure(queueStrategy: ToastrQueueStrategy.queue);

Available policies are queue, dropNewest, and dropOldest.

String helpers

'Profile saved'.toastrSuccess();
'Check your connection'.toastrWarning();

Custom toasts

Toastr.custom(
  ToastrConfig(
    type: ToastrType.error,
    message: 'Payment failed',
    title: 'Try again',
    useTypeColors: false,
    showTypeIcons: true,
    action: ToastrAction(
      label: 'Retry',
      onPressed: retryPayment,
    ),
  ),
);
final id = Toastr.loading('Uploading...');
await uploadFile();
Toastr.dismiss(id);

State management

Future<void> save() => repository.save().withToastr(
  loading: 'Saving...',
  success: 'Saved',
  error: 'Failed',
);

Demo

cd example
flutter run -d chrome

Toastr Flutter notifications in action

License

Apache-2.0