flutter_boost 0.0.420


中文文档 中文介绍

FlutterBoost #

A next-generation Flutter-Native hybrid solution. FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts.The philosophy of FlutterBoost is to use Flutter as easy as using a WebView. Managing Native pages and Flutter pages at the same time is non-trivial in an existing App. FlutterBoost takes care of page resolution for you. The only thing you need to care about is the name of the page(usually could be an URL). 

Prerequisites #

You need to add Flutter to your project before moving on.

Getting Started #

Add a dependency in you Flutter project. #

Open you pubspec.yaml and add the following line to dependencies:

flutter_boost: ^0.0.415

or you could rely directly on a Github project tag, for example(recommended)

flutter_boost:
        git:
            url: 'https://github.com/alibaba/flutter_boost.git'
            ref: '0.0.415'

Integration with Flutter code. #

Add init code to you App

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    ///register page widget builders,the key is pageName
    FlutterBoost.singleton.registerPageBuilders({
      'sample://firstPage': (pageName, params, _) => FirstRouteWidget(),
      'sample://secondPage': (pageName, params, _) => SecondRouteWidget(),
    });

    ///query current top page and load it
    FlutterBoost.handleOnStartPage();
  }

  @override
  Widget build(BuildContext context) => MaterialApp(
      title: 'Flutter Boost example',
      builder: FlutterBoost.init(), ///init container manager
      home: Container());
}

Integration with iOS code. #

Note: You need to add libc++ into "Linked Frameworks and Libraries"

Use FLBFlutterAppDelegate as the superclass of your AppDelegate

@interface AppDelegate : FLBFlutterAppDelegate <UIApplicationDelegate>
@end

Implement FLBPlatform protocol methods for your App.

@interface DemoRouter : NSObject<FLBPlatform>

@property (nonatomic,strong) UINavigationController *navigationController;

+ (DemoRouter *)sharedRouter;

@end


@implementation DemoRouter

- (void)openPage:(NSString *)name
          params:(NSDictionary *)params
        animated:(BOOL)animated
      completion:(void (^)(BOOL))completion
{
    if([params[@"present"] boolValue]){
        FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
        [vc setName:name params:params];
        [self.navigationController presentViewController:vc animated:animated completion:^{}];
    }else{
        FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
        [vc setName:name params:params];
        [self.navigationController pushViewController:vc animated:animated];
    }
}


- (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL))completion
{
    FLBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController;
    if([vc isKindOfClass:FLBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: uid]){
        [vc dismissViewControllerAnimated:animated completion:^{}];
    }else{
        [self.navigationController popViewControllerAnimated:animated];
    }
}

@end

Initialize FlutterBoost with FLBPlatform at the beginning of your App.

 [FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router
                                                        onStart:^(FlutterViewController *fvc) {
                                                            
                                                        }];

Integration with Android code. #

Init FlutterBoost in Application.onCreate() 

public class MyApplication extends FlutterApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        FlutterBoostPlugin.init(new IPlatform() {
            @Override
            public Application getApplication() {
                return MyApplication.this;
            }

            /**
             * get the main activity, this activity should always at the bottom of task stack.
             */
            @Override
            public Activity getMainActivity() {
                return MainActivity.sRef.get();
            }

            @Override
            public boolean isDebug() {
                return false;
            }

            /**
             * start a new activity from flutter page, you may need a activity router.
             */
            @Override
            public boolean startActivity(Context context, String url, int requestCode) {
                return PageRouter.openPageByUrl(context,url,requestCode);
            }

            @Override
            public Map getSettings() {
                return null;
            }
        });
    }

Basic Usage #

Concepts #

All page routing requests are being sent to the native router. Native router communicates with Native Container Manager, Native Container Manager takes care of building and destroying of Native Containers. 

Use Flutter Boost Native Container to show a Flutter page in native code. #

iOS

 FLBFlutterViewContainer *vc = FLBFlutterViewContainer.new;
        [vc setName:name params:params];
        [self.navigationController presentViewController:vc animated:animated completion:^{}];

Android

public class FlutterPageActivity extends BoostFlutterActivity {

    @Override
    public void onRegisterPlugins(PluginRegistry registry) {
        //register flutter plugins
        GeneratedPluginRegistrant.registerWith(registry);
    }

    @Override
    public String getContainerName() {
        //specify the page name register in FlutterBoost
        return "sample://firstPage";
    }

    @Override
    public Map getContainerParams() {
        //params of the page
        Map<String,String> params = new HashMap<>();
        params.put("key","value");
        return params;
    }
}

or

public class FlutterFragment extends BoostFlutterFragment {
    @Override
    public void onRegisterPlugins(PluginRegistry registry) {
        GeneratedPluginRegistrant.registerWith(registry);
    }

    @Override
    public String getContainerName() {
        return "sample://firstPage";
    }

    @Override
    public Map getContainerParams() {
        Map<String,String> params = new HashMap<>();
        params.put("key","value");
        return params;
    }
}

Use Flutter Boost to open a page in dart code. #

Dart

 FlutterBoost.singleton.openPage("pagename", {}, true);

Use Flutter Boost to close a page in dart code. #

FlutterBoost.singleton.closePageForContext(context);

Running the Demo #

Please see the example for details.

License #

This project is licensed under the MIT License - see the LICENSE.md file for details

关于我们 #

阿里巴巴-闲鱼技术是国内最早也是最大规模线上运行Flutter的团队。

我们在公众号中为你精选了Flutter独家干货,全面而深入。

内容包括:Flutter的接入、规模化应用、引擎探秘、工程体系、创新技术等教程和开源信息。

架构/服务端/客户端/前端/算法/质量工程师 在公众号中投递简历,名额不限哦

欢迎来闲鱼做一个好奇、幸福、有影响力的程序员,简历投递:tino.wjf@alibaba-inc.com

订阅地址

For English

0.0.1 #

  • TODO: Describe initial release.

example/README.md

flutter_boost_example #

Demonstrates how to use the flutter_boost plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_boost: ^0.0.420

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_boost/flutter_boost.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
89
Health:
Code health derived from static analysis. [more]
92
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jul 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/container/boost_container.dart. (-1.49 points)

Analysis of lib/container/boost_container.dart reported 3 hints:

line 25 col 8: Unused import: 'package:flutter_boost/container/container_coordinator.dart'.

line 202 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 209 col 5: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/AIOService/NavigationService/service/NavigationService.dart. (-1 points)

Analysis of lib/AIOService/NavigationService/service/NavigationService.dart reported 2 hints:

line 40 col 22: 'listenEvent' is deprecated and shouldn't be used.

line 44 col 16: 'cancelEventForSubscription' is deprecated and shouldn't be used.

Fix lib/AIOService/NavigationService/handlers/NavigationService_canPop.dart. (-0.50 points)

Analysis of lib/AIOService/NavigationService/handlers/NavigationService_canPop.dart reported 1 hint:

line 9 col 7: Name types using UpperCamelCase.

Fix additional 18 files with analysis or formatting issues. (-5 points)

Additional issues in the following files:

  • lib/AIOService/NavigationService/handlers/NavigationService_didDisappearPageContainer.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_didInitPageContainer.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_didShowPageContainer.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_onNativePageResult.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_willDeallocPageContainer.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_willDisappearPageContainer.dart (1 hint)
  • lib/AIOService/NavigationService/handlers/NavigationService_willShowPageContainer.dart (1 hint)
  • lib/container/container_coordinator.dart (1 hint)
  • lib/flutter_boost.dart (1 hint)
  • lib/router/router.dart (1 hint)
  • lib/AIOService/NavigationService/service/NavigationServiceRegister.dart (Run flutter format to format lib/AIOService/NavigationService/service/NavigationServiceRegister.dart.)
  • lib/AIOService/loader/ServiceLoader.dart (Run flutter format to format lib/AIOService/loader/ServiceLoader.dart.)
  • lib/container/container_manager.dart (Run flutter format to format lib/container/container_manager.dart.)
  • lib/container/navigator_observer.dart (Run flutter format to format lib/container/navigator_observer.dart.)
  • lib/messaging/message_proxy.dart (Run flutter format to format lib/messaging/message_proxy.dart.)
  • lib/messaging/native_page_container_event_handler.dart (Run flutter format to format lib/messaging/native_page_container_event_handler.dart.)
  • lib/messaging/page_result_mediator.dart (Run flutter format to format lib/messaging/page_result_mediator.dart.)
  • lib/support/logger.dart (Run flutter format to format lib/support/logger.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
xservice_kit ^0.0.27 0.0.29
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8

Admin