VistianOpenSource / Vistian.Flutter.Bindings

An experimental release allowing Flutter solutions to be hosted within Xamarin solutions
31 stars 4 forks source link

Xamarin host for Flutter

Introduction

An experimental release of code allowing for Flutter solutions to be hosted within an Xamarin Android / iOS solution.

Motivation

Prerequisites

Caveats

Installation

Please follow the installation instructions very carefully. Just installing the nuget package is currently insufficient to get a working environment.

Android

  1. Install the package Vistian.Flutter.Bindings available from nuget.
  2. In the Assets folder of your application create a 'flutter_shared' folder.
  3. In this folder place the icudtl.dat file available here https://github.com/VistianOpenSource/Vistian.Flutter.Bindings/blob/master/FlutterAssets/flutter_shared/icudtl.dat on github.
  4. If your application targets 64-bit solutions e.g. arm64-v8a turn this option off in your project settings. Similarly delete all of the installed common libraries and the existing app from your device (Mono Shared Runtime, Xamarin.*).
  5. To see that the Flutter view is correctly installed, change your startup activities OnCreate to be the following:
protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    var flutterView = Flutter.Bindings.Flutter.CreateView(this, this.Lifecycle, "home");
    var layout = new FrameLayout.LayoutParams(600, 800) {LeftMargin = 200, TopMargin = 400};

    AddContentView(flutterView, layout);
}
  1. To be able to adjust the Flutter content, goto a terminal / console and in the folder where your flutter solution exists type :
flutter attach 

or if you have more than one device connected , get the device id first then use that with attach

flutter devices
flutter attach -d device Id
  1. Once the Flutter attach is running restart your Xamarin solution and now you can use Shift+R & R in the terminal to refresh your solution.

iOS

Coming once I update by bindings from an older installation of Flutter to Flutter 0.9.4

Common Issues

Android

Application starts and immediately exits

More than likely this is down to the fact that the shared runtime and libraries haven't been removed from the device. The device log can confirm this.

Application starts but crashes when the Flutter View is created

This typically happens when the icudtl.dat hasn't been included in the application. I have been trying to get this installed automatically as part of the nuget package but for some reason the current version of Visual Studio doesn't want to install Android Assets from a nuget package. Once again the device log can confirm this.