亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于fluttertoast實(shí)現(xiàn)封裝彈框提示工具類(lèi)

 更新時(shí)間:2022年05月16日 15:19:38   作者:編程小龍  
這篇文章主要為大家介紹了基于fluttertoast實(shí)現(xiàn)封裝彈框提示工具類(lèi)的實(shí)現(xiàn)代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

提示

已將代碼上傳至gitee,后續(xù)會(huì)繼續(xù)更新學(xué)習(xí)封裝的一些組件:

flutter練習(xí)

實(shí)現(xiàn)效果

實(shí)現(xiàn)

1.先在pubspec.yaml文件匯總引入fluttertoast的包:

fluttertoast: ^8.0.8 # 彈窗

2.封裝彈框工具類(lèi)DialogUtils:

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
/// @author longzipeng
/// @創(chuàng)建時(shí)間:2022/2/24
/// 封裝自定義彈框
class DialogUtils {
  /// 基礎(chǔ)彈框
  static alert(
    BuildContext context, {
    String title = "提示",
    String content = "",
    GestureTapCallback? confirm,
    GestureTapCallback? cancle,
    List<Widget>? actions, // 自定義按鈕
  }) {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text(
              '提示',
              style: TextStyle(color: Theme.of(context).primaryColor),
            ),
            content: Text(content),
            actions: actions ??
                <Widget>[
                  InkWell(
                    onTap: () {
                      if (cancle != null) {
                        cancle();
                      }
                      Navigator.of(context).pop();
                    },
                    child: const Padding(
                      padding: EdgeInsets.only(right: 20),
                      child: Text(
                        "取消",
                        style: TextStyle(color: Colors.grey),
                      ),
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      if (confirm != null) {
                        confirm();
                      }
                      Navigator.of(context).pop();
                    },
                    child: Padding(
                      padding: const EdgeInsets.only(right: 10),
                      child: Text(
                        "確定",
                        style: TextStyle(color: Theme.of(context).primaryColor),
                      ),
                    ),
                  )
                ],
          );
        });
  }
  /// 彈出關(guān)于界面
  static alertAboutDialog(BuildContext context) {
    showAboutDialog(
      context: context,
      applicationIcon: FlutterLogo(),
      applicationName: 'flutterdemo',
      applicationVersion: '1.0.0',
      applicationLegalese: 'copyright 編程小龍',
      children: <Widget>[
        Container(
          height: 70,
          child: const Text(
            "總而言之,言而總之,時(shí)而不知,終究自知",
            maxLines: 2,
            style: TextStyle(),
          ),
        ),
      ],
    );
  }
  /// 顯示普通消息
  static showMessage(String msg,
      {toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.grey,
      fontSize: 16.0}) {
    // 先關(guān)閉彈框再顯示對(duì)應(yīng)彈框
    Fluttertoast.cancel();
    Fluttertoast.showToast(
        msg: msg,
        toastLength: toastLength,
        gravity: gravity,
        timeInSecForIosWeb: timeInSecForIosWeb,
        backgroundColor: backgroundColor,
        fontSize: fontSize);
  }
  /// 顯示錯(cuò)誤消息
  static showErrorMessage(String msg,
      {toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.red,
      fontSize: 16.0}) {
    showMessage(msg,
        toastLength: toastLength,
        gravity: gravity,
        timeInSecForIosWeb: timeInSecForIosWeb,
        backgroundColor: backgroundColor,
        fontSize: fontSize);
  }
  /// 顯示警告信息
  static showWaringMessage(String msg,
      {toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.orangeAccent,
      fontSize: 16.0}) {
    showMessage(msg,
        toastLength: toastLength,
        gravity: gravity,
        timeInSecForIosWeb: timeInSecForIosWeb,
        backgroundColor: backgroundColor,
        fontSize: fontSize);
  }
  /// 顯示成功消息
  static showSuccessMessage(String msg,
      {toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
        backgroundColor: Colors.greenAccent,
        fontSize: 16.0}) {
    showMessage(msg,
        toastLength: toastLength,
        gravity: gravity,
        timeInSecForIosWeb: timeInSecForIosWeb,
        backgroundColor: backgroundColor,
        fontSize: fontSize);
  }
}

測(cè)試

注意:這里L(fēng)istTitleWidget是自己封裝的組件,直接改為L(zhǎng)istTitle就不會(huì)報(bào)錯(cuò)了

import 'package:csdn_flutter_demo/pages/common/common_appbar.dart';
import 'package:csdn_flutter_demo/utils/dialog_utils.dart';
import 'package:csdn_flutter_demo/widgets/list_title_widgets.dart';
import 'package:flutter/material.dart';
/// @author longzipeng
/// @創(chuàng)建時(shí)間:2022/3/31
/// 彈框演示頁(yè)面
class DialogUtilsDemoPage extends StatefulWidget {
  const DialogUtilsDemoPage({Key? key}) : super(key: key);
  @override
  State<DialogUtilsDemoPage> createState() => _DialogUtilsDemoPageState();
}
class _DialogUtilsDemoPageState extends State<DialogUtilsDemoPage> {
  /// 查詢(xún)數(shù)據(jù)
  search(value) {
    print("搜索的值為:$value");
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const CommonAppbar(
        title: "彈窗、提示演示",
      ),
      body: ListView(
        children: [
          ListTitleWidget(
            title: const Text("彈框,帶確認(rèn)和取消"),
            onTap: () {
              DialogUtils.alert(context, content: "靚仔、靚女們,一起學(xué)習(xí)flutter!",
                  confirm: () {
                print("點(diǎn)擊了確認(rèn)");
              }, cancle: () {
                print("點(diǎn)擊了取消");
              });
            },
          ),
          ListTitleWidget(
            title: const Text("默認(rèn)提示"),
            onTap: () {
              DialogUtils.showMessage("默認(rèn)提示");
            },
          ),
          ListTitleWidget(
            title: const Text("成功提示"),
            onTap: () {
              DialogUtils.showSuccessMessage("成功提示");
            },
          ),
          ListTitleWidget(
            title: const Text("警告提示"),
            onTap: () {
              DialogUtils.showWaringMessage("警告提示");
            },
          ),
          ListTitleWidget(
            title: const Text("錯(cuò)誤提示"),
            onTap: () {
              DialogUtils.showErrorMessage("錯(cuò)誤提示");
            },
          ),
        ],
      ),
    );
  }
}

以上就是基于fluttertoast實(shí)現(xiàn)封裝彈框提示工具類(lèi)的詳細(xì)內(nèi)容,更多關(guān)于fluttertoast封裝彈框提示工具類(lèi)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題

    完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題

    下面小編就為大家?guī)?lái)一篇完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • Android實(shí)現(xiàn)圖片毛玻璃背景效果

    Android實(shí)現(xiàn)圖片毛玻璃背景效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片毛玻璃背景效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android中TelephonyManager用法實(shí)例

    Android中TelephonyManager用法實(shí)例

    這篇文章主要介紹了Android中TelephonyManager用法,結(jié)合實(shí)例形式分析了TelephonyManager類(lèi)的功能,使用技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-03-03
  • Android彈幕框架 黑暗火焰使基本使用方法

    Android彈幕框架 黑暗火焰使基本使用方法

    這篇文章主要介紹了Android彈幕框架黑暗火焰使基本使用方法,需要的朋友可以參考下。今天我將分享由BiliBili開(kāi)源的Android彈幕框架(DanmakuFlameMaster)的學(xué)習(xí)經(jīng)驗(yàn),感興趣的朋友一起看看吧
    2016-10-10
  • Android變形(Transform)之Matrix用法

    Android變形(Transform)之Matrix用法

    Android的2D變形(包括縮放,扭曲,平移,旋轉(zhuǎn)等)可以通過(guò)Matrix來(lái)實(shí)現(xiàn),本文研究了一下;接下來(lái)就將我這倆天研究的東西和大家分享下,先來(lái)看看Matrix的用法感興趣的你可不要錯(cuò)過(guò)了哈
    2013-02-02
  • Android studio升級(jí)4.1時(shí)遇到的問(wèn)題記錄

    Android studio升級(jí)4.1時(shí)遇到的問(wèn)題記錄

    這篇文章主要介紹了Android studio升級(jí)4.1時(shí)遇到的問(wèn)題記錄,本文給大家介紹的非常詳細(xì),在大家的平時(shí)開(kāi)發(fā)過(guò)程都是經(jīng)常遇到的問(wèn)題,需要的朋友可以參考下
    2020-10-10
  • 關(guān)于AndroidStudio R文件莫名其妙缺失的快速解決方法

    關(guān)于AndroidStudio R文件莫名其妙缺失的快速解決方法

    下面小編就為大家?guī)?lái)一篇關(guān)于AndroidStudio R文件莫名其妙缺失的快速解決方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Android基于OpenGL在GLSurfaceView上繪制三角形及使用投影和相機(jī)視圖方法示例

    Android基于OpenGL在GLSurfaceView上繪制三角形及使用投影和相機(jī)視圖方法示例

    這篇文章主要介紹了Android基于OpenGL在GLSurfaceView上繪制三角形及使用投影和相機(jī)視圖方法,結(jié)合實(shí)例形式分析了Android基于OpenGL的圖形繪制技巧,需要的朋友可以參考下
    2016-10-10
  • Android使用Jetpack Compose開(kāi)發(fā)零基礎(chǔ)起步教程

    Android使用Jetpack Compose開(kāi)發(fā)零基礎(chǔ)起步教程

    Jetpack Compose是用于構(gòu)建原生Android UI的現(xiàn)代工具包。Jetpack Compose使用更少的代碼,強(qiáng)大的工具和直觀的Kotlin API,簡(jiǎn)化并加速了Android上的UI開(kāi)發(fā)
    2023-04-04
  • Android中Item實(shí)現(xiàn)點(diǎn)擊水波紋效果

    Android中Item實(shí)現(xiàn)點(diǎn)擊水波紋效果

    這篇文章主要給大家介紹了關(guān)于Android中Item實(shí)現(xiàn)點(diǎn)擊水波紋效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開(kāi)發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-11-11

最新評(píng)論