Skip to content

Commit

Permalink
minor updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ponnamkarthik committed Jul 30, 2020
1 parent cdb4c96 commit 040e203
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions lib/fluttertoast_web.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import 'dart:async';
import 'dart:html' as html;
import 'dart:ui' as ui;
import 'dart:js' as js;
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

class FluttertoastWebPlugin {

FluttertoastWebPlugin() {
injectCssAndJSLibraries();
}

static void registerWith(Registrar registrar) {
final MethodChannel channel =
MethodChannel('PonnamKarthik/fluttertoast', const StandardMethodCodec(), registrar.messenger);
final MethodChannel channel = MethodChannel('PonnamKarthik/fluttertoast', const StandardMethodCodec(), registrar.messenger);
final FluttertoastWebPlugin instance = FluttertoastWebPlugin();
channel.setMethodCallHandler(instance.handleMethodCall);
}
Expand All @@ -33,10 +29,10 @@ class FluttertoastWebPlugin {
}
}

Future<void> showToast(args) {
showToast(args) {
String msg = args['msg'];
String gravity = "top";
if(args['gravity'] == "top" || args['gravity'] == "bottom") {
if (args['gravity'] == "top" || args['gravity'] == "bottom") {
gravity = args["gravity"];
}

Expand All @@ -56,25 +52,31 @@ class FluttertoastWebPlugin {
final List<html.HtmlElement> tags = <html.HtmlElement>[];

final html.StyleElement css = html.StyleElement()
..id = 'toast-css'
..appendText("@import url('https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css');");
tags.add(css);
..id = 'toast-css'
..appendText("@import url('https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css');");
tags.add(css);

final html.ScriptElement script = html.ScriptElement()
..async = true
..defer = true
..src = "https://cdn.jsdelivr.net/npm/toastify-js";
loading.add(script.onLoad.first);
tags.add(script);
..async = true
..defer = true
..src = "https://cdn.jsdelivr.net/npm/toastify-js";
loading.add(script.onLoad.first);
tags.add(script);
html.querySelector('head').children.addAll(tags);

await Future.wait(loading);

// addHtmlToast();
// addHtmlToast();
}

addHtmlToast({String msg = "", String gravity = "top", String position = "right", String bgcolor = "linear-gradient(to right, #00b09b, #96c93d)", int time = 3000, bool showClose = false}) {
addHtmlToast(
{String msg = "",
String gravity = "top",
String position = "right",
String bgcolor = "linear-gradient(to right, #00b09b, #96c93d)",
int time = 3000,
bool showClose = false}) {
print(html.querySelector("#toast-content"));
html.Element ele = html.querySelector("#toast-content");
String content = """
Expand All @@ -88,16 +90,12 @@ class FluttertoastWebPlugin {
});
toastElement.showToast();
""";
if(html.querySelector("#toast-content") != null) {
if (html.querySelector("#toast-content") != null) {
ele.remove();
}
final html.ScriptElement scriptText = html.ScriptElement()
..id = "toast-content"
..innerHtml = content;
html.querySelector('head').children.add(scriptText);

final html.ScriptElement scriptText = html.ScriptElement()
..id = "toast-content"
..innerHtml = content;
html.querySelector('head').children.add(scriptText);
}

}


0 comments on commit 040e203

Please sign in to comment.