Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fluttertoast
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
fluttertoast
Commits
39b1b0c4
Unverified
Commit
39b1b0c4
authored
Feb 09, 2023
by
Alex Seednov
Committed by
GitHub
Feb 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FToast improvements to provide safer usage (#415)
Co-authored-by: Alexander <seednov-alexander@ya.ru>
parent
bb926f7a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
8 deletions
+38
-8
lib/fluttertoast.dart
+38
-8
No files found.
lib/fluttertoast.dart
View file @
39b1b0c4
import
'dart:async'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
...
...
@@ -59,8 +59,8 @@ class Fluttertoast {
Color
?
backgroundColor
,
Color
?
textColor
,
bool
webShowClose
=
false
,
webBgColor
:
"linear-gradient(to right, #00b09b, #96c93d)"
,
webPosition
:
"right"
,
webBgColor
=
"linear-gradient(to right, #00b09b, #96c93d)"
,
webPosition
=
"right"
,
})
async
{
String
toast
=
"short"
;
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
...
...
@@ -143,11 +143,41 @@ class FToast {
_entry
=
null
;
return
;
}
if
(
context
==
null
)
{
/// Need to clear queue
removeQueuedCustomToasts
();
throw
(
"Error: Context is null, Please call init(context) before showing toast."
);
}
/// To prevent exception "Looking up a deactivated widget's ancestor is unsafe."
/// which can be thrown if context was unmounted (e.g. screen with given context was popped)
if
(
context
?.
mounted
!=
true
)
{
if
(
kDebugMode
)
{
print
(
'FToast: Context was unmuted, can not show
${_overlayQueue.length}
toast.'
);
}
/// Need to clear queue
removeQueuedCustomToasts
();
return
;
// Or maybe thrown error too
}
var
_overlay
=
Overlay
.
maybeOf
(
context
!);
if
(
_overlay
==
null
)
{
/// Need to clear queue
removeQueuedCustomToasts
();
throw
(
"""Error: Overlay is null.
Please don't use top of the widget tree context (such as Navigator or MaterialApp) or
create overlay manually in MaterialApp builder.
More information
- https://github.com/ponnamkarthik/FlutterToast/issues/393
- https://github.com/ponnamkarthik/FlutterToast/issues/234"""
);
}
/// Create entry only after all checks
_ToastEntry
_toastEntry
=
_overlayQueue
.
removeAt
(
0
);
_entry
=
_toastEntry
.
entry
;
if
(
context
==
null
)
throw
(
"Error: Context is null, Please call init(context) before showing toast."
);
Overlay
.
of
(
context
!)?.
insert
(
_entry
!);
_overlay
.
insert
(
_entry
!);
_timer
=
Timer
(
_toastEntry
.
duration
,
()
{
_fadeTimer
=
Timer
(
_toastEntry
.
fadeDuration
,
()
{
...
...
@@ -163,7 +193,7 @@ class FToast {
_fadeTimer
?.
cancel
();
_timer
=
null
;
_fadeTimer
=
null
;
if
(
_entry
!=
null
)
_entry
!
.
remove
();
_entry
?
.
remove
();
_entry
=
null
;
_showOverlay
();
}
...
...
@@ -179,7 +209,7 @@ class FToast {
_timer
=
null
;
_fadeTimer
=
null
;
_overlayQueue
.
clear
();
if
(
_entry
!=
null
)
_entry
!
.
remove
();
_entry
?
.
remove
();
_entry
=
null
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment