# Toast

Toast is a light feedback widget.

# FLToastDefaults

FLToastDefaults supports configuration of toast view style, position, display duration, dark mode and other behaviors. The default configuration is as follows:

const FLToastDefaults({
    this.showDuration = const Duration(milliseconds: 1500),
    this.darkColor = Colors.white,
    this.darkBackgroundColor = Colors.black87,
    this.backgroundOpacity = 0.8,
    this.lightColor = const Color(0xFF2F2F2F),
    this.lightBackgroundColor = const Color(0xFFE0E0E0),
    this.position = FLToastPosition.center,
    this.style = FLToastStyle.dark,
    this.dismissOtherToast = true,
    this.hideWithTap = true,
    this.textDirection = TextDirection.ltr,
    this.topOffset = kToolbarHeight + 10,
    this.bottomOffset = 10,
});

# FLToastProvider

FLToastProvider provides the ability to display toasts in the sub-widget tree. It generally acts as the parent node of the MaterialApp.

class _MyAppState extends State<MyApp> {
  FLToastDefaults _toastDefaults = FLToastDefaults();
  
  
  Widget build(BuildContext context) {
    return FLToastProvider(
      defaults: _toastDefaults,
      child: MaterialApp(
        title: 'FLUI',
        theme: $YOUR_THEME
        routes: $ROUTES
      )
   );
}

# FLToast



To show Toast, you need to use FLToast's static methods.

  • text
FLToast.text(text: 'Here is text');
/// or
FLToast.showText(text: 'Here is text', position: FLToastPosition.xxx, duration: Duration(seconds: xxx), style: FLToastStyle.xxx);
/// shortcut
FLToast.showText(text: 'Here is text');
  • loading
var dismiss = FLToast.loading(text: 'Loading...');
/// do something...
Future.delayed(Duration(seconds: 2), () {
    /// hide toast
    dismiss();
});
  • info, success & error
/// info
FLToast.info(text: 'Some info');
/// success
FLToast.success(text: 'Fetch success');
/// error
FLToast.error(text: 'Something was wrong');
  • custom content

GestureDetector(
  onTapDown: (TapDownDetails details) {
    final Widget mic = Container(
        padding: EdgeInsets.all(15),
        child: Image.asset('assets/record.gif', scale: 2));

    _hideCustomToast = FLToast.show(
        text: 'Swipe up to cancel sending',
        contentBuilder: (context) => mic);
  },
  onLongPressEnd: (LongPressEndDetails details) {
    if (_hideCustomToast != null) {
      _hideCustomToast();
      _hideCustomToast = null;
    }
  },
  child: ....
)

# dark mode



FLToastProvider(
    defaults: FLToastDefaults(style: FLToastStyle.light),
    ...
)
/// or show just once
FLToast.showText(text: 'Here is text', style: FLToastStyle.light);

# other position



FLToastProvider(
    defaults: FLToastDefaults(position: FLToastPosition.top),
    ...
)
/// or show just once
FLToast.showText(text: 'Here is text', position: FLToastPosition.top);

# API

# FLToastDefaults

property description type default value
showDuration show duration time Duration Duration(milliseconds: 1500)
darkColor text and icon color in dark style Color Colors.white
darkBackgroundColor background color in dark style Color Colors.black87
backgroundOpacity opacity of background color double 0.8
lightColor text and icon color in light style Color Color(0xFF2F2F2F)
lightBackgroundColor background color in light style Color Color(0xFFE0E0E0)
position toast position FLToastPosition FLToastPosition.center
style toast style FLToastStyle FLToastStyle.dark
dismissOtherToast dismiss other toasts when showing new toast bool true
hideWithTap tap to hide toast bool true
textDirection text direction TextDirection TextDirection.ltr
topOffset top offset double 66
bottomOffset bottom offset double 10

# FLToastProvider

property description type default value
defaults default configuration FLToastDefaults FLToastDefaults()
child child widget Widget

# FLToast

Method list:

  • loading({String text})

  • showLoading({String text, FLToastPosition position, FLToastStyle style})

  • show({String text, FLToastContentBuilder contentBuilder})

  • showToast({String text, FLToastContentBuilder contentBuilder, Duration duration, FLToastPosition position, FLToastStyle style})

  • text({String text})

  • showText({String text, Duration showDuration, FLToastPosition position, FLToastStyle style, VoidCallback onDismissed})

  • success({String text})

  • showSuccess({String text, Duration showDuration, FLToastPosition position, FLToastStyle style, VoidCallback onDismissed})

  • error({String text})

  • showError({String text, Duration showDuration, FLToastPosition position, FLToastStyle style, VoidCallback onDismissed})

  • info({String text})

  • showInfo({String text, Duration showDuration, FLToastPosition position, FLToastStyle style, VoidCallback onDismissed})


Argument list:
argument description type default value
text toast text String
position toast position FLToastPosition defaults.position
style toast style FLToastStyle defaults.style
duration show duration Duration defaults.duration
onDismissed dismiss callback VoidCallback

loading, showLoading, show, showToast have a return function which is used to dismiss the toast.