iT邦幫忙

2024 iThome 鐵人賽

DAY 14
0
Mobile Development

畢業專題拯救計畫系列 第 14

Flutter中的Third-Party Libraries--Fluttertoast

  • 分享至 

  • xImage
  •  

Fluttertoast 是 Flutter 中一個非常方便的插件,用於在應用界面上顯示簡短的訊息通知(toast)。這些訊息會在一段時間後自動消失,不會卡住使得下一則訊息無法發送,非常適合用來向用戶反饋操作結果。例如成功訊息(如「保存成功」)、錯誤訊息(如「操作失敗」)、警告訊息,或者其他簡短的通知等等。

添加到 pubspec.yaml

要使用這個插件,需要在 pubspec.yaml 文件中添加 dependencies:

dependencies:
  fluttertoast: v 8.2.8

導入插件

在 Dart 文件中導入 fluttertoast 包:

import 'package:fluttertoast/fluttertoast.dart';

使用 Fluttertoast.showToast() 方法來顯示訊息

Fluttertoast.showToast(
    msg: "This is a toast message",
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.BOTTOM,
    timeInSecForIosWeb: 1,
    backgroundColor: Colors.black,
    textColor: Colors.white,
    fontSize: 16.0
);

原本介面
https://ithelp.ithome.com.tw/upload/images/20240831/20163322RbCoMEvFW1.png
當點擊按鈕會顯示通知
https://ithelp.ithome.com.tw/upload/images/20240831/20163322dGjn6ibTIU.png
我們明天見~


上一篇
Flutter中的Third-Party Libraries--三個photo Libraries
下一篇
Flutter中的Plugin--url_launcher
系列文
畢業專題拯救計畫22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言