Git Product home page Git Product logo

viewer-flutter-dart's Introduction

Build Status License Autodesk Forge Flutter Platform

Description

Original blog: https://forge.autodesk.com/blog/kick-start-2020-cross-platform-viewer-apps-flutter

Sample project to load Viewer models locally for cross-platform apps built with Flutter.

The wheel never stops in the developer's world and Flutter is gaining huge momentum for recent years so let's see how one should build Viewer Apps with Flutter today and our demo would cover how to load models locally from within client! In fairness it's not exactly as straight forward to bundle Viewer models with the apps and we had addressed this topic here, here and here previously. But with the advent of such a massive game changer like Flutter there goes all the pain and anguish so let the fun begin right away!

Why Flutter

Flutter is Google's UI toolkit for crafting beautiful, natively compiled applications for mobile, web, and desktop from a single codebase, AOT (Ahead Of Time) compiled to fast, predictable, native code, which allows almost all of Flutter to be written in Dart - a sound typed, client-optimized, object-oriented, class defined, garbage-collected language using a C -style syntax for apps on multiple platforms, server and clients alike. This not only makes Flutter fast, virtually everything (including all the widgets) can be customized.

Project Structure

  • assets: static resources including Viewer HTML and SVF model files
  • android: scaffolded/generated Android platform code
  • ios: scaffolded/generated iOS platform code
  • lib: Flutter Dart code

Surely we'd still need to fall back as always to WebView to load Viewer scripts as well as the models since Viewer is yet to be implemented in any native form. However we'd be able to load models as bundled resources by starting a local http server on client and it gets even better: we'd be able to build to iOS, Android and even web targets using exactly the same Dart code and Flutter project/dependencies settings! Now let's walk through the dependencies as well the structure of our sample app here:

  • Jaguar: client side http server
  • Jaguar Flutter asset: serve Flutter assets
  • Flutter WebView plugin: WebView module for iOS, Android and Web
  • Flutter icon plugin: custom icons and splash screens

Setup and Run

Prerequisites

  • Flutter
  • iOS
  • Android, when integrating with existing projects be sure to migrate to Androidx since it’s required by the “flutter_webview_plugin”.

Setup

  • Clone project: https://github.com/dukedhx/viewer-flutter-dart
  • Set up your favorite IDE with Flutter
  • Put your SVF model files to the “assets” folder and change the URL in assets/index.html to point to the SVF entry file accordingly (see here to download the SVF files from Forge)
  • If you place your model files in other directory than assets/model make sure the path is referenced in pubspec.yaml:

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
      - assets/
      - assets/model/
      - path/to/your/model/
      - path/to/your/model/subdirs
      # ...
  • Verify Flutter installation and readiness: flutter doctor
  • Set up pods if you haven’t: pod setup
  • Navigate to project folder and set up the dependencies: flutter get pub

Build and Run:

  • Run on emulators: flutter run
  • Build to platform targets: flutter build ios / flutter build apk

Q&A

Blank screen/WebView won't load?

The Jaguar server won't resolve the serve future somehow on some oses/devices so set up a timer for the WebView to load after a few secs while the server gets started:

    final server = Jaguar();
    //...
    server.serve(); //

    Timer timer = new Timer(new Duration(seconds: 5), () =>
    flutterWebviewPlugin.launch('http://localhost:8080/',
        rect: new Rect.fromLTWH(
          0.0,
          100.0,
          MediaQuery.of(context).size.width,
          MediaQuery.of(context).size.height - 100,
    )));

Also try use the IP addr 127.0.0.1 instead of localhost

The Flutter WebView plugin won't compile?

when integrating with existing projects be sure to migrate to Androidx since it’s required by the “flutter_webview_plugin”.

License

MIT

Written By

Bryan Huang - Forge Partner Development https://forge.autodesk.com

viewer-flutter-dart's People

Contributors

dukedhx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

viewer-flutter-dart's Issues

Code Samples not work

Hi
i clone the sample code and put the svf model to the "assets" folder and change the URL in assets/index.html
run on emulators get Blank screen.

Flutter version: 2.3.0-17.0.pre.121
OS: mac big sur
Simulator: iPhone 12 - ios 14.5

also i try set up a timer for the webview

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.