Skip to content

Commit

Permalink
fix(web): get css & js urls using flutter utility (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-mazhnik committed Jul 12, 2023
1 parent ab0537b commit 00a0304
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/fluttertoast_web.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:html' as html;
import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

Expand Down Expand Up @@ -70,16 +71,24 @@ class FluttertoastWebPlugin {
final List<Future<void>> loading = <Future<void>>[];
final List<html.HtmlElement> tags = <html.HtmlElement>[];

// ignore: undefined_prefixed_name
final cssUrl = ui.webOnlyAssetManager.getAssetUrl(
'packages/fluttertoast/assets/toastify.css',
);
final html.LinkElement css = html.LinkElement()
..id = 'toast-css'
..attributes = {"rel": "stylesheet"}
..href = 'assets/packages/fluttertoast/assets/toastify.css';
..href = cssUrl;
tags.add(css);

// ignore: undefined_prefixed_name
final jsUrl = ui.webOnlyAssetManager.getAssetUrl(
'packages/fluttertoast/assets/toastify.js',
);
final html.ScriptElement script = html.ScriptElement()
..async = true
// ..defer = true
..src = "assets/packages/fluttertoast/assets/toastify.js";
..src = jsUrl;
loading.add(script.onLoad.first);
tags.add(script);
html.querySelector('head')!.children.addAll(tags);
Expand Down

0 comments on commit 00a0304

Please sign in to comment.