flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.31k stars 398 forks source link

Add flet build web --wasm (now available in flutter) #3069

Open hololeo opened 2 months ago

hololeo commented 2 months ago

Part of this comment (Tasks) was written by the flet-dev Team

More info: https://docs.flutter.dev/platform-integration/web/wasm

Tasks for WASM support

Based on @ndonkoHenri build log below (thank you!) I can see the following changes to support WASM:

Original Comment

Please add Flutter build web --wasm support to flet

Very exciting changes to Flutter web. It supports compiling main.dart.js into wasm and the skia engine.

The download size is dramatically reduced from 30 megs to 6 megs, and much faster start up of less than 3 seconds vs 10+. see https://docs.flutter.dev/platform-integration/web/wasm

example you can try right now

https://flutterweb-wasm.web.app/

i have tested this on my old iphone6 and it works extremely well

Watch this recent video of the announcement. it is in beta and available as of writing. linked to relevant talk

youtube talk about flutter web wasm

Please include this in Flet so our Flet web pyiode deploys can get much smaller and faster!

Screenshot 2024-04-20 at 9 56 56 PM

hololeo commented 2 months ago

this may also be helpful

Requires JS-interop to access browser and JS APIs
#
To support compilation to Wasm, Dart has shifted how it enables interop with browser and JavaScript APIs. This shift prevents Dart code that uses dart:html or package:js from compiling to Wasm.

Instead, Dart now provides new, lightweight interop solutions built around static JS interop:

package:web, which replaces dart:html (and other web libraries)
dart:js_interop, which replaces package:js and dart:js

https://dart.dev/interop/js-interop

hololeo commented 2 months ago

errors encountered by @ndonkoHenri

https://github.com/ndonkoHenri/test-flet-github-actions/actions/runs/8772266592/job/24071006981#step:6:656


package:flet/src/controls/checkbox.dart => 
package:flet/src/controls/cupertino_checkbox.dart => 
package:flet/src/controls/list_tile.dart => package:flet/src/utils/text.dart => 
package:flet/src/utils/launch_url.dart => 
package:flet/src/utils/platform_utils_web.dart => dart:html
    ...

/home/runner/.pub-cache/hosted/pub.dev/package_info_plus-4.2.0/lib/src/package_i
nfo_plus_web.dart:2:8: Error: Dart library 'dart:html' is not available on this 
platform.
import 'dart:html';
       ^
/home/runner/.pub-cache/hosted/pub.dev/flet-0.22.0/lib/src/utils/platform_utils_
web.dart:2:8: Error: Dart library 'dart:html' is not available on this platform.
import 'dart:html' as html;
FeodorFitsner commented 2 months ago

Wow, that looks like a future!

Btw, it's possible to add --wasm option even today with https://flet.dev/docs/publish#extra-args-to-flutter-build-command (provided package_info_plus is fixed or mocked).

FeodorFitsner commented 2 months ago

Re package_info_plus - look at two last FEAT items, we need to upgrade to 6.0: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/CHANGELOG.md#600

ndonkoHenri commented 2 months ago

Btw, it's possible to add --wasm option even today

Yeah, I tried that: https://github.com/ndonkoHenri/test-flet-github-actions/actions/runs/8772266592/job/24071006981#step:6:5 (Make sure to use either the beta or main channel, cause that's where that flag is available for now)

What's package_info_plus? Have we being using it?

I could perhaps be of help in the package migrations.