fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.62k stars 989 forks source link

[Bug]: device_info_plus breaks on build web --release --dart2js-optimization O4 #971

Open nikto-b opened 2 years ago

nikto-b commented 2 years ago

Platform

Web

Plugin

device_info_plus

Version

4.0.1

Flutter SDK

3.1.0-9.0.pre

Steps to reproduce

  1. Invoke webBrowserInfo getter in any way
                    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
                    final info = await deviceInfo.deviceInfo;
                    final map = info.toMap();
  2. Build release
    $ flutter build web --release --dart2js-optimization O4 --web-renderer html
  3. Catch UnimplementedError UnimplementedError: webBrowserInfo() has not been implemented.

Code Sample

No response

Logs

There is no way to run with `--release` and `--dart2js-optimization O4` flags, but here is web console logs:

Uncaught UnimplementedError: webBrowserInfo() has not been implemented.
    at Object.c (main.dart.js:3455:3)
    at Z2.ab3 (main.dart.js:35015:15)
    at main.dart.js:35000:15
    at aea.a (main.dart.js:4635:63)
    at aea.$2 (main.dart.js:30376:14)
    at Object.Y (main.dart.js:4621:10)
    at E0.gvt (main.dart.js:35005:10)
    at main.dart.js:35008:33
    at aea.a (main.dart.js:4635:63)
    at aea.$2 (main.dart.js:30376:14)
c   @   main.dart.js:3455
ash @   main.dart.js:5412
v6  @   main.dart.js:5505
$0  @   main.dart.js:30920
axj @   main.dart.js:4751
axt @   main.dart.js:4753
$1  @   main.dart.js:30320
ayX @   main.dart.js:3536
(anonymous) @   main.dart.js:3544
childList (async)       
$1  @   main.dart.js:30327
an2 @   main.dart.js:4758
ow  @   main.dart.js:4819
eV  @   main.dart.js:4770
IQ  @   main.dart.js:37594
o6  @   main.dart.js:37592
P   @   main.dart.js:38553
tM  @   main.dart.js:38314
hv  @   main.dart.js:38575
xH  @   main.dart.js:38323
jO  @   main.dart.js:38284
(anonymous) @   main.dart.js:3577
Vd  @   main.dart.js:38497
$2  @   main.dart.js:38509
a8  @   main.dart.js:30021
Fs  @   main.dart.js:38504
Nw  @   main.dart.js:38502
hV  @   main.dart.js:37650
Ah  @   main.dart.js:37644
Ah  @   main.dart.js:56684
Gm  @   main.dart.js:37638
a7a @   main.dart.js:37627
xt  @   main.dart.js:37625
Yc  @   main.dart.js:37621
(anonymous) @   main.dart.js:3577
QU  @   main.dart.js:966
a_z @   main.dart.js:25402
(anonymous) @   main.dart.js:3577
$1  @   main.dart.js:25577
$1  @   main.dart.js:25540
$1  @   main.dart.js:25416
ayX @   main.dart.js:3536
(anonymous) @   main.dart.js:3544

### Flutter Doctor

```shell
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, 3.1.0-9.0.pre, on Arch Linux 5.18.9, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.2)
[✓] IntelliJ IDEA Community Edition (version 2022.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!
miquelbeltran commented 2 years ago

Just to confirm, this doesn't happen on debug, correct?

Does it happen when you remove the dart2js optimization?

Does it happen with other levels of optimization?

I don't fully know what dart2js-optimization does, but I suspect that what is happening is that DeviceInfoPlusPlugin class from device_info_plus_web.dart gets lost during the optimization.

nikto-b commented 2 years ago

Just to confirm, this doesn't happen on debug, correct?

Does it happen when you remove the dart2js optimization?

Does it happen with other levels of optimization?

I don't fully know what dart2js-optimization does, but I suspect that what is happening is that DeviceInfoPlusPlugin class from device_info_plus_web.dart gets lost during the optimization.

AFAIK, dart2js optimizations can cut off some parts of generated JS code, this can cause problems with DI (google_maps_flutter was optimized-out in release builds for android about year ago, for example)

miquelbeltran commented 2 years ago

Thanks for the info! Just in case, the issue you mention is about Java Proguard optimizations on Android, not the dart2js optimization.

billthecoder046 commented 1 year ago

Facing the same issue. Can't access the browser info in release mode but can in debug mode.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

mr-stan-dev commented 5 months ago

Facing the same issue. No flags. Just with flutter build web --release

NITK10CA49 commented 3 months ago

i am also facing the same issue. Can't access the browser info in release mode but can in debug mode. This issue raised in july 2022, its 2 years. Is this issue going to be fixed? or is it working fine with any other older versions. If it is not supported by web,i am requesting you to remove that support in pub.dev Thanks Team for your support

miquelbeltran commented 3 months ago

This is a community effort, there are no companies behind this project, and it is purely voluntary based.

Unfortunately, this seems to need special knowledge on the dart2js compiler, which no one in the maintainer team has, so external help is definitely needed.

miquelbeltran commented 3 months ago

Btw, a message says it works with the O2 optimization, so did you try with the --dart2js-optimization O2 flag?

If anyone can check the different optimization levels from O0 to O4 and report back, that would be very useful, and we can add that to the README

NITK10CA49 commented 3 months ago

i am doing with flutter build web --web-renderer canvaskit, i am not sure purpose above optimisation

miquelbeltran commented 3 months ago

I ran flutter build web --web-renderer canvaskit on the device_info_plus example project, then went to build/web and started a web server with python3 -m http.server, then I opened http://0.0.0.0:8000/ on my browser.

The app loads correctly.

I repeated the same process with flutter build web --release and I couldn't reproduce the issue.

I cleaned the project to ensure the build folder was empty, and then run flutter build web --release --dart2js-optimization O4 with the highest level of optimization, then I run the project and I couldn't reproduce the issue.

Tested again with flutter build web --release --dart2js-optimization O4 --web-renderer html matching the original post just in case and no issues.

If you still have this issue, please provide a repo with that reproduces the error.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days