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
4fef9001
Unverified
Commit
4fef9001
authored
Jun 03, 2024
by
AmirHossein Mohammadazadeh
Committed by
GitHub
Jun 03, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrating dart:html to package:web (#507)
parent
2d872ebc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
17 deletions
+37
-17
example/pubspec.lock
+10
-2
lib/fluttertoast_web.dart
+17
-14
pubspec.lock
+9
-1
pubspec.yaml
+1
-0
No files found.
example/pubspec.lock
View file @
4fef9001
...
...
@@ -78,7 +78,7 @@ packages:
path: ".."
relative: true
source: path
version: "8.2.
3
"
version: "8.2.
5
"
leak_tracker:
dependency: transitive
description:
...
...
@@ -204,6 +204,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
sdks:
dart: ">=3.
2.0-
0 <4.0.0"
dart: ">=3.
3.
0 <4.0.0"
flutter: ">=1.10.0"
lib/fluttertoast_web.dart
View file @
4fef9001
import
'dart:async'
;
import
'
dart:html'
as
html
;
import
'
package:web/web.dart'
as
web
;
import
'dart:ui_web'
as
ui
;
import
'package:flutter/services.dart'
;
import
'package:flutter_web_plugins/flutter_web_plugins.dart'
;
...
...
@@ -69,27 +69,29 @@ class FluttertoastWebPlugin {
/// [injectCssAndJSLibraries] which add the JS and CSS files into DOM
Future
<
void
>
injectCssAndJSLibraries
()
async
{
final
List
<
Future
<
void
>>
loading
=
<
Future
<
void
>>[];
final
List
<
html
.
HtmlElement
>
tags
=
<
html
.
Html
Element
>[];
final
List
<
web
.
HTMLElement
>
tags
=
<
web
.
HTML
Element
>[];
final
cssUrl
=
ui
.
assetManager
.
getAssetUrl
(
'packages/fluttertoast/assets/toastify.css'
,
);
final
html
.
LinkElement
css
=
html
.
LinkElement
()
final
web
.
HTMLLinkElement
css
=
web
.
HTML
LinkElement
()
..
id
=
'toast-css'
..
attributes
=
{
"rel"
:
"stylesheet"
}
..
setAttribute
(
"rel"
,
"stylesheet"
)
..
href
=
cssUrl
;
tags
.
add
(
css
);
final
jsUrl
=
ui
.
assetManager
.
getAssetUrl
(
'packages/fluttertoast/assets/toastify.js'
,
);
final
html
.
ScriptElement
script
=
html
.
ScriptElement
()
final
web
.
HTMLScriptElement
script
=
web
.
HTML
ScriptElement
()
..
async
=
true
// ..defer = true
..
src
=
jsUrl
;
loading
.
add
(
script
.
onLoad
.
first
);
tags
.
add
(
script
);
html
.
querySelector
(
'head'
)!.
children
.
addAll
(
tags
);
for
(
final
web
.
HTMLElement
tag
in
tags
)
{
web
.
document
.
querySelector
(
'head'
)!.
append
(
tag
);
}
await
Future
.
wait
(
loading
);
}
...
...
@@ -105,7 +107,7 @@ class FluttertoastWebPlugin {
bool
showClose
=
false
,
int
?
textColor
})
{
String
m
=
msg
.
replaceAll
(
"'"
,
"
\\
'"
).
replaceAll
(
"
\n
"
,
"<br />"
);
html
.
Element
?
ele
=
html
.
querySelector
(
"#toast-content"
);
web
.
Element
?
ele
=
web
.
document
.
querySelector
(
"#toast-content"
);
String
content
=
"""
var toastElement = Toastify({
text: '
$m
',
...
...
@@ -117,18 +119,19 @@ class FluttertoastWebPlugin {
});
toastElement.showToast();
"""
;
if
(
html
.
querySelector
(
"#toast-content"
)
!=
null
)
{
if
(
web
.
document
.
querySelector
(
"#toast-content"
)
!=
null
)
{
ele
!.
remove
();
}
final
html
.
ScriptElement
scriptText
=
html
.
ScriptElement
()
final
web
.
HTMLScriptElement
scriptText
=
web
.
HTML
ScriptElement
()
..
id
=
"toast-content"
..
innerH
tml
=
content
;
html
.
querySelector
(
'head'
)!.
children
.
ad
d
(
scriptText
);
..
innerH
TML
=
content
;
web
.
document
.
body
!.
appen
d
(
scriptText
);
if
(
textColor
!=
null
)
{
html
.
Element
toast
=
html
.
querySelector
(
'.toastify'
)!;
web
.
Element
toast
=
web
.
document
.
querySelector
(
'.toastify'
)!;
String
tcRadix
=
textColor
.
toRadixString
(
16
);
final
String
tC
=
"
${tcRadix.substring(2)}${tcRadix.substring(0, 2)}
"
;
toast
.
style
.
setProperty
(
'color'
,
"#
$tC
"
);
final
style
=
toast
.
getAttribute
(
'style'
)
??
''
;
toast
.
setAttribute
(
'style'
,
'
$style
color: #
$tC
;'
);
}
}
}
pubspec.lock
View file @
4fef9001
...
...
@@ -56,6 +56,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: "direct main"
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
sdks:
dart: ">=3.
2.0-
0 <4.0.0"
dart: ">=3.
3.
0 <4.0.0"
flutter: ">=1.10.0"
pubspec.yaml
View file @
4fef9001
...
...
@@ -13,6 +13,7 @@ dependencies:
sdk
:
flutter
flutter_web_plugins
:
sdk
:
flutter
web
:
^0.5.1
flutter
:
plugin
:
...
...
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