Showtoast, showloading, showconfirmdialog

Time:2020-10-31

This is a few commonly used global common prompt box method, which may be used many times in my later articles. Here, we will record them in a unified way.
The following methods are all written inlib/common/toast.dartMedium.

showToast

fluttertoastToast library for Android and IOS for flutter.
staypubspec.yamlAdd:

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

void showToast(
  String text, {
  gravity: ToastGravity.CENTER,
  toastLength: Toast.LENGTH_SHORT,
}) {
  Fluttertoast.showToast(
    msg: text,
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.BOTTOM,
    timeInSecForIos: 1,
    backgroundColor:  Colors.grey [600], // gray background
    fontSize: 16.0,
  );
}

use:

Showtoast ("deleted successfully! "";

showLoading

A loaded animation, not text, default display text loading

void showLoading(context, [String text]) {
  text = text ?? "Loading...";
  showDialog(
      barrierDismissible: false,
      context: context,
      builder: (context) {
        return Center(
          child: Container(
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(3.0),
                boxShadow: [
                  //Shadow
                  BoxShadow(
                    color: Colors.black12,
                    //offset: Offset(2.0,2.0),
                    blurRadius: 10.0,
                  )
                ]),
            padding: EdgeInsets.all(16),
            margin: EdgeInsets.all(16),
            constraints: BoxConstraints(minHeight: 120, minWidth: 180),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                SizedBox(
                  height: 30,
                  width: 30,
                  child: CircularProgressIndicator(
                    strokeWidth: 3,
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 20.0),
                  child: Text(
                    text,
                    style: Theme.of(context).textTheme.body2,
                  ),
                ),
              ],
            ),
          ),
        );
      });
}

use:

Showloading (context, 'deleting, please wait...');

showConfirmDialog

For the prompt box with the confirm cancel button, content is the content text of the prompt box, and confirmcallback is the callback of clicking the OK button

void showConfirmDialog(BuildContext context,String content, Function confirmCallback) {
  showDialog(
      context: context,
      builder: (context) {
        return new AlertDialog(
          Title: new text,
          content: new Text(content),
          actions: <Widget>[
            new FlatButton(
              onPressed: () {
                confirmCallback();
                Navigator.of(context).pop();
              },
              Child: new text,
            ),
            new FlatButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              Child: new text,
            ),
          ],
        );
      });
}

use:

Showconfirmdialog (context, 'are you sure you want to delete this data? ', () {
          //Print ('click OK to delete... ');
          //Logic after performing the determine operation
 });

reference material

fluttertoast
showDialog<T> function
AlertDialog class: A material design alert dialog.
【Flutter】ActionSheet, Alert, Dialog

Recommended Today

Example of java servlet filter

Introduction to servlet filter      Servlet filter is actually a standard Java class. This class obtains the function of filter by implementing the filter interface. It passes through the JSP container when it starts web.xml The configuration file is loaded by the system.The servlet filter is called when receiving the user’s request. When the server receives […]