r/FlutterDev • u/EngineerScientist • Apr 29 '20
Article Flutter web support updates
https://medium.com/flutter/flutter-web-support-updates-8b14bfe6a9088
u/martej Apr 29 '20
I’ve been doing flutter mobile for about six months now and I’m pumped to try my hand at making a pwa. I imagine the transition is not that hard, but can you suggest a video or resource to get me started?
15
u/SladeBrockett Apr 29 '20 edited Apr 29 '20
if you've been flutter mobile for that long, you're already 99% of the way there. It's exactly the same as far as coding goes, however, there are a couple of differences that you have to keep in mind.
For setup, there are some minor differences, notable that you have to run flutter config --enable-web as spelled out here: https://flutter.dev/docs/get-started/web
For debugging, it was a little tricky because debugging wasn't supported in chrome in vscode, so you had to debug in android studio, or debug the code on a mobile device (simulator or real) in order to put in breakpoints. HOWEVER, in the medium article referenced in this post, they indicated that you can now do that by adding "args": ["--web-enable-expression-evaluation"], to your launch.json.
Plugins are a little dicey right now. 80% of the time when it says it works for web, it actually does. However, I keep running in to little 'gotchas' here and there. So, anytime I have to use a plugin, I make sure that it works in a variety of situations instead of just trusting that it will.
flutter-html mashup: One of the big work-arounds that I'm using right now is to always keep in the back of my mind the fact that html is still a possibility, even if flutter doesn't work 100%. Therefore, when I get stuck on something using flutter, I shift to using html concepts. For example, I had a really hard time displaying pdfs created in the app using plugins because they were only geared to have a mobile File object, an asset object, or a network object as the source. The solution ended up being using the 'package:universal_html/html.dart' plugin to manipulate html, like this:
import 'package:universal_html/html.dart' as html; <-- the package I used
html.Blob blob = html.Blob(<dynamic>[pdfFile], 'application/pdf');
final url = html.Url.createObjectUrlFromBlob(blob);
html.window.open(url, "_blank");
html.Url.revokeObjectUrl(url);My point is, when you get stuck, don't forget that html is still available. (however, this particular example has been the only time that I really needed to use it.)
Also, a difference to keep in mind is on mobile devices, you have access to the file structure. On flutter web, you don't. Therefore, instead of saving files to the device, you have to use something like sqflite or hive for long term storage.
Finally, I wouldn't bother learning pwa with flutter since flutter web is new, but the requirements/knowledge for pwa are the identical. (namely, the manifest.json file and how to troubleshoot during development) One of the best tutorials I've seen for PWA is this series: https://www.youtube.com/watch?v=4XT23X0Fjfk . Despite the fact that it's not written for flutter, all of the PWA-specific items are identical between flutter web and html/javascript... so it's useful in both worlds.
Edit: I tried out the "--web-enable-expression-evaluation" that's supposed to allow debugging for vscode. yeah... still not quite there. It looks like I'll still have to use the device simulator in order to use breakpoints effectively.
4
u/timsneath Apr 29 '20
If you're running from the
beta,devormasterchannels, you can build for the web by following the instructions on the Flutter web support page.flutter createautomatically includes the manifest and scripts needed to register as a PWA. More details on customizing your PWA manifest are here: https://web.dev/progressive-web-apps/
7
u/Early_Unit Apr 30 '20
Coming from web development, I wasn't so excited about flutter web, but now I realize how much work has been done by flutter. If you think about it twitter, reddit and many other big "web apps" these days are just blank html files that load 10MB of reactjs to render data on dom. We're stretching the limits of what's possible with js and the dom, so why don't we just throw it away and use a better and faster rendering engine ? I don't think that flutter web is ready or better than html/css/js today, but i find it interesting that dart on web is exploring new paths and doesn't try to be Google's Typescript.
6
u/killingbanana Apr 30 '20
I wish Flutter Web apps felt more "native". Things like native scrolling, selectable text, native links (middle click..., right clicks...), right click menus etc.
3
2
0
24
u/pc52 Apr 29 '20
I really look forward to the new Flutter release from this week!