ponnamkarthik / FlutterToast

Toast Plugin for Flutter
MIT License
1.44k stars 357 forks source link

Flutter web Uncaught ReferenceError: Toastify is not defined #252

Closed shatanikmahanty closed 3 years ago

shatanikmahanty commented 3 years ago

I get this error on launching from hosted website :

Uncaught SyntaxError: Unexpected token '<' packages/fluttertoast/assets/toastify.js:1 when website is first loaded

On trying to show a toast : Uncaught ReferenceError: Toastify is not defined at :1:30 at O6.H (main.dart.js?version=104:35837) at main.dart.js?version=104:72768 at ano.a (main.dart.js?version=104:4478) at ano.$2 (main.dart.js?version=104:32705) at Object.R (main.dart.js?version=104:4464) at I1.acF (main.dart.js?version=104:72779) at I1.CY (main.dart.js?version=104:72743) at Object.eval (eval at atx (main.dart.js?version=104:3146), :3:35) at main.dart.js?version=104:61826

It started to happen only after I migrated to 7.1.4 from 7.0.4 also this doesnot happen on debug mode in localhost

manhtuan1712 commented 3 years ago

I get this error too

shatanikmahanty commented 3 years ago

I get this error too

When did this issue start happening for you?

gsvano commented 3 years ago

Hi! This issue produced in dev branch of flutter when run production build for web. Assets aren't included in result build and has absolute path from root of site - this is not good too, because application can be placed in other path, eg https://site.com/test/

shatanikmahanty commented 3 years ago

I am using beta channel which is required for Flutter web

gsvano commented 3 years ago

Ok. I'll try to reproduce this bug in beta channel.

gsvano commented 3 years ago

Unfortunately, this issue reproduce for beta channel too.

C:\Work\showthis_client_flutter>flutter upgrade
Flutter is already up to date on channel beta
Flutter 1.24.0-10.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 022b333a08 (8 days ago) • 2020-11-18 11:35:09 -0800
Engine • revision 07c1eed46b
Tools • Dart 2.12.0 (build 2.12.0-29.10.beta)

C:\Work\showthis_client_flutter>flutter clean
Deleting build...                                                   6,0s
Deleting .dart_tool...                                               9ms
Deleting Generated.xcconfig...                                       1ms
Deleting flutter_export_environment.sh...                            0ms
Deleting ephemeral...                                                2ms
Deleting .flutter-plugins-dependencies...                            0ms
Deleting .flutter-plugins...                                         0ms

C:\Work\showthis_client_flutter>flutter pub get
Running "flutter pub get" in showthis_client_flutter...            991ms

C:\Work\showthis_client_flutter>flutter build web
Running "flutter pub get" in showthis_client_flutter...            606ms
Compiling lib\main.dart for the Web...                             30,1s

C:\Work\showthis_client_flutter>

So... I can't found toastify assets in build/web folder. I can't understand why...

And probably for html.ScriptElement and html.LinkElement you should add "assets" to start of path without slash, because first slash is path to root of domain.

fluttertoast_web.dart
      ..href = 'assets/packages/fluttertoast/assets/toastify.css';
...
      ..src = "assets/packages/fluttertoast/assets/toastify.js";
shatanikmahanty commented 3 years ago

Thanks for testing it @gsvano. Is there any work around for this as of now

gsvano commented 3 years ago

Ok, I make pull request to fix it: #253 Don't forget update version.

shatanikmahanty commented 3 years ago

Thank you so much @gsvano . Surely I will check it out and let you know if its working once it is out on pub.dev .

ponnamkarthik commented 3 years ago

@gsvano Thanks for PR. Its live in pub.dev 7.1.5

shatanikmahanty commented 3 years ago

The update worked for me, a big thanks to Ivan for making it happen and Karthik for pushing the update.

I had to perform a flutter clean then flutter pub get and flutter build web for flutter to include assets in build. If anyone else is facing issues after upgrade please make sure to perform flutter clean. Happy Coding .