Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutter web + PWA

Meet Janani
September 08, 2022

Flutter web + PWA

Going above and beyond on flutter web

Presented by Meet Janani & Milap Chokshi on 8-September-2022.

Meet Janani

September 08, 2022
Tweet

More Decks by Meet Janani

Other Decks in Programming

Transcript

  1. Flutter web + PWA Going above and beyond on flutter

    web Presenter: Meet Janani & Milap Chokshi
  2. Agenda (Source Code) • Flutter Web ◦ What is flutter

    web? ◦ Why we need to use flutter web? ◦ How to add web support to an existing app? ◦ Advantage , Disadvantage • Manifest File ◦ What is manifest file ◦ Explain manifest file component in detail • PWA ◦ What is PWA ◦ Advantages & its Limitations • URL Navigation ◦ Go router • Responsive UI ◦ Responsive UI Widgets [GridView, Visibility, Value, Row-Column]
  3. What is flutter Web / PWA ? • Flutter web/PWA

    delivers the same experiences on the web as on mobile. • Building on the portability of Dart, the power of the web platform and the flexibility of the Flutter framework, you can now build apps for iOS, Android, and the browser from the same codebase. • one thing you need to keep in mind is that it creates Single Page Web App! You can definitely have multi-pages. But when the Flutter framework converts the web app into the native language, there will only be one HTML file i.e. index.html. • As Flutter Web is a single page, It pushes multiple pages on the same page.
  4. Why we need to use Flutter web? • Shared Codebase

    • Reach to users beyond app stores without limitations • Target every screen size such as Mobile, Tablet, Desktop • Faster (Easy to Deploy on preferred platform)
  5. How to add web support to an existing app ?

    - To add web support to an existing project created using a previous version of Flutter, run the following command from your project’s directory: ◦ Flutter create . - Beginning with Flutter v1.10 or above`s project we can migrate to add Web support. ◦ To enable web support: ▪ flutter config --enable-web ◦ To create a new project: ▪ flutter create project_name ◦ To build flutter web: ▪ flutter build web ◦ To check connected devices: ▪ flutter devices ◦ To run your app in chrome: ▪ flutter run -d chrome
  6. Flutter Web Advantages - Render graphical effects, transitions, and animations.

    - Similar to native app performance & supports both Material and Cupertino UI elements. - Renders animations in up to 60 FPS. - Huge amount open source and commercial libraries on pub.dev - Can be integrated with already existing web app as embedded elements. - It’s possible to run JS code from dart using JS Promise. - Flutter web is great option if JS library or SDK have to implement.
  7. Flutter Web/PWA Dis-Advantages - Flutter Web is not SEO friendly.

    - The load size is much larger than on more popular web frameworks. ◦ HTML minimum payload is 1.8MB ◦ CanvasKit adds an additional 2MB to the payload giving better performance in return. These values may look poor when compared to classic web development. • We don`t have control over generated HTML, CSS, and JS code.
  8. Is Flutter Web suitable for web app development ? -

    It’s essential to understand what kind of framework Flutter Web is. - Misusing the framework may lead to underperforming solutions. - Flutter Web can bring considerable benefits to your business if used correctly
  9. How to run JavaScript using JS Promise - Use pub

    package : js:0.6.x - Call Javascript promise to Dart ◦ Add entry of your js file into index.html like <script src:”your_script.js” defer></script> ◦ Create function data type with @JS() annotation. For this use import ‘package:js/js.dart’ import. ◦ Pass this above function into promiseToFuture() function from dart. It will run JS scripts from dart and return Future results as per annotation function`s return data type. For this use import ‘dart:js_util’. ◦ It run JS script and return data whatever JS Function will return in dart.
  10. How to handle Cors error - Run flutter run -d

    web-server in terminal it will give localhost url like http://localhost:49517 - open Safari - Preferences - Advanced. and tick "show develop menu in menu bar" - You will get Develop menu in Safari's Top bar , Now tap the menu and click on disable Cross-Origin restrictions then restart safari - open http://localhost:49517 it will work.
  11. What is Manifest file - The web app manifest is

    a JSON file that tells the browser about your PWA and how it should behave when installed on the user's device. - A manifest file includes the app name, the icons, and the URL that should be opened when the app is launched - Manifest files are supported in Chrome, Edge, Firefox, UC Browser, Opera, and the Samsung browser. Safari has partial support. - The manifest file can have any name, but is commonly named manifest.json which is available at root of your website's directory.
  12. Manifest File component explained in-details List of properties that Manifest

    files include: Short_name name icons start_url background_color display_override scope theme_color shortcuts description screenshots
  13. Manifest File component explained in-details - Splash screens on mobile:

    ◦ Chrome automatically creates the splash screen from the manifest properties, specifically: ▪ name ▪ background_color ▪ icons ◦ The background_color should be the same color as the load page, to provide a smooth transition from the splash screen to your app. - Browser will choose the icon that closely matches the device resolution for the device.
  14. PWA

  15. What is PWA - Progressive web apps are like having

    qualities of web and app at the same time. - Google launched Flutter 2 stable release on March, 2021, To build Mobile app as PWA. - Browser compatibility Chart: https://developer.mozilla.org/en-US/docs/Web/Manifest
  16. Flutter PWA Advantages - Offline access - Faster loading time

    - App Like feel - No App store submission required - Single code base
  17. Mobile Vs PWA Limitations - PWA could not use all

    functions of mobile such as Bluetooth & Contactless payment. - PWA does not support Push notifications, Phone book contacts. - PWA does not use proximity sensors event & geofencing - PWA can store upto 50 MB data only in a static cashing, that data will erase in some time interval - Overall Native apps have better performance Compared to PWA.
  18. Flutter GoRouter for URL navigation - Declare your list of

    routes and prepare GoRouter object - Pass GoRouter.routeInformationParcer & GoRouter.routeDeligate to MaterialApp.router() - 2 way to navigate to the desired screen ◦ Go: just navigate to next screen, it won`t add into stack, so pop() will not work in this case ◦ Push: it is actually adding into stack so programmatically we can pop newly opened screen. - Let` Take a look sample.
  19. Responsive UI - It will adopt your UI to different

    screen size automatically. - Create UI only once and have it display pixel perfect on Different screen size. - First add ResponsiveWrapper.builder() inside material app. In witch initialize Maxwidth, MinWidth, and Breakpoint which is of List type, inside it resize device like Mobile, Tablet & Desktop, And AutoScale value is defined. - AutoScale shrinks and expands your layout proportionally, preserving the exact look of your UI - Let`s jump on a practical side.
  20. Responsive UI Widgets - Responsive GridView Widget - Responsive Value

    Widget - Responsive Visibility Widget - Responsive Row-Column Widget