Flutter Widgets → Flutter Toast – Camposha

Flutter Widgets

Flutter Widgets

Flutter Widgets

Flutter Toast

Flutter Toast Tutorial and Examples

This is a flutter Toast tutorial.

We see how to show:

  1. Short Toast.
  2. Long Toast.
  3. Colored Toast.
  4. Toast in center of screen.
  5. Toast at the Bottom of screen.

Video tutorial(ProgrammingWizards TV Channel)

Well we have a video tutorial as an alternative to this. If you prefer tutorials like this one then it would be good you subscribe to our YouTube channel. Basically we have a TV for programming where do daily tutorials especially android.

Let’s look a flutter Toast example.

Flutter Toast Example

This is a simple flutter toast example.We use Dart programming language.

Flutter Toast
Flutter Toast

Here are the files we explore:

  1. pubspec.yaml
  2. lib/main.dart
(a). pubspec.yaml
name: mr_toast
description: A  Flutter Toast application.

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  # We will use fluttertoast library
  fluttertoast: ^2.0.7

dev_dependencies:
  flutter_test:
    sdk: flutter

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
(b). main.dart

This is where we write our flutter code in dart programming language. In Dart it is very common to write several classes in a single file. So this simple file will have three classes.

Importing Packages in Flutter/Dart

But first we need to import some packages and we do that using the import keyword in dart.

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

Here are the packages we are importing:

  1. material.dart : will give us material design widgets and theme.
    .
Creating classes in Flutter/Dart

In Dart like in most C style programming languages you create a class using the class keyword. Classes are encapsulation mechanism in Object Oriented Programming languages.

In this case we create three classes:
1.class MyApp extends StatefulWidget{..}

  1. class _MyAppState extends State<MyApp> {..}

Best regards,

Oclemy.

Leave a Reply

Your email address will not be published. Required fields are marked *

X