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
f829e327
Commit
f829e327
authored
Mar 21, 2021
by
Karthik Ponnam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NullSafety on master
parent
85bbe9eb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
46 deletions
+51
-46
CHANGELOG.md
+5
-0
example/pubspec.lock
+1
-1
lib/fluttertoast.dart
+34
-34
lib/fluttertoast_web.dart
+9
-9
pubspec.lock
+1
-1
pubspec.yaml
+1
-1
No files found.
CHANGELOG.md
View file @
f829e327
## [8.0.2]
-
Null Safety
-
Code Docs Added
## [7.1.8]
## [7.1.8]
-
Web sourceMap Warning
-
Web sourceMap Warning
...
...
example/pubspec.lock
View file @
f829e327
...
@@ -169,5 +169,5 @@ packages:
...
@@ -169,5 +169,5 @@ packages:
source: hosted
source: hosted
version: "2.1.0"
version: "2.1.0"
sdks:
sdks:
dart: ">=2.12.0
-0.0
<3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.10.0"
flutter: ">=1.10.0"
lib/fluttertoast.dart
View file @
f829e327
...
@@ -37,8 +37,8 @@ class Fluttertoast {
...
@@ -37,8 +37,8 @@ class Fluttertoast {
/// Let say you have an active show
/// Let say you have an active show
/// Use this method to hide the toast immediately
/// Use this method to hide the toast immediately
static
Future
<
bool
>
cancel
()
async
{
static
Future
<
bool
?
>
cancel
()
async
{
bool
res
=
await
_channel
.
invokeMethod
(
"cancel"
);
bool
?
res
=
await
_channel
.
invokeMethod
(
"cancel"
);
return
res
;
return
res
;
}
}
...
@@ -49,14 +49,14 @@ class Fluttertoast {
...
@@ -49,14 +49,14 @@ class Fluttertoast {
/// Wraps the https://github.com/apvarun/toastify-js for Web
/// Wraps the https://github.com/apvarun/toastify-js for Web
///
///
/// Parameter [msg] is required and remning all are options
/// Parameter [msg] is required and remning all are options
static
Future
<
bool
>
showToast
({
static
Future
<
bool
?
>
showToast
({
@
required
String
msg
,
required
String
msg
,
Toast
toastLength
,
Toast
?
toastLength
,
int
timeInSecForIosWeb
=
1
,
int
timeInSecForIosWeb
=
1
,
double
fontSize
,
double
?
fontSize
,
ToastGravity
gravity
,
ToastGravity
?
gravity
,
Color
backgroundColor
,
Color
?
backgroundColor
,
Color
textColor
,
Color
?
textColor
,
bool
webShowClose
=
false
,
bool
webShowClose
=
false
,
webBgColor:
"linear-gradient(to right, #00b09b, #96c93d)"
,
webBgColor:
"linear-gradient(to right, #00b09b, #96c93d)"
,
webPosition:
"right"
,
webPosition:
"right"
,
...
@@ -95,7 +95,7 @@ class Fluttertoast {
...
@@ -95,7 +95,7 @@ class Fluttertoast {
'webPosition'
:
webPosition
'webPosition'
:
webPosition
};
};
bool
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
bool
?
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
return
res
;
return
res
;
}
}
}
}
...
@@ -110,7 +110,7 @@ typedef PositionedToastBuilder = Widget Function(
...
@@ -110,7 +110,7 @@ typedef PositionedToastBuilder = Widget Function(
/// fToast.showToast(child)
/// fToast.showToast(child)
///
///
class
FToast
{
class
FToast
{
BuildContext
context
;
BuildContext
?
context
;
static
final
FToast
_instance
=
FToast
.
_internal
();
static
final
FToast
_instance
=
FToast
.
_internal
();
...
@@ -126,9 +126,9 @@ class FToast {
...
@@ -126,9 +126,9 @@ class FToast {
FToast
.
_internal
();
FToast
.
_internal
();
OverlayEntry
_entry
;
OverlayEntry
?
_entry
;
List
<
_ToastEntry
>
_overlayQueue
=
[];
List
<
_ToastEntry
>
_overlayQueue
=
[];
Timer
_timer
;
Timer
?
_timer
;
/// Internal function which handles the adding
/// Internal function which handles the adding
/// the overlay to the screen
/// the overlay to the screen
...
@@ -142,9 +142,9 @@ class FToast {
...
@@ -142,9 +142,9 @@ class FToast {
_entry
=
_toastEntry
.
entry
;
_entry
=
_toastEntry
.
entry
;
if
(
context
==
null
)
if
(
context
==
null
)
throw
(
"Error: Context is null, Please call init(context) before showing toast."
);
throw
(
"Error: Context is null, Please call init(context) before showing toast."
);
Overlay
.
of
(
context
).
insert
(
_entry
);
Overlay
.
of
(
context
!)!.
insert
(
_entry
!
);
_timer
=
Timer
(
_toastEntry
.
duration
,
()
{
_timer
=
Timer
(
_toastEntry
.
duration
!
,
()
{
Future
.
delayed
(
Duration
(
milliseconds:
360
),
()
{
Future
.
delayed
(
Duration
(
milliseconds:
360
),
()
{
removeCustomToast
();
removeCustomToast
();
});
});
...
@@ -156,7 +156,7 @@ class FToast {
...
@@ -156,7 +156,7 @@ class FToast {
removeCustomToast
()
{
removeCustomToast
()
{
_timer
?.
cancel
();
_timer
?.
cancel
();
_timer
=
null
;
_timer
=
null
;
if
(
_entry
!=
null
)
_entry
.
remove
();
if
(
_entry
!=
null
)
_entry
!
.
remove
();
_showOverlay
();
_showOverlay
();
}
}
...
@@ -169,7 +169,7 @@ class FToast {
...
@@ -169,7 +169,7 @@ class FToast {
_timer
?.
cancel
();
_timer
?.
cancel
();
_timer
=
null
;
_timer
=
null
;
_overlayQueue
.
clear
();
_overlayQueue
.
clear
();
if
(
_entry
!=
null
)
_entry
.
remove
();
if
(
_entry
!=
null
)
_entry
!
.
remove
();
_entry
=
null
;
_entry
=
null
;
}
}
...
@@ -179,10 +179,10 @@ class FToast {
...
@@ -179,10 +179,10 @@ class FToast {
/// Paramenter [child] is requried
/// Paramenter [child] is requried
///
///
void
showToast
({
void
showToast
({
@
required
Widget
child
,
required
Widget
child
,
PositionedToastBuilder
positionedToastBuilder
,
PositionedToastBuilder
?
positionedToastBuilder
,
Duration
toastDuration
,
Duration
?
toastDuration
,
ToastGravity
gravity
,
ToastGravity
?
gravity
,
})
{
})
{
Widget
newChild
=
_ToastStateFul
(
Widget
newChild
=
_ToastStateFul
(
child
,
child
,
...
@@ -201,7 +201,7 @@ class FToast {
...
@@ -201,7 +201,7 @@ class FToast {
/// _getPostionWidgetBasedOnGravity generates [Positioned] [Widget]
/// _getPostionWidgetBasedOnGravity generates [Positioned] [Widget]
/// based on the gravity [ToastGravity] provided by the user in
/// based on the gravity [ToastGravity] provided by the user in
/// [showToast]
/// [showToast]
_getPostionWidgetBasedOnGravity
(
Widget
child
,
ToastGravity
gravity
)
{
_getPostionWidgetBasedOnGravity
(
Widget
child
,
ToastGravity
?
gravity
)
{
switch
(
gravity
)
{
switch
(
gravity
)
{
case
ToastGravity
.
TOP
:
case
ToastGravity
.
TOP
:
return
Positioned
(
top:
100.0
,
left:
24.0
,
right:
24.0
,
child:
child
);
return
Positioned
(
top:
100.0
,
left:
24.0
,
right:
24.0
,
child:
child
);
...
@@ -230,7 +230,7 @@ class FToast {
...
@@ -230,7 +230,7 @@ class FToast {
break
;
break
;
case
ToastGravity
.
SNACKBAR
:
case
ToastGravity
.
SNACKBAR
:
return
Positioned
(
return
Positioned
(
bottom:
MediaQuery
.
of
(
context
).
viewInsets
.
bottom
,
bottom:
MediaQuery
.
of
(
context
!
).
viewInsets
.
bottom
,
left:
0
,
left:
0
,
right:
0
,
right:
0
,
child:
child
);
child:
child
);
...
@@ -246,8 +246,8 @@ class FToast {
...
@@ -246,8 +246,8 @@ class FToast {
/// each [OverlayEntry] and [Duration] for every toast user
/// each [OverlayEntry] and [Duration] for every toast user
/// triggered
/// triggered
class
_ToastEntry
{
class
_ToastEntry
{
final
OverlayEntry
entry
;
final
OverlayEntry
?
entry
;
final
Duration
duration
;
final
Duration
?
duration
;
_ToastEntry
({
this
.
entry
,
this
.
duration
});
_ToastEntry
({
this
.
entry
,
this
.
duration
});
}
}
...
@@ -255,7 +255,7 @@ class _ToastEntry {
...
@@ -255,7 +255,7 @@ class _ToastEntry {
/// internal [StatefulWidget] which handles the show and hide
/// internal [StatefulWidget] which handles the show and hide
/// animations for [FToast]
/// animations for [FToast]
class
_ToastStateFul
extends
StatefulWidget
{
class
_ToastStateFul
extends
StatefulWidget
{
_ToastStateFul
(
this
.
child
,
this
.
duration
,
{
Key
key
})
:
super
(
key:
key
);
_ToastStateFul
(
this
.
child
,
this
.
duration
,
{
Key
?
key
})
:
super
(
key:
key
);
final
Widget
child
;
final
Widget
child
;
final
Duration
duration
;
final
Duration
duration
;
...
@@ -269,20 +269,20 @@ class ToastStateFulState extends State<_ToastStateFul>
...
@@ -269,20 +269,20 @@ class ToastStateFulState extends State<_ToastStateFul>
with
SingleTickerProviderStateMixin
{
with
SingleTickerProviderStateMixin
{
/// Start the showing animations for the toast
/// Start the showing animations for the toast
showIt
()
{
showIt
()
{
_animationController
.
forward
();
_animationController
!
.
forward
();
}
}
/// Start the hidding animations for the toast
/// Start the hidding animations for the toast
hideIt
()
{
hideIt
()
{
_animationController
.
reverse
();
_animationController
!
.
reverse
();
_timer
?.
cancel
();
_timer
?.
cancel
();
}
}
/// Controller to start and hide the animation
/// Controller to start and hide the animation
AnimationController
_animationController
;
AnimationController
?
_animationController
;
Animation
_fadeAnimation
;
late
Animation
_fadeAnimation
;
Timer
_timer
;
Timer
?
_timer
;
@override
@override
void
initState
()
{
void
initState
()
{
...
@@ -291,7 +291,7 @@ class ToastStateFulState extends State<_ToastStateFul>
...
@@ -291,7 +291,7 @@ class ToastStateFulState extends State<_ToastStateFul>
duration:
const
Duration
(
milliseconds:
350
),
duration:
const
Duration
(
milliseconds:
350
),
);
);
_fadeAnimation
=
_fadeAnimation
=
CurvedAnimation
(
parent:
_animationController
,
curve:
Curves
.
easeIn
);
CurvedAnimation
(
parent:
_animationController
!
,
curve:
Curves
.
easeIn
);
super
.
initState
();
super
.
initState
();
showIt
();
showIt
();
...
@@ -303,7 +303,7 @@ class ToastStateFulState extends State<_ToastStateFul>
...
@@ -303,7 +303,7 @@ class ToastStateFulState extends State<_ToastStateFul>
@override
@override
void
deactivate
()
{
void
deactivate
()
{
_timer
?.
cancel
();
_timer
?.
cancel
();
_animationController
.
stop
();
_animationController
!
.
stop
();
super
.
deactivate
();
super
.
deactivate
();
}
}
...
@@ -317,7 +317,7 @@ class ToastStateFulState extends State<_ToastStateFul>
...
@@ -317,7 +317,7 @@ class ToastStateFulState extends State<_ToastStateFul>
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
FadeTransition
(
return
FadeTransition
(
opacity:
_fadeAnimation
,
opacity:
_fadeAnimation
as
Animation
<
double
>
,
child:
Center
(
child:
Center
(
child:
Material
(
child:
Material
(
color:
Colors
.
transparent
,
color:
Colors
.
transparent
,
...
...
lib/fluttertoast_web.dart
View file @
f829e327
...
@@ -37,7 +37,7 @@ class FluttertoastWebPlugin {
...
@@ -37,7 +37,7 @@ class FluttertoastWebPlugin {
/// it to [addHtmlToast]
/// it to [addHtmlToast]
showToast
(
args
)
{
showToast
(
args
)
{
String
msg
=
args
[
'msg'
];
String
msg
=
args
[
'msg'
];
String
gravity
=
"top"
;
String
?
gravity
=
"top"
;
if
(
args
[
'gravity'
]
==
"top"
||
args
[
'gravity'
]
==
"bottom"
)
{
if
(
args
[
'gravity'
]
==
"top"
||
args
[
'gravity'
]
==
"bottom"
)
{
gravity
=
args
[
"gravity"
];
gravity
=
args
[
"gravity"
];
}
}
...
@@ -47,7 +47,7 @@ class FluttertoastWebPlugin {
...
@@ -47,7 +47,7 @@ class FluttertoastWebPlugin {
String
bgColor
=
String
bgColor
=
args
[
'webBgColor'
]
??
"linear-gradient(to right, #00b09b, #96c93d)"
;
args
[
'webBgColor'
]
??
"linear-gradient(to right, #00b09b, #96c93d)"
;
int
textColor
=
args
[
'textcolor'
];
int
?
textColor
=
args
[
'textcolor'
];
int
time
=
args
[
'time'
]
==
null
int
time
=
args
[
'time'
]
==
null
?
3000
?
3000
...
@@ -82,7 +82,7 @@ class FluttertoastWebPlugin {
...
@@ -82,7 +82,7 @@ class FluttertoastWebPlugin {
..
src
=
"assets/packages/fluttertoast/assets/toastify.js"
;
..
src
=
"assets/packages/fluttertoast/assets/toastify.js"
;
loading
.
add
(
script
.
onLoad
.
first
);
loading
.
add
(
script
.
onLoad
.
first
);
tags
.
add
(
script
);
tags
.
add
(
script
);
html
.
querySelector
(
'head'
).
children
.
addAll
(
tags
);
html
.
querySelector
(
'head'
)
!
.
children
.
addAll
(
tags
);
await
Future
.
wait
(
loading
);
await
Future
.
wait
(
loading
);
}
}
...
@@ -91,14 +91,14 @@ class FluttertoastWebPlugin {
...
@@ -91,14 +91,14 @@ class FluttertoastWebPlugin {
/// make toast visible on web
/// make toast visible on web
addHtmlToast
(
addHtmlToast
(
{
String
msg
=
""
,
{
String
msg
=
""
,
String
gravity
=
"top"
,
String
?
gravity
=
"top"
,
String
position
=
"right"
,
String
position
=
"right"
,
String
bgcolor
=
"linear-gradient(to right, #00b09b, #96c93d)"
,
String
bgcolor
=
"linear-gradient(to right, #00b09b, #96c93d)"
,
int
time
=
3000
,
int
time
=
3000
,
bool
showClose
=
false
,
bool
showClose
=
false
,
int
textColor
})
{
int
?
textColor
})
{
String
m
=
msg
.
replaceAll
(
"'"
,
"
\\
'"
).
replaceAll
(
"
\n
"
,
"<br />"
);
String
m
=
msg
.
replaceAll
(
"'"
,
"
\\
'"
).
replaceAll
(
"
\n
"
,
"<br />"
);
html
.
Element
ele
=
html
.
querySelector
(
"#toast-content"
);
html
.
Element
?
ele
=
html
.
querySelector
(
"#toast-content"
);
String
content
=
"""
String
content
=
"""
var toastElement = Toastify({
var toastElement = Toastify({
text: '
$m
',
text: '
$m
',
...
@@ -111,14 +111,14 @@ class FluttertoastWebPlugin {
...
@@ -111,14 +111,14 @@ class FluttertoastWebPlugin {
toastElement.showToast();
toastElement.showToast();
"""
;
"""
;
if
(
html
.
querySelector
(
"#toast-content"
)
!=
null
)
{
if
(
html
.
querySelector
(
"#toast-content"
)
!=
null
)
{
ele
.
remove
();
ele
!
.
remove
();
}
}
final
html
.
ScriptElement
scriptText
=
html
.
ScriptElement
()
final
html
.
ScriptElement
scriptText
=
html
.
ScriptElement
()
..
id
=
"toast-content"
..
id
=
"toast-content"
..
innerHtml
=
content
;
..
innerHtml
=
content
;
html
.
querySelector
(
'head'
).
children
.
add
(
scriptText
);
html
.
querySelector
(
'head'
)
!
.
children
.
add
(
scriptText
);
if
(
textColor
!=
null
)
{
if
(
textColor
!=
null
)
{
html
.
Element
toast
=
html
.
querySelector
(
'.toastify'
);
html
.
Element
toast
=
html
.
querySelector
(
'.toastify'
)
!
;
String
tcRadix
=
textColor
.
toRadixString
(
16
);
String
tcRadix
=
textColor
.
toRadixString
(
16
);
final
String
tC
=
"
${tcRadix.substring(2)}${tcRadix.substring(0, 2)}
"
;
final
String
tC
=
"
${tcRadix.substring(2)}${tcRadix.substring(0, 2)}
"
;
toast
.
style
.
setProperty
(
'color'
,
"#
$tC
"
);
toast
.
style
.
setProperty
(
'color'
,
"#
$tC
"
);
...
...
pubspec.lock
View file @
f829e327
...
@@ -59,5 +59,5 @@ packages:
...
@@ -59,5 +59,5 @@ packages:
source: hosted
source: hosted
version: "2.1.0"
version: "2.1.0"
sdks:
sdks:
dart: ">=2.12.0
-0
<3.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.10.0"
flutter: ">=1.10.0"
pubspec.yaml
View file @
f829e327
...
@@ -5,7 +5,7 @@ homepage: https://github.com/PonnamKarthik/FlutterToast
...
@@ -5,7 +5,7 @@ homepage: https://github.com/PonnamKarthik/FlutterToast
issue_tracker
:
https://github.com/ponnamkarthik/FlutterToast/issues
issue_tracker
:
https://github.com/ponnamkarthik/FlutterToast/issues
environment
:
environment
:
sdk
:
"
>=2.7.0
<3.0.0"
sdk
:
'
>=2.12.0
<3.0.0'
flutter
:
"
>=1.10.0"
flutter
:
"
>=1.10.0"
dependencies
:
dependencies
:
...
...
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