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

What's Add2App project?(Flutter)

What's Add2App project?(Flutter)

About Flutter Add2App project.
How to use Flutter from existing Android/iOS project.

kosuke matsumura

March 26, 2019
Tweet

More Decks by kosuke matsumura

Other Decks in Technology

Transcript

  1. About Me • দଜߤ༟(Kosuke Matsumura) • NAVITIME JAPAN Co., Ltd.


    Android/iOS Developer • Kawasaki Frontale Supporter • Twitter
 m.kosuke @kosuke_mtm
  2. Add2App project • Make it easy to add Flutter on

    existing application • In preview(as of 2019.3.17) • Available in master channel
  3. OUTLINE Standard Flutter Project Add2App Project Existing Android/iOS project should

    import Flutter project as a module. Flutter project includes Android/iOS project from the beginning. Import with CocoaPods Import with cradle
  4. OUTLINE $ flutter --version Flutter 1.3.11-pre.34
 • channel master Framework


    • 2019-03-15 22:03:13 -0700 Tools
 • Dart 2.2.1 (build 2.2.1-dev.1.0 None) Execution environment Warning:
 https://github.com/flutter/flutter/wiki/Bad-Builds
  5. OUTLINE $ flutter --version Flutter 1.3.11-pre.34
 • channel master Framework


    • 2019-03-15 22:03:13 -0700 Tools
 • Dart 2.2.1 (build 2.2.1-dev.1.0 None) Execution environment Warning:
 https://github.com/flutter/flutter/wiki/Bad-Builds
  6. SETUP Create “Flutter module” $ flutter channel master $ flutter

    create -t module my_flutter `-t` option is `template`.
 This command create the Flutter module project template.
 Existing Android/iOS project will import this module. set branch to `master`
  7. SETUP Create “Flutter module” $ flutter create -t module my_flutter

    In the Flutter module project, there are hidden subfolder:
 `.android/` and `.ios/`
  8. SETUP -Android- Add compile option: using java1.8 build.gradle android {

    compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 }
 …
  9. SETUP -Android- Add path to the Flutter module project setting.gradle

    include ':app' // add below setBinding(new Binding([gradle: this])) evaluate(new File( settingsDir.parentFile, 'my_flutter/.android/include_flutter.groovy' ))
  10. SETUP -Android- Introduce an implementation dependency on the Flutter module

    from app app/build.gradle dependencies { implementation project(‘:flutter') … }
  11. SETUP -Android- [optional] Apply AndroidX to the Flutter module project

    ɾExecute on Android Project(not Flutter module project) ɾYou should correct import manually
  12. SETUP -iOS- Setup Podfile
 ※If you don’t have Podfile, execute

    `pod init` Podfile flutter_application_path = ‘../my_flutter/‘ eval(File.read( File.join(flutter_application_path, ‘.ios’, ‘Flutter’, ‘podhelper.rb’)), binding) And execute `pod install`
  13. SETUP -iOS- Add a build phase for building Dart code


    Run Script “$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh” build
 “$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
  14. USING -Android- As a View MainActivity.kt val flutterView = Flutter.createView(

    this, // Activity lifecycle, // Lifecycle "route1" ) Talk about this later
  15. USING -Android- As a Fragment MainActivity.kt val transaction = supportFragmentManager.beginTransaction()

    transaction.replace(R.id.container, Flutter.createFragment(“route2”)) transaction.commit() What is “route”?
  16. What is “route”? Dart code is able to receive String

    main.dar void main() => runApp(_widgetForRoute(window.defaultRouteName)); Widget _widgetForRoute(String route) { switch (route) { case 'route1': return SomeWidget(…); case 'route2': return SomeWidget(…); default: return Center(child: Text('Unknown route: $route')); } }
  17. USING -iOS- AppDelegate.swift import Flutter Replace super class with `FlutterAppDelegate`

    } FlutterAppDelegate.swift @interface FlutterAppDelegate: UIResponder <UIApplicationDelegate, …> @UIApplicationMain class AppDelegate: FlutterAppDelegate {
  18. USING -iOS- AppDelegate.swift import Flutter Case of using Flutter plugin

    } @UIApplicationMain class AppDelegate: FlutterAppDelegate {
  19. USING -iOS- AppDelegate.swift import Flutter Case of using Flutter plugin

    @UIApplicationMain class AppDelegate: FlutterAppDelegate { import FlutterPluginRegistrant var flutterEngine: FlutterEngine? override func application(_ application: UIApplication,didFinishLaunching… { self.flutterEngine = FlutterEngine(name: "io.flutter", project: nil) self.flutterEngine?.run(withEntrypoint: nil) GeneratedPluginRegistrant.register(with: self.flutterEngine) return super.application(application, didFinishLaunchingWithOptions:… }
  20. Hot Reload $ cd xxxxx/my_flutter $ flutter attach IDE Support

    Hot Reload for Add2App is in progress. But Flutter command line tools are already present.
  21. Hot Reload IDE Support Hot Reload for Add2App is in

    progress. But Flutter command line tools are already present. Dart Observatory web user interface URL
  22. Hot Reload IDE Support Hot Reload for Add2App is in

    progress. But Flutter command line tools are already present. Dart Observatory web user interface URL
  23. References • Add2App project
 https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps • github
 https://github.com/flutter/flutter/projects/28 • Google

    Developer blog
 https://developers.googleblog.com/2018/12/flutter-10-googles-portable-ui- toolkit.html • gitHub
 https://github.com/shcahill/Add2AppSample