Flutter Toast 使用 Flutter 原生 API实现的 Toast 功能

Overview

Toast

A Flutter Toast plugin.

How to Use

# add this line to your dependencies
toast: ^0.1.4
import 'package:toast/toast.dart';
Toast.show("Toast plugin app", context, duration: Toast.LENGTH_SHORT, gravity:  Toast.BOTTOM);
property description
msg String (Not Null)(required)
context BuildContext (Not Null)(required)
duration Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
gravity Toast.TOP (or) Toast.CENTER (or) Toast.BOTTOM
textStyle TextStyle (default fontSize:15, color: Colors.white)
backgroundColor Color (default Color(0xAA000000))
backgroundRadius double (default 16)
border Border (optional)

toast toast

License

MIT License
Comments
  • Target of URI doesn't exist: 'package:toast/toast.dart'.

    Target of URI doesn't exist: 'package:toast/toast.dart'.

    After Add import 'package:toast/toast.dart'; this line into my main.dart file, not run to my app and show this error message..Please give me a solution how to solve it..

    Error message : Target of URI doesn't exist: 'package:toast/toast.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

    opened by udarakalpana 2
  • not work in WillPopScope (onWillPop)

    not work in WillPopScope (onWillPop)

    WillPopScope( // onWillPop: () async{ Toast.show("test",context); } )

    E/flutter ( 2193): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'insert' was called on null. E/flutter ( 2193): Receiver: null E/flutter ( 2193): Tried calling: insert(Instance of 'OverlayEntry') E/flutter ( 2193): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5) E/flutter ( 2193): #1 ToastView.createView (package:toast/toast.dart:67:18) E/flutter ( 2193): E/flutter ( 2193): #2 Toast.show (package:toast/toast.dart:19:15) E/flutter ( 2193): #3 AppState.build. (package:mama_call/main.dart:145:25) E/flutter ( 2193): #4 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #5 AppState.build. (package:mama_call/main.dart:141:26) E/flutter ( 2193): #6 ModalRoute.willPop (package:flutter/src/widgets/routes.dart:1083:26) E/flutter ( 2193): #7 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #8 ModalRoute.willPop (package:flutter/src/widgets/routes.dart:1079:38) E/flutter ( 2193): #9 NavigatorState.maybePop (package:flutter/src/widgets/navigator.dart:2004:57) E/flutter ( 2193): #10 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #11 NavigatorState.maybePop (package:flutter/src/widgets/navigator.dart:2001:42) E/flutter ( 2193): #12 _WidgetsAppState.didPopRoute (package:flutter/src/widgets/app.dart:808:28) E/flutter ( 2193): #13 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #14 _WidgetsAppState.didPopRoute (package:flutter/src/widgets/app.dart:803:27) E/flutter ( 2193): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.handlePopRoute (package:flutter/src/widgets/binding.dart:482:26) E/flutter ( 2193): #16 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.handlePopRoute (package:flutter/src/widgets/binding.dart:480:30) E/flutter ( 2193): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding._handleNavigationInvocation (package:flutter/src/widgets/binding.dart:510:16) E/flutter ( 2193): #19 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:397:55) E/flutter ( 2193): #20 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #21 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:394:39) E/flutter ( 2193): #22 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:365:54) E/flutter ( 2193): #23 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binary_messenger.dart:110:33) E/flutter ( 2193): #24 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6) E/flutter ( 2193): #25 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binary_messenger.dart:101:37) E/flutter ( 2193): #26 _invoke3. (dart:ui/hooks.dart:280:15) E/flutter ( 2193): #27 _rootRun (dart:async/zone.dart:1124:13) E/flutter ( 2193): #28 _CustomZone.run (dart:async/zone.dart:1021:19) E/flutter ( 2193): #29 _CustomZone.runGuarded (dart:async/zone.dart:923:7) E/flutter ( 2193): #30 _invoke3 (dart:ui/hooks.dart:279:10) E/flutter ( 2193): #31 _dispatchPlatformMessage (dart:ui/hooks.dart:141:5)

    opened by unclehking 2
  • Wrong after installation

    Wrong after installation

    `Failed to build iOS app Error output from Xcode build: ↳ ** BUILD FAILED **

    Xcode's output: ↳ The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. Supported values are: 3.0, 4.0, 4.2. This setting can be set in the build settings editor.`

    bug 
    opened by iiiusky 2
  • Not incompatibilities androidX

    Not incompatibilities androidX

    when ues androidx ,import this lib build failed with error info :

    /Users/Carl/dev_soft/flutter/.pub-cache/hosted/pub.flutter-io.cn/fluttertoast-2.2.11/android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java:14: 错误: 程序包android.support.v4.content不存在
    import android.support.v4.content.ContextCompat;
                                     ^
    /Users/Carl/dev_soft/flutter/.pub-cache/hosted/pub.flutter-io.cn/fluttertoast-2.2.11/android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java:107: 错误: 找不到符号
              Drawable shapeDrawable = ContextCompat.getDrawable(ctx, R.drawable.toast_bg);
                                       ^
      符号:   变量 ContextCompat
      位置: 类 FluttertoastPlugin
    2 个错误
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':fluttertoast:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for details.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 15s
    Running Gradle task 'assembleDebug'...
    Running Gradle task 'assembleDebug'... Done                        15.9s
    The built failed likely due to AndroidX incompatibilities in a plugin. The tool
    is about to try using Jetfier to solve the incompatibility.
    
    opened by carl1990 1
  • toast 页面不能穿透事件,导致层级较低的UI界面无法响应事件,会有等待时间,有较大的体验问题

    toast 页面不能穿透事件,导致层级较低的UI界面无法响应事件,会有等待时间,有较大的体验问题

    这里提出一个简单的优化方案,实测有效: 在Material外层包裹一个IgnorePointer即可. @override Widget build(BuildContext context) { return new Positioned( top: gravity == 2 ? 50 : null, bottom: gravity == 0 ? 50 : null, child: IgnorePointer( child: Material( color: Colors.transparent, child: widget, ) )); }

    opened by TPQuietBro 1
  • Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable

    Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable

    兄弟,使用过程报了这个错,请问有解决方案吗: image

    Exception has occurred. FlutterError (Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable. To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method. )

    opened by carmel 1
  • Keyboard is over Toast

    Keyboard is over Toast

    Hi there! Thanks for this awesome Flutter plugin. I am actually facing an issue while using it, when I am using Toast.Bottom as gravity value the Keyboard hide the Toast when it is active. can you make the Toast move just above it. I am actually using the center mode but it is not what I initially wanted. Thanks

    opened by frediustcDev 1
  • Toast iOS Error

    Toast iOS Error

    Hi, I got this error after running this line: Toast.show("Toast plugin app", duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM);

    flutter/.pub-cache/hosted/pub.dartlang.org/toast-0.0.6/ios/Classes/ToastReference.swift:325:37: error: 'init(style:)' has been renamed to 'init(activityIndicatorStyle:)' let activityIndicatorView = UIActivityIndicatorView(style: .whiteLarge) ^ ~~~~~ activityIndicatorStyle UIKit.UIActivityIndicatorView:6:12: note: 'init(style:)' was introduced in Swift 4.2 public init(style: UIActivityIndicatorViewStyle) ^ /Users/rlecheta/Dev/flutter/.pub-cache/hosted/pub.dartlang.org/toast-0.0.6/ios/Classes/ToastReference.swift:354:47: error: 'common' has been renamed to 'RunLoopMode.commonModes' RunLoop.main.add(timer, forMode: .common) ^~~~~~ RunLoopMode.commonModes Foundation.RunLoop.Mode:9:23: note: 'common' was introduced in Swift 4.2 public static let common: RunLoopMode ^ /Users/rlecheta/Dev/flutter/.pub-cache/hosted/pub.dartlang.org/toast-0.0.6/ios/Classes/ToastReference.swift:354:47: error: 'common' has been renamed to 'RunLoopMode.commonModes' RunLoop.main.add(timer, forMode: .common) ^~~~~~ RunLoopMode.commonModes Foundation.RunLoop.Mode:9:23: note: 'common' was introduced in Swift 4.2 public static let common: RunLoopMode

    bug 
    opened by rlecheta 1
  • ssss

    ssss

    package com.android.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.fragment.MenuFragment;
//import com.special.ResideMenu.ResideMenu;
//import com.special.ResideMenu.ResideMenuInfo;
//import com.special.ResideMenu.ResideMenuItem;

public class MainActivity extends FragmentActivity {

    public Fragment mContent;
    public TextView maintitle;
    public ImageView logo;

    private MenuFragment fragment;

    MyApplication myApp;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        maintitle = (TextView) findViewById(R.id.main_txt);
        logo = (ImageView) findViewById(R.id.logo);

        myApp = (MyApplication) getApplication();

        // changeFragment(new HuDongFragment());
        initView();// 初始化页面信息
    }


    // 监听手机上的BACK键
    //public boolean onKeyDown(int keyCode, KeyEvent event) {
    //    if (keyCode == KeyEvent.KEYCODE_BACK) {
    //        // 判断菜单是否关闭
    //        if (is_closed) {
    //            // 判断两次点击的时间间隔(默认设置为2秒)ime) > 2000) {
    //                Toast.makeText(this, "再按一次退出程
    //            if ((System.currentTimeMillis() - mExitT序", Toast.LENGTH_SHORT).show();

    //                mExitTime = System.currentTimeMillis();
    //            } else {
    //                finish();
    //                System.exit(0);
    //                super.onBackPressed();
    //            }
    //        } else {
    //            resideMenu.closeMenu();
    //        }
    //        return true;
    //    }
    //    return super.onKeyDown(keyCode, event);
    //}

    private void initView() {

        maintitle.setText("今日签到");
        fragment =  new MenuFragment();
        mContent = fragment;

        // 显示主页面
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, mContent).commit();

    }

    public void switchContent(Fragment fragment) {
        fragment.getClass().getSimpleName() == fragment.getClass().getSimpleName()

        mContent = fragment;

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, fragment).commit();

    }

    @Override
    public void onBackPressed() {
        switchContent(fragment);
        //  super.onBackPressed();
    }
}

    
    opened by appdev 0
  • textStyle instead of textColor

    textStyle instead of textColor

    In my humble opinion we should give more opportunity to customize Toast. Adding textStyle parameter to show method make our toast message more usable.

    opened by RenatFakhrutdinov 0
  • Added 'context' to the example given.

    Added 'context' to the example given.

    Beginners would find it confusing that the example given didn't work out of the box and they wouldn't know how to debug it. Overall, good job! I found the package useful. No frills, no unnecessary bloats.

    opened by wtoalabi 0
  • Showing a second toast before the previous one disappears makes it disappear too soon

    Showing a second toast before the previous one disappears makes it disappear too soon

    If I show a first toast for 5 seconds, then after 4 seconds show a second toast, then the second message gets shown only one second. Seems like there are two ways one could fix that:

    • Using a Timer instead of Future.delayed. Timers can be canceled. https://api.dart.dev/stable/2.3.1/dart-async/Timer/cancel.html
    • Wrapping the Future.delayed with a CancelableOperation. https://pub.dev/documentation/async/latest/async/CancelableOperation-class.html
    opened by atn832 1
  • fix: Demo Unhandled Exception:  Null check operator used on a null value Close #29

    fix: Demo Unhandled Exception: Null check operator used on a null value Close #29

    [PROBLEM]

    The official demo will throw the error Unhandled Exception: Null check operator used on a null value when showing toast.

    see: Issue#29

    [REASON]

    1. Toast.show need invoke ToastView.createView which need overlayState from its ancestor widget.
    2. The official demo initial the ToastContext in MyApp.build, which ancestor element is RenderObjectToWidgetElement -> StatelessElement,so Overlay.of can't find overlayState.
    3. Meanwhile the MaterialApp already insert an overlayState for us

    [SOLUTION]

    Use the context of MyHomePage instead of MyApp.

    [TEST]

    Work with Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19043.1766], locale en-US)

    image

    opened by jixiaoyong 0
  • [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 147 pos 12: '_overlay != null': is not true.

    [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 147 pos 12: '_overlay != null': is not true.

    [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 147 pos 12: '_overlay != null': is not true.

    [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Null check operator used on a null value

    opened by chetannager 3
  • NoSuchMethodError: The method 'insert' was called on null.

    NoSuchMethodError: The method 'insert' was called on null.

    My code is very simple and I'm still getting an error :

    void initState() { super.initState(); Toast.show("Toast plugin app", context, duration: Toast.LENGTH_SHORT, gravity: Toast.BOTTOM); }

    error :

    [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'insert' was called on null. E/flutter ( 2653): Receiver: null E/flutter ( 2653): Tried calling: insert(Instance of 'OverlayEntry')

    opened by FarsFuad 2
  • Toast Message is not visible when keyboard is shown

    Toast Message is not visible when keyboard is shown

    Hi! You made a good open source library. I really appreciate about it.

    But there is a bug which is related with the soft keyboard. Toast Message is not visible when keyboard is shown.

    Thanks!

    opened by ghost 1
Owner
www.apkdv.com
null
The @Flutter Plugin to show native toast on Android

Native Toast The Flutter Plugin to show native toast on Android. How it works? The native_toast plugin works on the basis of the Toast class. in Andro

Mihir Paldhikar 4 Jan 3, 2023
A simple yet powerful Flutter plugin for showing Toast at Android, iOS and Web.

Flutter Toast A simple yet powerful Flutter plugin for showing Toast at Android and iOS. Features: Native Toast Pure Flutter Toaster Installation Add

Eyro Labs 5 Dec 13, 2021
FlutterToast - Flutter application to show Android's Toast Message

Android's Toast Message in Flutter Flutter application to show Android's Toast Message. Methods and code to Show Toast message in flutter. To show Toa

Uttam 4 Dec 16, 2022
Toast Plugin for Flutter

fluttertoast Toast Library for Flutter Now this toast library supports two kinds of toast messages one which requires BuildContext other with No Build

Karthik Ponnam 1.3k Jan 9, 2023
Toast Plugin for Flutter

fluttertoast Toast Library for Flutter Now this toast library supports two kinds of toast messages one which requires BuildContext other with No Build

Karthik Ponnam 1.1k Feb 12, 2022
Reddit like flutter toast

asset_toast A new flutter plugin project. Getting Started | usage AssetToast.show("hello there", context, asset: "assets/im

Griffins Gichure 5 Oct 22, 2021
🆙🚀 Flutter application upgrade/ Flutter App Upgrade /Flutter App Update/Flutter Update / download Plug-in

???? Flutter application upgrade/ Flutter App Upgrade /Flutter App Update/Flutter Update / download Plug-in (with notice bar progress), supports full upgrade, hot update and incremental upgrade

PengHui Li 344 Dec 30, 2022
ABC of Flutter widgets. Intended for super beginners at Flutter. Play with 35+ examples in DartPad directly and get familiar with various basic widgets in Flutter

Basic Widgets Examples This is aimed for complete beginners in Flutter, to get them acquainted with the various basic widgets in Flutter. Run this pro

Pooja Bhaumik 815 Jan 3, 2023
Minha primeira aplicação android utilizando Flutter feito no curso de Flutter da Cod3r Cursos Online. O foco dessa aplicação foi um contato inicial com o Flutter.

expenses Expenses é uma aplicação android simples feita em Flutter para controlar despesas pessoais. A aplicação consiste em: Listar transações feitas

Guilherme Teixeira Ais 2 Apr 19, 2022
Flutter Github Following Application, Using Flutter Provider and Flutter HTTP to get data from Github API.

Flutter Github Following Application Watch it on Youtube Previous Designs Checkout my Youtube channel Installation Please remember, after cloning this

Mohammad Rahmani 110 Dec 23, 2022
Flutter RSS feed parsing - A demo application of flutter which parse RSS XML contents to the flutter application

Flutter RSS feed parsing demo This is demo application of flutter which shows ho

Nyakuri Levite 3 Nov 15, 2022
Boris Gautier 1 Jan 31, 2022
Code for Flutter Talk from Flutter Vikings 2022: Custom User Interactions in Flutter

Custom User Interactions - Flutter Vikings 2022 A companion app for the Flutter Vikings 2022 talk - Custom User Interactions with Shortcuts, Intents,

Justin McCandless 9 Sep 16, 2022
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI 1/2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Fl

Johannes Milke 46 Dec 6, 2022
Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flutter app.

Flutter Tutorial - User Profile Page UI #2 Create a Flutter User Profile Page UI where you can access and edit your user's information within your Flu

Johannes Milke 45 Dec 15, 2022
Let's create a selectable Flutter Navigation Drawer with routing that highlights the current item within the Flutter Sidebar Menu.

Flutter Tutorial - Sidebar Menu & Selectable Navigation Drawer Let's create a selectable Flutter Navigation Drawer with routing that highlights the cu

Johannes Milke 12 Dec 26, 2022
Components that optimize Flutter fluency.(Flutter 流畅度优化的通用方案,轻松解决卡顿问题)

Flutter fluency optimization component "Keframe" Page switching fluency improved: How to use Project depend on: Quick learning Constructor Description

Ke Technologies 793 Dec 30, 2022
Challenge yourself every weekend with flutter. Join me to implement challenging UI & digital designs using Flutter.

Weekend With Flutter This is my new challenge. Every weekend, I want to implement challenging UI & digital designs using Flutter. you can join me with

Payam Zahedi 16 Feb 24, 2022
Let's create a complete Flutter User Profile Page with SharedPreferences to persist the user's information in Flutter.

Flutter Tutorial - User Profile & SharedPreferences Let's create a complete Flutter User Profile Page with SharedPreferences to persist the user's inf

Johannes Milke 21 Dec 3, 2022