szotp / runner_lib

Using flutter project as iOS library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

runner_lib

Shows how to use Flutter app as iOS library. Very experimental. The project was created following these instructions:

  1. Create flutter app as usual and run it once on iOS simulator.
  2. Open Xcode workspace and add new framework. For my purposes I will name it RunnerLib.
  3. Change deployment target of that framework to be the same as for Runner. Also disable bitcode.
  4. Change target membership of App.framework and Flutter.framework to RunnerLib.
  5. Create Launcher class with one static method: + (void)launchFrom:(UIViewController *)parent, this what should create a FlutterViewController and present it.
  6. Rewrite the Runner to use Launcher class. Replace FlutterAppDelegate with standard AppDelegate, make ViewController, etc. It should look like standard native iOS project, so you could create one and copy over AppDelegate, storyboard and ViewController.
  7. Call launchFrom method in your view controller, in viewDidAppear or as IBAction on a button.
  8. You should be able to build the Runner and see that flutter screen appears.
  9. Now, if you build the Runner app, you can open the crated Runner.app, and see that Frameworks directory contains 3 frameworks: App, Flutter and Runner.
  10. You will need to have two sets of frameworks: one set for simulator, compiled in debug mode, and another set for devices - archived. Getting debug frameworks is pretty easy, just compile from Xcode and inspect the product. Archived frameworks are harder, I recommend doing xcodebuild archive with disabled signing.
  11. Your users will have to configure their project to use correct frameworks depending on device. Possibly this step can be automated by Carthage and fat binaries, but I'm not sure. The problem is with App.framework which looks completely different on device than on simulator.

About

Using flutter project as iOS library

License:MIT License


Languages

Language:Dart 62.6%Language:Objective-C 30.2%Language:Java 4.1%Language:Shell 3.0%