1
1
import 'dart:async' ;
2
- import 'dart:html ' as html ;
2
+ import 'package:web/web.dart ' as web ;
3
3
import 'dart:ui_web' as ui;
4
4
import 'package:flutter/services.dart' ;
5
5
import 'package:flutter_web_plugins/flutter_web_plugins.dart' ;
@@ -69,27 +69,29 @@ class FluttertoastWebPlugin {
69
69
/// [injectCssAndJSLibraries] which add the JS and CSS files into DOM
70
70
Future <void > injectCssAndJSLibraries () async {
71
71
final List <Future <void >> loading = < Future <void >> [];
72
- final List <html. HtmlElement > tags = < html. HtmlElement > [];
72
+ final List <web. HTMLElement > tags = < web. HTMLElement > [];
73
73
74
74
final cssUrl = ui.assetManager.getAssetUrl (
75
75
'packages/fluttertoast/assets/toastify.css' ,
76
76
);
77
- final html. LinkElement css = html. LinkElement ()
77
+ final web. HTMLLinkElement css = web. HTMLLinkElement ()
78
78
..id = 'toast-css'
79
- ..attributes = { "rel" : "stylesheet" }
79
+ ..setAttribute ( "rel" , "stylesheet" )
80
80
..href = cssUrl;
81
81
tags.add (css);
82
-
82
+
83
83
final jsUrl = ui.assetManager.getAssetUrl (
84
84
'packages/fluttertoast/assets/toastify.js' ,
85
85
);
86
- final html. ScriptElement script = html. ScriptElement ()
86
+ final web. HTMLScriptElement script = web. HTMLScriptElement ()
87
87
..async = true
88
88
// ..defer = true
89
89
..src = jsUrl;
90
90
loading.add (script.onLoad.first);
91
91
tags.add (script);
92
- html.querySelector ('head' )! .children.addAll (tags);
92
+ for (final web.HTMLElement tag in tags) {
93
+ web.document.querySelector ('head' )! .append (tag);
94
+ }
93
95
94
96
await Future .wait (loading);
95
97
}
@@ -105,7 +107,7 @@ class FluttertoastWebPlugin {
105
107
bool showClose = false ,
106
108
int ? textColor}) {
107
109
String m = msg.replaceAll ("'" , "\\ '" ).replaceAll ("\n " , "<br />" );
108
- html .Element ? ele = html .querySelector ("#toast-content" );
110
+ web .Element ? ele = web.document .querySelector ("#toast-content" );
109
111
String content = """
110
112
var toastElement = Toastify({
111
113
text: '$m ',
@@ -117,18 +119,19 @@ class FluttertoastWebPlugin {
117
119
});
118
120
toastElement.showToast();
119
121
""" ;
120
- if (html .querySelector ("#toast-content" ) != null ) {
122
+ if (web.document .querySelector ("#toast-content" ) != null ) {
121
123
ele! .remove ();
122
124
}
123
- final html. ScriptElement scriptText = html. ScriptElement ()
125
+ final web. HTMLScriptElement scriptText = web. HTMLScriptElement ()
124
126
..id = "toast-content"
125
- ..innerHtml = content;
126
- html. querySelector ( 'head' ) ! .children. add (scriptText);
127
+ ..innerHTML = content;
128
+ web.document.body ! . append (scriptText);
127
129
if (textColor != null ) {
128
- html .Element toast = html .querySelector ('.toastify' )! ;
130
+ web .Element toast = web.document .querySelector ('.toastify' )! ;
129
131
String tcRadix = textColor.toRadixString (16 );
130
132
final String tC = "${tcRadix .substring (2 )}${tcRadix .substring (0 , 2 )}" ;
131
- toast.style.setProperty ('color' , "#$tC " );
133
+ final style = toast.getAttribute ('style' ) ?? '' ;
134
+ toast.setAttribute ('style' , '$style color: #$tC ;' );
132
135
}
133
136
}
134
137
}
0 commit comments