Skip to content

fabrik_snackbar

pub.dev

ScaffoldMessenger requires a Scaffold, shows one snackbar at a time, and gives you limited control over placement and animation.

fabrik_snackbar renders into the root Overlay instead. That means no Scaffold requirement, snackbars that survive navigation, and top-or-bottom placement — with four semantic variants for the common cases.

FabrikSnackbar.success(context, title: 'Saved');
FabrikToast.show(context, message: 'Copied to clipboard');
dependencies:
fabrik_snackbar: ^0.1.8
import 'package:fabrik_snackbar/fabrik_snackbar.dart';

No setup, no builder, no provider — the only requirement is a context below a MaterialApp or CupertinoApp.

FabrikSnackbar.success(context, title: 'Profile updated');
FabrikSnackbar.error(
context,
title: 'Upload failed',
message: 'Check your connection and try again.',
);

Every variant takes any combination of title and message — at least one is required.

VariantColorIconUse for
successGreenCheck circleAn action completed
errorRedError outlineAn action failed
warningOrangeWarning triangleSomething needs attention
infoBlueInfo outlinePassive information
SnackbarToast
ContentTitle, message, icon, action buttonA single line of text
DismissalSwipe or autoAuto only
PlacementTop or bottomTop, center, or bottom
Use forResults that may need a responseBrief confirmations

Reach for a toast when the message is “copied” and a snackbar when it is “couldn’t save — retry?”.

FabrikSnackbar.success(
context,
title: 'Item deleted',
actionButton: TextButton(
onPressed: restoreItem,
child: const Text('UNDO', style: TextStyle(color: Colors.white)),
),
);

Plain-string content can be restyled without switching to custom widgets:

FabrikSnackbar.success(
context,
title: 'Saved',
message: 'Your changes are live.',
titleStyle: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
messageStyle: const TextStyle(color: Colors.white70),
);

Omit them to get FabrikSnackbarDefaults.defaultTitleStyle and defaultMessageStyle.

FabrikSnackbar.custom accepts a FabrikSnackbarConfig with every option:

FabrikSnackbar.custom(
context,
config: FabrikSnackbarConfig(
title: 'Order placed',
message: 'Arriving in 2–3 days.',
icon: const Icon(Icons.shopping_bag_outlined, color: Colors.white),
backgroundColor: Colors.indigo,
position: FabrikSnackbarPosition.top,
duration: const Duration(seconds: 5),
borderRadius: BorderRadius.circular(16),
onTap: () => openOrder(),
),
);

Because FabrikSnackbarConfig is const-constructible, reusable styles can live as constants:

const criticalAlert = FabrikSnackbarConfig(
title: 'Session expired',
position: FabrikSnackbarPosition.top,
style: FabrikSnackbarStyle.grounded,
blockBackgroundInteraction: true,
barrierBlur: 4,
);
FabrikSnackbar.custom(context, config: criticalAlert);

For something the user must acknowledge, dim and block the UI behind it:

FabrikSnackbar.custom(
context,
config: const FabrikSnackbarConfig(
title: 'Session expired',
message: 'Please sign in again.',
blockBackgroundInteraction: true,
barrierBlur: 4,
),
);

blockBackgroundInteraction absorbs taps; barrierBlur and barrierColor are the visual treatment. Use it sparingly — it takes over the screen.

For styled runs of text, pass an InlineSpan:

FabrikSnackbar.custom(
context,
config: const FabrikSnackbarConfig(
richTitle: TextSpan(
children: [
TextSpan(text: 'Saved to '),
TextSpan(text: 'Favourites',
style: TextStyle(fontWeight: FontWeight.bold)),
],
),
),
);

When several content fields are set, the highest-priority one wins:

richTitle > titleText > title
richMessage > messageText > message

title and richTitle are mutually exclusive and assert if both are passed; the same applies to message and richMessage.

FabrikToast.show(
context,
message: 'Link copied',
icon: Icons.link,
position: FabrikToastPosition.top,
duration: const Duration(seconds: 2),
);

Both snackbars and toasts render inside a Semantics node marked as a live region, so screen readers announce them when they appear. The announced label is built from the title and message, including text extracted from rich content.

FabrikSnackbar.success · .error · .warning · .info

ParameterTypeDefault
title / messageString?null — at least one required
richTitle / richMessageInlineSpan?null
titleStyle / messageStyleTextStyle?Defaults from FabrikSnackbarDefaults
durationInSecondsint?3
positionFabrikSnackbarPosition?bottom
dismissDirectionFabrikSnackbarDismissDirection?vertical
maxWidthdouble?480 on wide screens
actionButtonWidget?null
safeAreabool?true
barrierBlur / barrierColordouble? / Color?0 / null

Everything above, plus:

ParameterTypeDefaultDescription
titleText / messageTextWidget?nullCustom content widgets
iconWidget?nullLeading icon
backgroundColorColor0xFF323232Ignored when a gradient is set
backgroundGradientGradient?nullOverrides backgroundColor
styleFabrikSnackbarStylefloatingfloating or grounded
margin / paddingEdgeInsets16/8, 16/12Outer and inner spacing
blockBackgroundInteractionboolfalseAbsorb taps behind the snackbar
onTap / onDismissedVoidCallback?nullLifecycle callbacks
ParameterTypeDefault
messageStringrequired
positionFabrikToastPositionbottom
durationDuration2 seconds
backgroundColor / textColorColor0xFF323232 / white
borderRadiusBorderRadiusFully rounded
fontSizedouble14
icon / iconColor / iconSizeIconData? / Color / doublenull / white / 24
onTapVoidCallback?null
EnumValues
FabrikSnackbarPositiontop, bottom
FabrikSnackbarStylefloating, grounded
FabrikSnackbarDismissDirectionvertical, horizontal
FabrikToastPositiontop, center, bottom

Each exposes convenience getters such as isTop and isFloating.