Toast Message in Flutter

  • msg - It is a String property and it will only contain the feedback or the information that displays on our screen.
  • context - It is nothing but BuildContext.
  • duration - It denotes the period of time. We have two options short-period(Toast.LENGTH_SHORT), long-period(Toast.LENGTH_LONG).
  • gravity - It denotes the position of the toast message, whether it is top(Toast.TOP), center(Toast.CENTER), or bottom(Toast.BOTTOM).
  1. Create the RaisedButton and in its child property, create a text widget as “Show Short Toast” which is the button name, and in the onPressed property, call the showToast as “Show Short Toast” which displays the toast message.
    [Note :
    showToast is a function which we already created in step 4.]
  2. On the next button, we have added the gravity property in showToast. Here, the gravity is Toast.BOTTOM which means it will display the toast message on the bottom of the screen.
  3. On the last button, the gravity property is Toast.TOP which means it will display the toast message on top of the screen.
  • textColor → It denotes the color of the text and the default color is white.
  • backgroundColor → Here default color is 0xAA000000.
  • backgroundRadius → Here default radius is 16.
  • border → It is an optional property.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store