hybrid_stack_manager 0.0.1 copy "hybrid_stack_manager: ^0.0.1" to clipboard
hybrid_stack_manager: ^0.0.1 copied to clipboard

outdatedDart 1 only

Hybrid stack management when using Flutter and Native(iOS/Android) simutaneously.

hybrid_stack_manager #

In hybrid scenarios where there are flutter pages and native pages, and they can jump to flutter/native at will. In other words, hybrid stack management would be the first important problem we should consider. This package can manage the hybrid stack and supports any jumping between flutter/native and native/flutter.

Architecture #

Snapshot #

iOS

hybrid_stack_management_ios

Android

hybrid_stack_management_android

Usage #

Add dependency in pubspec.yaml:

​ hybrid_stack_manager:0.0.1

After "flutter packages get",you can check the examples within the package to see how to use it.

Usage in iOS side #

1.Construct a rootNavigationController for later use when pushing.

2.Set the sNativeOpenUrlHandler where ios side router logic is implemented,as below:

    sNativeOpenUrlHandler = ^UIViewController *(NSString *url,NSDictionary *query,NSDictionary *params){
        NSURL *tmpUrl = [NSURL URLWithString:url];
        if([@"ndemo" isEqualToString:tmpUrl.host]){
            return [XDemoController new];
        }
        return nil;
    };

Usage in Android side #

1.Set the context for activity jumping

XURLRouter.setAppContext(getApplicationContext());

2.Set NativeRouterHandler,where android side router logic is implemented, as below:

  void setupNativeOpenUrlHandler(){
    XURLRouter.setNativeRouterHandler(this);
  }
  public Class openUrlWithQueryAndParams(String url, HashMap query, HashMap params){
    Uri tmpUri = Uri.parse(url);
    if("ndemo".equals(tmpUri.getHost())){
      return XDemoActivity.class;
    }
    return null;
  }

Usage in Flutter side #

1.Init a global key for later use to fetch a context and pass it to the Router 2.Set the Router's routerWidgetHandler where Flutter side router logic is implemented,as below:

    Router.sharedInstance().routerWidgetHandler =
        ({RouterOption routeOption, Key key}) {
      if (routeOption.url == "hrd://fdemo") {
        return new FDemoWidget(routeOption, key: key);
      }
      return null;
    };
    return _singleton;

Attention #

1.In Flutter,the NavigatorState class located in flutter/lib/src/widgets/navigator.dart is modified by adding a getter function to fetch the history as below:

  List<Route<dynamic>> get history => _history;

2.In iOS,I reuse the XFlutterViewController singleton which is embedded in FlutterViewWrapperController with the help of addChildVC/removeFromParentVC。It is necessary to ensure that the viewWill/DidAppear/Disappear call could be passed from ParentVC Appear to ChildVC(Especially the viewWillAppear: and viewDidDisappear:)。

- (BOOL)shouldAutomaticallyForwardAppearanceMethods{
    return TRUE;
}

3.Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v0.5.6, on Mac OS X 10.14 18A353d, locale en-CN)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ! CocoaPods out of date (1.5.0 is recommended).
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To upgrade:
        brew upgrade cocoapods
        pod setup
[✓] Android Studio (version 3.1)
[!] VS Code (version 1.25.1)
[✓] Connected devices (1 available)

! Doctor found issues in 2 categories.

Though flutter bata v0.5.6 is used in my environment, this logic works even in v0.3.1 and above.

Contact me #

Contact me

3
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Hybrid stack management when using Flutter and Native(iOS/Android) simutaneously.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on hybrid_stack_manager