SlideShare a Scribd company logo
1 of 64
hello web
@rihanna_ke
@rihanna_ke
Bringing to web
Today’s talk
for web??
Code-compatible implementation
rendered using standard-based web
technologies
@rihanna_ke
$ flutter channel beta
$ flutter upgrade
$ flutter config --enable-web
Set up
- SDK installed > 1.12
- Chrome
flutter.dev/docs/get-started/web
Create and run
flutter.dev/docs/get-started/web
$ flutter run -d chrome
$ flutter create myapp
Add web support for existing app
@rihanna_ke
$ flutter create . $ flutter run -d chrome
While developing for Debug?
Use Flutter DevTools for the following tasks:
● Debugging
● Logging
● Running Flutter inspector
Use Chrome DevTools for the following tasks:
● Generating event timeline
● Analyzing performance— after building!
flutter.dev/docs/development/platform-integration/web
https://medium.com/flutter/flutter-web-support-updates-8b14bfe6a908
Build
flutter.dev/docs/get-started/web
$ flutter build web
/build/web
assets/
icons/
favicon.png
favicon.ico
flutter_service_worker.js
manifest.json
index.html
main.dart.js
main.dart.js.map
05/2017
o5/201912/2018
for web technical preview
12/2019
for web beta
@rihanna_ke
Not recommended for production!!!
DomCanvas vs CanvasKit
@rihanna_ke
https://medium.com/flutter/flutter-web-support-updates-8b14bfe6a908
https://github.com/flutter/flutter_web/blob/master/docs/canvaskit.md
- HTML, CSS, Canvas API
- default
- poorer repaint
performance
- compact size
- greatest stability
- Brings Skia to the web
using WebAssembly and
WebGL
- complex & intensive
graphics
- few rough edges
$ flutter run -d chrome --release
--dart-define=FLUTTER_USE_SKIA=true
Flutter Mobile vs Flutter for Web
@rihanna_ke https://medium.com/flutter/hummingbird-building-flutter-for-the-web-e687c2a023a8
Tech stack DomCanvas
Flutter Web engine
(dart:ui)
Dart code for HTML, CSS, Canvas
main.dart.js
Flutter code
Dart2js compiler
@rihanna_ke
Typically in web
Flutter for web
Your App
The flutter framework
Web-flavored dart:ui lib
main.dart.js
@rihanna_ke
building | layouting | painting
build/web/main.dart.js
Obfuscation
Minification
Tree shaking
@rihanna_ke
so….
@rihanna_ke
compile existing Flutter code
using all the features of Flutter
embed into a web page
deploy to any web server
without any browser plugin
Interop Dart/JS, HTML?
@rihanna_ke
Flutter Plugins?
Flutter web Plugins?
- Plugins give access to platform-specific
interfaces.
...
@rihanna_ke
pub.dev
@rihanna_ke
Your own plugin?
- extend existing plugins for web
- flutter plugin implementation
* create
* implement
- Add to pubspec.yaml
https://medium.com/flutter/how-to-write-a-flutter-web-plugin-5e26c689ea1
https://medium.com/flutter/how-to-write-a-flutter-web-plugin-part-2-afdddb69ece6
https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin
Interop with Dart
@rihanna_ke
Interop with JS
@rihanna_ke
- package:js
dependencies:
js: ^0.6.1+1
- dart:js
https://github.com/rihannaKe/flutterInteropJs
HTML? HtmlElementView
https://codepen.io/riccio85/pen/wvMeaMe
import 'dart:html';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
void main() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'hello-html',
(int viewId) => IFrameElement()
..width = '640'
..height = '360'
..src = 'https://www.youtube.com/embed/ukLBCRBlIkk'
..style.border = 'none');
runApp( Padding(
padding: EdgeInsets.all(25),
child: SizedBox(
width: 640,
height: 360,
child: HtmlElementView(viewType: 'hello-html'),
),
),
);
}
HtmlElementView IFrameElement
https://codepen.io/riccio85/pen/wvMeaMe
Running on web?
https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html
import 'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// running on the web!
} else {
// NOT running on the web!
Platform.isAndroid
Platform.isFuchsia
Platform.isIOS
Platform.isLinux
Platform.isMacOS
Platform.isWindows
}
const bool kIsWeb = identical(0, 0.0)
for web scenarios
@rihanna_ke
into web page
@rihanna_ke
Embed
Built flutter code
Deploy it to a web server
Reachable url
Embed interactive content
@rihanna_ke
<iframe src=”url”> <iframe>
Showcase website
pre-release post-release
< > < >
- familiarize
- perceive early
feedbacks
- real user testing
- quick sampling
- interact with the
sample
- build trust on the
quality
Demo & code?
https://bit.ly/3bRzTo5
<>
https://bit.ly/36dj7hH
https://github.com/rihannaKe/mobile-app-showcase-site
rihannaKe.github.io/flutter_web_samples
@rihanna_ke
Bring into web page
Benefits of embedding Flutter in web content
graphically rich content
interactive experiences
@rihanna_ke
signup / signin
Chat code
syncfusion
larvalabs
data visualization
@rihanna_ke
online tool
@rihanna_ke Embed dartpad
online tool
@rihanna_ke Embed codepen
“
And so on..
@rihanna_ke
embedding into web page
graphically rich content
interactive experiences
Code reusability
UI consistency
@rihanna_ke
@rihanna_ke
Package as PWA
PWA with Flutter web
&&
||
&&
@rihanna_ke https://developers.google.com/web/progressive-web-
||
PWA definition
Reliable - Load instantly and never show the downasaur,
even in uncertain network conditions.
Fast - Respond quickly to user interactions with silky
smooth animations and no janky scrolling.
Engaging - Feel like a natural app on the device, with an
immersive user experience.
@rihanna_ke
manifest.json
Behind PWA
Installable
Easily distribute
App-likeConnectivity Independent
ProgressiveDiscoverable
Re-engable
Fresh
Responsive
Linkable and shareable
@rihanna_ke
Minimal PWA checklist
web app manifest
service worker
HTTPS
app icon
HTML page, with PWA tweaks
@rihanna_ke
Build
flutter.dev/docs/get-started/web
$ flutter build web
/build/web
assets/
icons/
favicon.png
favicon.ico
flutter_service_worker.js
manifest.json
index.html
main.dart.js
main.dart.js.map
const CACHE_NAME = 'flutter-app-cache';
const RESOURCES = { …… };
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function (cacheName) {
return caches.delete(cacheName);
}).then(function (_) {
return caches.open(CACHE_NAME);
}).then(function (cache) {
return cache.addAll(Object.keys(RESOURCES));
})
);
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
if (response) {
return response;
}
return fetch(event.request);
})
);
});
build/web/flutter_service_worker.js
<html>
<script>
if('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js');
});
}
</script>
</html>
build/web/index.html
web
as
@rihanna_ke
Flutter-pwa
https://flutter-pwa.web.app
web
as
PWA-Desktop
https://developers.google.com/web/progressive-web-apps/desktop
Deploy
Firebase Hosting
GitHub Pages
Google Cloud Hosting
Netlify.com
Surge.sh
we
b
as
Is it really a PWA?
web
graphically rich content
interactive experiences
Benefits of
embedding
Flutter in a web
page
Code/UI consistency
web
installable
distribution strategy
Benefits of
packaging
Flutter code as
PWA
web
Ease of deployment
No installation / No store
More users trying your app
Quickly iterate on your app
Always updated app
Starter kit
flutter.dev/web
dartpad.dev
codepen.io/flutter
Web samples
Web codelab
Responsive UI
Flutter web updates
File an issue
New codelabs
Slides?
https://bit.ly/2YAJCeN
Rihanna Kedir
Photo from Unsplash@rihanna_ke

More Related Content

What's hot

What's hot (20)

What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?What and Why Flutter? What is a Widget in Flutter?
What and Why Flutter? What is a Widget in Flutter?
 
Flutter
FlutterFlutter
Flutter
 
Flutter beyond hello world
Flutter beyond hello worldFlutter beyond hello world
Flutter beyond hello world
 
The magic of flutter
The magic of flutterThe magic of flutter
The magic of flutter
 
Hello Flutter
Hello FlutterHello Flutter
Hello Flutter
 
Introduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fastIntroduction to Flutter - truly crossplatform, amazingly fast
Introduction to Flutter - truly crossplatform, amazingly fast
 
INTRODUCTION TO FLUTTER.pdf
INTRODUCTION TO FLUTTER.pdfINTRODUCTION TO FLUTTER.pdf
INTRODUCTION TO FLUTTER.pdf
 
Flutter for web
Flutter for web Flutter for web
Flutter for web
 
Flutter workshop
Flutter workshopFlutter workshop
Flutter workshop
 
Build beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutterBuild beautiful native apps in record time with flutter
Build beautiful native apps in record time with flutter
 
Flutter session 01
Flutter session 01Flutter session 01
Flutter session 01
 
Flutter
FlutterFlutter
Flutter
 
Flutter Bootcamp
Flutter BootcampFlutter Bootcamp
Flutter Bootcamp
 
Flutter
FlutterFlutter
Flutter
 
What is Flutter
What is FlutterWhat is Flutter
What is Flutter
 
Flutter: Future of App Development
Flutter: Future of App DevelopmentFlutter: Future of App Development
Flutter: Future of App Development
 
Flutter
FlutterFlutter
Flutter
 
Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)Developing Cross platform apps in flutter (Android, iOS, Web)
Developing Cross platform apps in flutter (Android, iOS, Web)
 
Introduction to flutter's basic concepts
Introduction to flutter's basic conceptsIntroduction to flutter's basic concepts
Introduction to flutter's basic concepts
 
flutter.school #HelloWorld
flutter.school #HelloWorldflutter.school #HelloWorld
flutter.school #HelloWorld
 

Similar to Flutter for web

Similar to Flutter for web (20)

Everything about flutter web development
Everything about flutter web developmentEverything about flutter web development
Everything about flutter web development
 
Build run first web application using flutter for web
Build run first web application using flutter for webBuild run first web application using flutter for web
Build run first web application using flutter for web
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
Building Rich Applications with Appcelerator
Building Rich Applications with AppceleratorBuilding Rich Applications with Appcelerator
Building Rich Applications with Appcelerator
 
Php On Windows
Php On WindowsPhp On Windows
Php On Windows
 
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hourConvert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) in 1 hour
 
Flutter vs React Native | Edureka
Flutter vs React Native | EdurekaFlutter vs React Native | Edureka
Flutter vs React Native | Edureka
 
Expo - Zero to App.pptx
Expo - Zero to App.pptxExpo - Zero to App.pptx
Expo - Zero to App.pptx
 
SharePoint 2013 App Provisioning Models
SharePoint 2013 App Provisioning ModelsSharePoint 2013 App Provisioning Models
SharePoint 2013 App Provisioning Models
 
Adobe Air
Adobe AirAdobe Air
Adobe Air
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material design
 
The Big Cloud native FaaS Lebowski
The Big Cloud native FaaS LebowskiThe Big Cloud native FaaS Lebowski
The Big Cloud native FaaS Lebowski
 
JSNation.com - Azure Static Web Apps (SWA) with Azure DevOps
JSNation.com - Azure Static Web Apps (SWA) with Azure DevOpsJSNation.com - Azure Static Web Apps (SWA) with Azure DevOps
JSNation.com - Azure Static Web Apps (SWA) with Azure DevOps
 
Node.js Tools Ecosystem
Node.js Tools EcosystemNode.js Tools Ecosystem
Node.js Tools Ecosystem
 
FEDM Meetup: Introducing Mojito
FEDM Meetup: Introducing MojitoFEDM Meetup: Introducing Mojito
FEDM Meetup: Introducing Mojito
 
PhoneGap/Cordova
PhoneGap/CordovaPhoneGap/Cordova
PhoneGap/Cordova
 
Amazing vue.js projects that are open source and free.
Amazing vue.js projects that are open source and free.Amazing vue.js projects that are open source and free.
Amazing vue.js projects that are open source and free.
 
Improve your Java Environment with Docker
Improve your Java Environment with DockerImprove your Java Environment with Docker
Improve your Java Environment with Docker
 
Webinar by ZNetLive & Plesk- Winning the Game for WebOps and DevOps
Webinar by ZNetLive & Plesk- Winning the Game for WebOps and DevOps Webinar by ZNetLive & Plesk- Winning the Game for WebOps and DevOps
Webinar by ZNetLive & Plesk- Winning the Game for WebOps and DevOps
 
Docker Container As A Service - Mix-IT 2016
Docker Container As A Service - Mix-IT 2016Docker Container As A Service - Mix-IT 2016
Docker Container As A Service - Mix-IT 2016
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Flutter for web

Editor's Notes

  1. Let’s see how we can do that currently.
  2. Good afternoon everyone I am Rihanna Kedir. I work as software engineer. I am a women techmaker ambassador and gdg Rome co-lead. And google developer expert in web technologies, dart and Flutter.
  3. We will start on seeing how we can bring Flutter code into a browser and see some use cases on how to use Flutter’s web compatible code. Moreover, I‘ll show you how to host flutter for web into a static web page and then how to package a flutter web into a Progressive web app.
  4. So first of all, how can we bring flutter into our web browser? Adding support for web means permitting a code-compatible implementation of Flutter that is rendered using standard-based web technologies.
  5. Assuming that you have flutter sdk installed on your platform. Currently, debugging a flutter web app requires the Chrome browser so the other requirement is to have chrome installed on your computer. Flutter has early support for running web applications but we need to be running the beta channel at present. To use the latest version of the Flutter SDK from the beta channel and enable web support we can run the following commands.
  6. Once we set up our environments, to create a flutter app with web support we can use flutter create name of the app. To run the app we can use the run command. That will open a chrome browser and we can see our app running in chrome.
  7. We can also add web support to an existing flutter app with flutter create dot command.
  8. In terms of debugging we can use the flutter devtools during development. For analyzing performance for web it is possible to use chrome dev tools once we build the app. And in case if you are wandering for testing you can do that with the normal widget tests
  9. And when we are ready to release we can run the build app command. This populates a build/web directory with built files, which needs to be served together. And now we are ready to deploy to any web server. So basically that will be all we need to bring flutter code into a modern web browser!!
  10. Going through the timeline of Flutter for web support. The start of the experiment was announced on December 2018 as Hummingbird project. On may of last year was released in technical preview. And today we have in beta version. It’s under active development and experiment. Is not yet recommended deploying a web app to production. So stay tuned to the updates. It might be early to use it for a complex flutter applications, but yet we can do some cool things with it and we are going to see some use case.
  11. Currently there are two available rendering approaches the DomCanvas and the Canavaskit approach. The DomCanvas uses the combination of HTML, CSS and Canvas API for rendering into the browser. CanvasKit brings Skia to the web using WebAssembly and WebGL, enabling a hardware-accelerated drawing surface that improves rendering, complex and intensive graphics efficiently. DomCanvas offers the greatest compatibility with a wide variety of browsers, with a compact code size. However, repaint performance is poorer The CanvasKit backend offers superior performance, fidelity, and correctness, but it has poor initial startup time due to a larger code size. By default, Flutter’s web support uses DomCanvas, but you can enable the CanvasKit rendering engine. It still has a few rough edges and the DomCanvas engine offers the greatest stability.
  12. As Flutter’s architecture is designed with portability in mind, adding web support to Flutter means adding drawing layer on top of standard browser APIs.
  13. Here is the tech stack we have in the DomCanvas approach that permits bringing your flutter code into the browser. At the top we have our flutter code. Then we got the Flutter framework followed by the Flutter Web engine. The layer that generates a dart code suitable for rendering our flutter code along the framework using web technologies. The Dart2js compiler is the layer that compiles dart code into javascript.
  14. And What happens behind the scene is that our application, the Flutter framework, and the web-flavored dart:ui library — all written in Dart — are compiled to JavaScript with the Dart2js compiler and that file can run on any modern browser.
  15. So typically in web development, we use HTML templates and CSS to build up our web app, and we pass it onto the browser. And the browser uses HTML and CSS to layout our elements and paint them on a web page.
  16. With Flutter on the other hand the building, the layouting, and the painting cycle are fully available to us. So Flutter for web exposes the whole rendering pipeline to us in just a single javascript file precisely the main.dart.js. Meaning Flutter is painting everything into the browser!!!!
  17. …not only that ……..but when building for release the Obfuscation, minification and three shaking processes are handled free for us. Obfuscation is the process of making the code unclear and unreadable to humans. This adds a level of security to source code. Minification is the process of removing unnecessary data present in code resulting in smaller file sizes and faster loading. Tree shaking is the process of not including unused modules in the bundle during the build process.
  18. This way Flutter for web support we can compile our Flutter code that we wrote using all its features. Embed the compiled code into a web page, and deploy that to any web server. And we have it running in our browsers without any plugin.
  19. But before that let’s see what we have for web. Now the idea behind flutter is to write code once and run it ‘everywhere’. When developing with flutter we use Flutter plugins. And sometimes we might need to write a platform specific code. Let’s see what we have.
  20. Regarding to plugins flutter plugins they give Flutter access to platform-specific interfaces. so you might be asking which plugins we can use for web. Now several plugins with web support are available , to mention some : Shared preferences, firebase-core and firebase-auth, google-sign-in, url-launcher, video-player
  21. More and more existing Flutter plugins are including web support, to find an updated list you can check on pub.dev using the web filter.
  22. You can also add web support to existing flutter plugins yourself, by simply coding against the plugin's public interface and using its APIs. In addition, in case you want to build your own plugin, for example interop with javascript library that you already have or simply you want your own implementation, you can do that by using the flutter plugin’s public implementation. In both cases you can add them in pubspec.yaml file and when flutter for web compiles, these will work.
  23. In terms of Interop with Dart, Dart has been used for web since it was created. For instance it can be used for developing web application in Angular. Flutter web apps have full access to all existing Dart libraries that run on the web today. In case we need a specific functionality on the web, we can check the dart for web packages and include them into our flutter project.
  24. We can interop with javascript libraries also. And for javascript libraries or our js codes, we can use dart’s JS-interop packages and in specific package:js and dart:js.
  25. kIsweb una costante top-level che possiamo importare dalla libreria foundation e usare per determinare durante se il nostro codice Flutter sta girando in un browser o meno.
  26. Now that we are all set to go. We have the all the tools to create and build a Flutter code that can run into a browser. Let’ checkout the scenarios.
  27. The first use case that I want to show you is embedding a compiled Flutter code into a web page.
  28. So assuming that you have the compiled flutter code deployed a web server. That is to say you have the url address to reach your Flutter for web app.
  29. To embed a flutter code into a web page we use iframe and use the url of our compiled web app. And with this we can host flutter compiled code within an existing web page.
  30. Let’s checkout this example. This is a simple static website for showcasing a mobile app. It is a responsive web site made out of common web technologies: it has Bootstrap4, Jquery, and uses a html5-devices-mokeup which is a library for simulating mobile, tablet and desktop devices into a web page. Usually when showcasing a mobile app, is common to only find some images, a gif , a video simply showing how to use the app. But thanks to the flutter for web support we can do much more than that!! With this you’ll surely have a WOW effect! So we are not showcasing it as a gif or a video, but with the compiled flutter app itself!!!!!
  31. Flutter make it easy and fast to build UI right?? Accordingly it makes it easy also to reuse the widgets and compose different UIs. For example in this demo I used the compiled app as it is also for mobile, however is possible to only use portions of your app. Therefore a developer has the possibility to choose whether to showcase the whole app, portion of it, just the UI same functionality Or simply the onboarding for instance The first use-case is to give the customer access to the application without having to download it from a store, but by just giving him access to an http link. It can be enforced by adding the Progressive Web App concept inside the Flutter’s project. Whether a realsed app that your showcasing or just in part of it , Weather you showacase the entire app or just the onboarding. This benefits a developer to And broaden
  32. And decide to showcase prior of releasing the mobile app into the stores or obviously after the release. This will benefit both users and developers. The user will have the possibility to interact, familiarize with the ‘sample’ app and build trust in the quality of your apps prior downloading the native mobile app from the stores. On the other hand the benefits for the developer are the following: Broaden exposure and usability test. Usability is key for the success of mobile apps. perceive early feedback in terms of let’s say : is enjouble, easiness to use, being user-friendly and less time consuming when completing tasks. Having the possibility to broaden your app to reach more end users and receiving feedbacks can help a developer to efficiently implement the native app.
  33. Let’s see another example of embedding Flutter in a web page. Here I embedded multiple flutter apps. In this case each Flutter app has been compiled and for the sake of simplicity they have been all deployed in the same folders of the web page. I had the idea organizing one of flutter study jams, to permit the participants to decide which codelab they want to do based on their interest after interacting with the available apps. It is possible to use this methodology for example: To showcase multiple apps or variations of the same app To Create a catalogue of Flutter apps But it doesn’t stop only here. In fact if you are flutter dev and you want to create a portfolio this can work for you as well!!!! Because it allows to put multiple applications that you created in one web page and interact with each of them!!!
  34. We have seen how we can easily embed a Flutter app inside a web page. We can enrich a simple static page with an interactive experience. In the same way we can enrich our web pages with Flutter graphically rich content.
  35. You can embed for example signup / signin portion or brand driven content into a web page
  36. Your mobile chat app into a web page
  37. Or simply for data visualization in a cross-platform consistent way including web.
  38. It can be an online tool visualization, take as example the dartpad tool that supports coding online flutter and it can be easily embedded into a web page. We will see how later.
  39. It can be an online tool visualization, take as example the dartpad tool that supports coding online flutter and it can be easily embedded into a web page. We will see how later.
  40. And so on
  41. Embedding interactive content not only permits us to enrich our web page with graphically rich content, but at the same time we can take advantage of it for reusing the same Flutter codebase cross-platform including web. for maintaining design consistency so users can adapt to our product easily in any platform including web.
  42. Now let’s see the next scenario and maybe the more exciting one Packaging Flutter for web as a Progressive web app. As more and more web apps and web sites are becoming PWA nowdays.
  43. PWA it is a web page that can behave just like a native app downloaded from the stores. Let’s like to describe PWA as what you get when you combine together best of the web and the best of the app.The basic concept of PWA is to deliver the app like experience within a browser. It starts as a normal web page in a browser, and as a user explores the webpage, they get the prompt if they would like to “Add to Home Screen”. Once the user accepts the prompt, the PWA gets added to their home screen. Once open from the home screen, it can even hide the browser UI controls and appear as an app.
  44. As a definition of PWA we have this three features. Reliable - Load instantly and never show the downasaur, even in uncertain network conditions. Fast - Respond quickly to user interactions with silky smooth animations and no janky scrolling. Engaging - Feel like a natural app on the device, with an immersive user experience. In terms of packaging our flutter web app in PWA means most of the definitions falls back to our flutter code.
  45. PWA not a framework or a library. It is a set of technologies and practices allowing you to create web applications similar to the native ones. The major component of a PWA is the service worker. A service worker is a JavaScript file that sits between the server and the browser, and can do stuff on behalf of both the browser and the server, in the background. It can handle requests, and send responses. A very common task for service workers, and a baseline PWA requirement, is to provide offline capabilities. The second main component is the manifest file: It contains meta-data about your PWA such as theme colour, icons, and whether it should be displayed standalone as a PWA or not. Basically it contains all the information needed to configure how the PWA will look when it is added/installed to the home screen of the device, and configures how it will behave when it’s launched.
  46. Let’s checkout the minimum requirements in order to call a web app a PWA. We talked about the Service worker and the manifest file. The other requirements are: Service workers require HTTPS, so the PWA must also be served over HTTPS. PWAs need to have an icon that can be used to launch the app from the device homescreen, and to show on a splashscreen. Our PWA Minimus can have at least two icons: 192x192px icon and 512×512 px icon Finally, to tie everything together, we need some HTML and that is the actual web page.
  47. Flutter template for web apps now includes support for the core features needed for an installable, offline-capable PWA app.
  48. When building for relase a flutter app, we got the flutter_service_worker.js file. Which simply permits the offline capability by using the browser cache and serving the need assets from the cache when the user is offline.
  49. And the service worker registration code, that installs the service worker
  50. So now when building flutter for web for a release, we got an installable web application that works also offline.
  51. All we need is the url and everybody can check out the app. And here we have the two launcher icons in the home screen: the first one is the native downloaded app icon and the second one is the PWA icon. Consequently the first launching the Flutter code compiled to native app, and the other launching the same flutter code compiled to a web app. Both coisiting in our homescreen.
  52. As use case let’s see this app.
  53. PWA are now are supported on all major desktop platforms, including Chrome OS, Linux, Mac, and Windows. They can be 'installed' on the user's device like native desktop apps and they are launched in the same way as the other desktop apps. They run in an app window, without an address bar or tabs. In this video we are seeing how it works on macOs. We open the same url of our deployed app and we install it. We will then have the app launcher icon in our launcher pad. It works the same way in the other platforms too.
  54. What is great about web development is the easiness of deploying your web app. And to do that quickly you can use one of this services or any of other available services. And in just few seconds, minutes you are the app is online.
  55. Now let’s analyse our web app and to do so we can use lighthouse. Lighthouse is an open-source, automated tool for improving the quality of web pages. It has audits for performance, accessibility, progressive web apps, SEO and more. You can run Lighthouse in Chrome DevTools right under the Audits tab. it runs a series of audits against the page, and then it generates a report on how well the page did. From there, one can use the failing audits as indicators on how to improve the page. Each audit has a reference doc with helpful steps to improve your web app. In our case most of the indicators might not be applicable. As our source code is in Flutter and the analyzed code is the generated one after the Flutter code is compiled into javascript.
  56. Wrapping up we have some use cases that benefit from embedding a Flutter compiled code into a web page. In terms of enriching a web pages with graphically rich content and interactive experiences. And also in terms of code reusing and UI consistency cross platforms.
  57. In the other hand we have seen the seen what can be the benefits of packaging and delivering a Flutter compiled code as a PWA. With this we can have a app-like behaviour but without going through the app stores. Which gives us more choice in terms of the app’s distribution strategy making by making it also visible in the browser and so searchable for users. Weather we want to release on stores or just the web or have both, with pros and cons of the chosen strategies.
  58. Overall what is great about web is the ease of deployment. Ease of deployment has some benefits for your flutter projects. You have no install friction, It permits you to have more users trying your app and it enables you to quickly iterate on your applications or experiments. The web is a great way of delivering quick iteration cycle to improve products overall right? No need of app stores, and the user can get always your uptodate application, as long as it is connected.