Current Flutter version 1.17

FlutterBoost version 1.12.13 is used

To create a flutter module project, refer to the official documentation. CD the folder to the target folder and run the flutter create –template module flutter_module command.

After successful creation, open the Flutter_module project, open the pubspec.yaml file, and add the required dependencies

Flutter_boost: ^1.12.13 Flui: ^0.9.1 dio: ^3.0.9Copy the code

Run the command to update the dependencies (VSCode will update them automatically when saved)

Run the flutter run command to generate a POD

To create a Swift project, open the Swift project Podfile and add the related POD command

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

platform :ios, '11.0'
use_frameworks!

target 'demo' do
  
  # flutter
  flutter_application_path = '.. /flutter_module'
  load File.join(flutter_application_path, '.ios'.'Flutter'.'podhelper.rb')
  install_all_flutter_pods(flutter_application_path)
end

Copy the code

Execute pod install (pod install will need to be executed again each time pubspec.yaml in Flutter_module changes)

Add the Bridging file bridge-header. h and refer to FlutterBoost Demo to add the header file

#import "GeneratedPluginRegistrant.h"
#import <flutter_boost/FlutterBoost.h>
Copy the code

Open the appdelegate. swift file

import Flutter @UIApplicationMain class AppDelegate: FlutterAppDelegate { override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Register a FLUTTER routelet router = PlatformRouterImp.init();
        FlutterBoostPlugin.sharedInstance().startFlutter(with: router, onStart: { (engine) in
            
        });
        
        return true}}Copy the code

Create the file PlatformRouterImp. Swift in the Swift project

import UIKit class LYGHFlutterContainer: FLBFlutterViewContainer { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController? .navigationBar.isHidden =true} override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) self.navigationController? .navigationBar.isHidden =false
    }
}

class PlatformRouterImp: NSObject, FLBPlatform {
    
    func open(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
        var animated = false
        if exts["animated"] != nil {
            animated = exts["animated"] as! Bool
        }
        let vc = LYGHFlutterContainer.init()
        vc.setName(url, params: urlParams)
        vc.hidesBottomBarWhenPushed = true
        self.navigationController().pushViewController(vc, animated: animated)
        completion(true)
    }
    
    func present(_ url: String, urlParams: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
        var animated = false
        if exts["animated"] != nil {
            animated = exts["animated"] as! Bool
        }
        let vc = LYGHFlutterContainer.init()
        vc.setName(url, params: urlParams)
        navigationController().present(vc, animated: animated) {
            completion(true)
        }
    }
    
    func close(_ uid: String, result: [AnyHashable : Any], exts: [AnyHashable : Any], completion: @escaping (Bool) -> Void) {
        var animated = false
        if exts["animated"] != nil {
            animated = exts["animated"] as! Bool
        }
        let presentedVC = self.navigationController().presentedViewController
        let vc = presentedVC as? FLBFlutterViewContainer
        ifvc? .uniqueIDString() == uid { vc? .dismiss(animated: animated, completion: { completion(true)})}else {
            self.navigationController().popViewController(animated: animated)
        }
    }
    
    func navigationController() -> LYGHNavigationController {
        let navi = LYGHMainTabBarViewController.currentSelectedNavigationController()
        returnnavi! }}Copy the code

Example Jump to the Flutter_module project from Swift

FlutterBoostPlugin.open("orderLogotics", urlParams:["orderNumber": model.streamNo ?? ""."type": model.streamName ?? ""], exts: ["animated": true], onPageFinished: { (_ result:Any?) in
                print(String(format:"call me when page finished, and your result is:%@", result as! CVarArg));
            }) { (f:Bool) in
                print(String(format:"page is opened"));
            }
Copy the code

The main.dart code in the Flutter_module project

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'modules/logistics_module/logistics.dart';
import 'package:flutter/services.dart';

void main() {
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  } else {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
  }

  runApp(MyApp());
}

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

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

    FlutterBoost.singleton.registerPageBuilders(<String, PageBuilder>{
      'orderLogotics':
          (String pageName, Map<dynamic, dynamic> params, String _) {
        returnOrderLogistics(params: params); }}); } @override Widget build(BuildContext context) {return MaterialApp(
      title: ' ',
      builder: FlutterBoost.init(postPush: _onRoutePushed),
      home: Container(),
    );
  }

  void _onRoutePushed(
    String pageName,
    String uniqueId,
    Map<dynamic, dynamic> params,
    Route<dynamic> route,
    Future<dynamic> _,
  ) {}
}
Copy the code