bifrost 0.1.0
bifrost: ^0.1.0 copied to clipboard

Bifrost is a plugin which enables hybrid integration of Flutter for your existing native apps.

Bifrost #

Bifrost is a plugin which enables easy embedding of your Flutter application into your existing native apps.

Requirements #

  • Flutter 2.0.0+ on stable channel
  • iOS 10.0+ Xcode 12.0+ Swift 5+
  • Android minSdkVersion 16 Kotlin 1.3.50+

Getting Started #

Flutter #

Add a dependency in your Flutter project

dependencies:
  bifrost: ^0.1.0

Initialize Bifrost on your MaterialApp or CupertinoApp

@override
Widget build(BuildContext context) {
  return MaterialApp(
    builder: Bifrost.init(),
    routes: routes,
    theme: theme,
  );
}

Invoke a method of the native layer, from your Flutter code

final appVersion = await BifrostChannels.common.invokeMethod('getAppVersion');

Send notification to native app

BifrostChannels.notification.invokeMethod('doSomething', arguments);

Android #

Start Bifrost Flutter Engine in your application class and also add the common MethodCallHandler

class App : Application() {

  override fun onCreate() {
    super.onCreate()
    // start flutter engine
    Bifrost.startFlutterEngine(this, CommonHandler())
  }

  // application common handler
  private class CommonHandler : MethodChannel.MethodCallHandler {
    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
      when (call.method) {
        "getAppVersion" -> result.success(BuildConfig.VERSION_NAME)
      }
    }
  }
}

Start a new activity by passing an initial route

val intent = BifrostFlutterActivity.createIntent(this, "/greetings", arguments)
startActivity(intent)

Create a new fragment instance by passing an initial route

val fragment = BifrostFlutterFragment.newInstance("/first")

Register notification listener

Bifrost.registerNotification("doSomething") { arguments ->
  // do something
}

iOS #

Start Bifrost Flutter Engine in your AppDelegate and also add the common MethodCallHandler

import UIKit
import bifrost

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
 
        // start bifrost flutter engine
        Bifrost.startFlutterEngine(commonHandler: handle)
        
        return true
    }

    // common channel handle
    private func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
        if (call.method == "getAppVersion") {
            let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"]
            result(version)
        }
    }
}

Start a new ViewController by passing an initial route

let vc = BifrostFlutterViewController.init("/greetings", arguments: arguments)

If you want to use storyboard, you can use custom attributes

Storyboard Attributes

Register notification listener

Bifrost.registerNotification("doSomething") { arguments in
  // do something          
}
6
likes
110
pub points
18%
popularity

Publisher

dextra-sw.com

Bifrost is a plugin which enables hybrid integration of Flutter for your existing native apps.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on bifrost