### Initializing FlutterBoost App (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Configures the FlutterBoost application by defining a route factory that maps route names to page builders. This setup is essential for handling navigation between native and Flutter pages within the Boost framework. ```Dart void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { static Map routerMap = { '/': (settings, uniqueId) { return PageRouteBuilder( settings: settings, pageBuilder: (_, __, ___) => Container()); }, 'embedded': (settings, uniqueId) { return PageRouteBuilder( settings: settings, pageBuilder: (_, __, ___) => EmbeddedFirstRouteWidget()); }, 'presentFlutterPage': (settings, uniqueId) { return PageRouteBuilder( settings: settings, pageBuilder: (_, __, ___) => FlutterRouteWidget( params: settings.arguments, uniqueId: uniqueId, )); }}; Route routeFactory(RouteSettings settings, String uniqueId) { FlutterBoostRouteFactory func =routerMap[settings.name]; if (func == null) { return null; } return func(settings, uniqueId); } @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return FlutterBoostApp( routeFactory ); } ``` -------------------------------- ### Implementing FlutterBoostDelegate for iOS Navigation Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Provides an example implementation of the `FlutterBoostDelegate` protocol in Objective-C. This delegate handles requests to push native routes, push Flutter routes, and pop routes, integrating with the native UINavigationController. ```objc @interface MyFlutterBoostDelegate : NSObject @property (nonatomic,strong) UINavigationController *navigationController; @end @implementation MyFlutterBoostDelegate - (void) pushNativeRoute:(FBCommonParams*) params{ BOOL animated = [params.arguments[@"animated"] boolValue]; BOOL present= [params.arguments[@"present"] boolValue]; UIViewControllerDemo *nvc = [[UIViewControllerDemo alloc] initWithNibName:@"UIViewControllerDemo" bundle:[NSBundle mainBundle]]; if(present){ [self.navigationController presentViewController:nvc animated:animated completion:^{ }]; }else{ [self.navigationController pushViewController:nvc animated:animated]; } } - (void) pushFlutterRoute:(FBCommonParams*)params { FlutterEngine* engine = [[FlutterBoost instance ] getEngine]; engine.viewController = nil; FBFlutterViewContainer *vc = FBFlutterViewContainer.new ; [vc setName:params.pageName params:params.arguments]; BOOL animated = [params.arguments[@"animated"] boolValue]; BOOL present= [params.arguments[@"present"] boolValue]; if(present){ [self.navigationController presentViewController:vc animated:animated completion:^{ }]; }else{ [self.navigationController pushViewController:vc animated:animated]; } } - (void) popRoute:(FBCommonParams*)params result:(NSDictionary *)result{ FBFlutterViewContainer *vc = (id)self.navigationController.presentedViewController; if([vc isKindOfClass:FBFlutterViewContainer.class] && [vc.uniqueIDString isEqual: params.uniqueId]){ [vc dismissViewControllerAnimated:YES completion:^{ }]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } @end ``` -------------------------------- ### Include Flutter Pods in iOS Podfile (Ruby) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md Modifies the iOS Podfile to include the Flutter module's pods. It sets the path to the flutter_module and uses the podhelper script to install all required Flutter pods. ```Ruby flutter_application_path = '../flutter_module' load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb') install_all_flutter_pods(flutter_application_path) ``` -------------------------------- ### Overriding NavigationController Orientation Methods (Objective-C) Source: https://github.com/alibaba/flutter_boost/blob/main/Frequently Asked Question.md Provides Objective-C code examples for overriding the `shouldAutorotate` and `supportedInterfaceOrientations` methods in a Native `UINavigationController`. This is necessary to correctly manage screen orientation for `FlutterViewController` instances when embedded within a Native navigation stack, allowing control over which orientations are supported. ```Objective-C -(BOOL)shouldAutorotate { // id currentViewController = self.topViewController; // // // if ([currentViewController isKindOfClass:[FlutterViewController class]]) // return [currentViewController shouldAutorotate]; return YES; } -(UIInterfaceOrientationMask)supportedInterfaceOrientations { id currentViewController = self.topViewController; if ([currentViewController isKindOfClass:[FlutterViewController class]]){ NSLog(@"[XDEBUG]----fvc supported:%ld\n",[currentViewController supportedInterfaceOrientations]); return [currentViewController supportedInterfaceOrientations]; } return UIInterfaceOrientationMaskAll; } ``` -------------------------------- ### Initializing FlutterBoost and Implementing Delegate in OHOS EntryAbility Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md This code demonstrates how to initialize FlutterBoost within the onWindowStageCreate method of an OHOS EntryAbility. It shows implementing the FlutterBoostDelegate interface to handle native and Flutter route pushes and configuring the initialization options, including plugins. ```TypeScript export default class EntryAbility extends UIAbility implements FlutterBoostDelegate { // FlutterBoostDelegate override pushNativeRoute(options: FlutterBoostRouteOptions) { } // FlutterBoostDelegate override pushFlutterRoute(options: FlutterBoostRouteOptions) { router.pushUrl({ url: 'pages/MyFlutterPage', params: { uri: options.getPageName(), params: options.getArguments(), } }).then(() => { console.info('Succeeded in jumping to the second page.') }) } onWindowStageCreate(windowStage: window.WindowStage): void { // 初始化启动参数(建议带上GeneratedPluginRegistrant.getPlugins()) const optionsBuilder: FlutterBoostSetupOptionsBuilder = new FlutterBoostSetupOptionsBuilder() .setPlugins(GeneratedPluginRegistrant.getPlugins()); FlutterBoost.getInstance().setup(this, this.context, () => { //引擎初始化成功 }, optionsBuilder.build()) } } ``` -------------------------------- ### Opening Flutter Pages from iOS Native Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Shows how to use the `open:arguments:` method of the FlutterBoost instance to navigate to a Flutter page from native iOS code, including passing arguments to control animation and presentation style. ```objc [[FlutterBoost instance] open:@"flutterPage" arguments:@{@"animated":@(YES)} ]; [[FlutterBoost instance] open:@"secondStateful" arguments:@{@"present":@(YES)}]; ``` -------------------------------- ### Initializing FlutterBoost in iOS AppDelegate Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Sets up FlutterBoost within the iOS AppDelegate's `didFinishLaunchingWithOptions` method. This involves creating and providing a delegate object to handle navigation events between native and Flutter. ```objc @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { MyFlutterBoostDelegate* delegate=[[MyFlutterBoostDelegate alloc ] init]; [[FlutterBoost instance] setup:application delegate:delegate callback:^(FlutterEngine *engine) { } ]; return YES; } @end ``` -------------------------------- ### Opening New Page with Flutter Boost (Swift) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Demonstrates how to configure and open a new page using Flutter Boost. It shows setting the page name, arguments, transparency, completion callback, and a callback for when the page is finished and returns data. ```Swift let options = FlutterBoostRouteOptions() options.pageName = "mainPage" options.arguments = ["key" :"value"] //页面是否透明(用于透明弹窗场景),若不设置,默认情况下为true options.opaque = true //这个是push操作完成的回调,而不是页面关闭的回调!!!! options.completion = { completion in print("open operation is completed") } //这个是页面关闭并且返回数据的回调,回调实际需要根据您的Delegate中的popRoute来调用 options.onPageFinished = { dic in print(dic) } FlutterBoost.instance().open(options) ``` -------------------------------- ### Initializing FlutterBoost in Android Application Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Sets up FlutterBoost within the Android Application class, providing custom delegates to handle navigation requests between native and Flutter pages. This is typically done in the `onCreate` method. ```java public class MyApplication extends FlutterApplication { @Override public void onCreate() { super.onCreate(); FlutterBoost.instance().setup(this, new FlutterBoostDelegate() { @Override public void pushNativeRoute(String pageName, HashMap arguments) { Intent intent = new Intent(FlutterBoost.instance().currentActivity(), NativePageActivity.class); FlutterBoost.instance().currentActivity().startActivity(intent); } @Override public void pushFlutterRoute(String pageName, HashMap arguments) { Intent intent = new FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity.class, FlutterBoost.ENGINE_ID) .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.opaque) .destroyEngineWithActivity(false) .url(pageName) .urlParams(arguments) .build(FlutterBoost.instance().currentActivity()); FlutterBoost.instance().currentActivity().startActivity(intent); } },engine->{ engine.getPlugins(); } ); } } ``` -------------------------------- ### Creating Custom OHOS Page to Host FlutterView Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md This ArkTS component (MyFlutterPage) serves as a container for a Flutter view within an OHOS application. It initializes FlutterBoostEntry in aboutToAppear, manages its lifecycle methods (aboutToDisappear, onPageShow, onPageHide), and embeds the FlutterPage component, also handling the back button press to delegate it to FlutterBoost. ```TypeScript @Entry @Component struct MyFlutterPage { private flutterEntry: FlutterBoostEntry | null = null; private flutterView?: FlutterView aboutToAppear() { this.flutterEntry = new FlutterBoostEntry(getContext(this), router.getParams()); this.flutterEntry.aboutToAppear(); this.flutterView = this.flutterEntry.getFlutterView(); hilog.info(0x0000, "Flutter", "Index aboutToAppear==="); } //2 aboutToDisappear() { hilog.info(0x0000, "Flutter", "Index aboutToDisappear==="); this.flutterEntry?.aboutToDisappear() } onPageShow() { hilog.info(0x0000, "Flutter", "Index onPageShow==="); this.flutterEntry?.onPageShow() } // 1 onPageHide() { hilog.info(0x0000, "Flutter", "Index onPageHide==="); this.flutterEntry?.onPageHide() } build() { Stack() { FlutterPage({ viewId: this.flutterView?.getId() }) } } // 拦截返回键 onBackPress(): boolean | void { FlutterBoost.getInstance().getPlugin()?.onBackPressed(); return true; } } ``` -------------------------------- ### Opening Page with BoostNavigator (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Uses BoostNavigator.instance.push to navigate to a specified route ("flutterPage"). The withContainer: true parameter indicates whether to open the page in a new container. It returns a Future that resolves with a result. ```Dart String result = await BoostNavigator.instance .push("flutterPage", withContainer: true); ``` -------------------------------- ### Navigating to Flutter Page using OHOS Router Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md This snippet demonstrates how to navigate to the custom OHOS page (MyFlutterPage) that hosts the Flutter view using the OHOS router. It passes the Flutter route name (uri) and optional parameters (params) to the target page, which are then used by FlutterBoostEntry. ```TypeScript router.pushUrl({ url: 'pages/MyFlutterPage', params: { uri: '这里写dart侧注册好的路由名', params: '传递给界面的参数', } }).then(() => { console.info('Succeeded in jumping to the second page.') }) ``` -------------------------------- ### Opening New Page - Flutter Boost (Android) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Provides the Android-side API for opening a new page using FlutterBoost.instance().open. Shows how to build FlutterBoostRouteOptions with page name, arguments, and request code. ```Java FlutterBoostRouteOptions options = new FlutterBoostRouteOptions.Builder() .pageName("pageName") .arguments(new HashMap<>()) .requestCode(1111) .build(); FlutterBoost.instance().open(options); ``` -------------------------------- ### Opening/Closing Flutter Pages from Android Native Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Demonstrates the basic API calls to open a Flutter page from native Android code using its route name and optional parameters, and to close a Flutter page using its unique ID. ```java FlutterBoost.instance().open("flutterPage",params); FlutterBoost.instance().close("uniqueId"); ``` -------------------------------- ### Opening New Page - Flutter Boost (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Provides the unified API for pushing new pages using either BoostNavigator.instance.push or the standard Navigator.of(context).pushNamed. Explains key parameters like name, withContainer, arguments, and opaque. Notes the limitation regarding anonymous routes. ```Dart BoostNavigator.instance.push( "yourPage", //required withContainer: false, //optional arguments: {"key":"value"}, //optional opaque: true, //optional,default value is true ); ///or Navigator.of(context).pushNamed('simplePage', arguments: {'data': _controller.text}); ///不能使用匿名路由,boost目前无法捕捉匿名路由,匿名路由就是直接使用类似 ///类似CupertinoPageRoute的形式来进行push,暂不支持!!! ``` -------------------------------- ### Listening to FlutterBoost Lifecycle (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Implements the PageVisibilityObserver mixin to receive callbacks for page visibility changes (appear, disappear, foreground, background). This allows widgets to react to lifecycle events within the FlutterBoost environment. ```Dart class SimpleWidget extends StatefulWidget { final Map params; final String messages; final String uniqueId; const SimpleWidget(this.uniqueId, this.params, this.messages); @override _SimpleWidgetState createState() => _SimpleWidgetState(); } class _SimpleWidgetState extends State with PageVisibilityObserver { static const String _kTag = 'xlog'; @override void didChangeDependencies() { super.didChangeDependencies(); print('$_kTag#didChangeDependencies, ${widget.uniqueId}, $this'); } @override void initState() { super.initState(); PageVisibilityBinding.instance.addObserver(this, ModalRoute.of(context)); print('$_kTag#initState, ${widget.uniqueId}, $this'); } @override void dispose() { PageVisibilityBinding.instance.removeObserver(this); print('$_kTag#dispose, ${widget.uniqueId}, $this'); super.dispose(); } @override void onForeground() { print('$_kTag#onForeground, ${widget.uniqueId}, $this'); } @override void onBackground() { print('$_kTag#onBackground, ${widget.uniqueId}, $this'); } @override void onAppear(ChangeReason reason) { print('$_kTag#onAppear, ${widget.uniqueId}, $reason, $this'); } void onDisappear(ChangeReason reason) { print('$_kTag#onDisappear, ${widget.uniqueId}, $reason, $this'); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('tab_example'), ), body: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Container( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( margin: const EdgeInsets.only(top: 80.0), child: Text( widget.messages, style: TextStyle(fontSize: 28.0, color: Colors.blue), ), alignment: AlignmentDirectional.center, ), Container( margin: const EdgeInsets.only(top: 32.0), child: Text( widget.uniqueId, style: TextStyle(fontSize: 22.0, color: Colors.red), ), alignment: AlignmentDirectional.center, ), InkWell( child: Container( padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(30.0), color: Colors.yellow, child: Text( 'open flutter page', style: TextStyle(fontSize: 22.0, color: Colors.black), )), onTap: () => BoostNavigator.instance.push("flutterPage", arguments: {'from': widget.uniqueId}), ) Container( height: 300, width: 200, child: Text( '', style: TextStyle(fontSize: 22.0, color: Colors.black), ), ) ], ))), ); } } ``` -------------------------------- ### Initialize FlutterBoost and Delegates in Android Application (Java) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md Initializes the FlutterBoost instance in the Android Application class's `onCreate` method. It configures delegates (`FlutterBoostDelegate`) to handle navigation requests between native Android and Flutter pages. ```Java public class App extends Application { @Override public void onCreate() { super.onCreate(); FlutterBoost.instance().setup(this, new FlutterBoostDelegate() { @Override public void pushNativeRoute(FlutterBoostRouteOptions options) { //这里根据options.pageName来判断你想跳转哪个页面,这里简单给一个 Intent intent = new Intent(FlutterBoost.instance().currentActivity(), YourTargetAcitvity.class); FlutterBoost.instance().currentActivity().startActivityForResult(intent, options.requestCode()); } @Override public void pushFlutterRoute(FlutterBoostRouteOptions options) { Intent intent = new FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity.class) .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.transparent) .destroyEngineWithActivity(false) .uniqueId(options.uniqueId()) .url(options.pageName()) .urlParams(options.arguments()) .build(FlutterBoost.instance().currentActivity()); FlutterBoost.instance().currentActivity().startActivity(intent); } }, engine -> { }); } } ``` -------------------------------- ### Configuring FlutterBoost Activity in Android Manifest Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Configures the `FlutterBoostActivity` in the AndroidManifest.xml file. This involves setting the activity name, theme, configuration changes, hardware acceleration, input mode, and necessary metadata for Flutter embedding. ```xml ``` -------------------------------- ### iOS: FlutterBoostPlugin startFlutterWithPlatform (After) Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md The updated signature of the startFlutterWithPlatform method (now in FlutterBoostPlugin2) after the API change in version 0.1.5. It now accepts an FLB2Platform protocol and a callback providing a more generic engine object. ```Objective-C FlutterBoostPlugin2 - (void)startFlutterWithPlatform:(id)platform onStart:(void (^)(id engine))callback; ``` -------------------------------- ### Managing Multiple Flutter Instances in OHOS Tabs Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md This ArkTS component (EntryPage) shows how to manage multiple independent Flutter instances within different tabs of an OHOS application. It creates multiple FlutterBoostEntry instances, stores them in an array, and manually calls their lifecycle methods (aboutToAppear, onPageShow, onPageHide) when the active tab changes to ensure correct state management for each Flutter view. ```TypeScript @Entry @Component struct EntryPage { @State currentIndex: number = 0; private flutterEntries: Array = []; build() { Column() { Tabs({ index: this.currentIndex, barPosition: BarPosition.End }) { ForEach(bottomTabItems.getTabItems(), (item: TabItem) => { TabContent() { Column() { this.Content() } } .tabBar(this.CardTab(item)) }, (item: TabItem, index?: number) => index + JSON.stringify(item)) } .vertical(false) .barWidth("100%") .barHeight("56vp") .layoutWeight(1) .barMode(BarMode.Fixed) .align(Alignment.Center) .onChange((index: number) => { this.currentIndex = index; if (this.currentIndex == 1) { this.flutterEntries[0]?.aboutToAppear(); this.flutterEntries[0]?.onPageShow(); this.flutterEntries[1]?.onPageHide(); } else if (this.currentIndex == 2) { this.flutterEntries[1]?.aboutToAppear(); this.flutterEntries[1]?.onPageShow(); this.flutterEntries[0]?.onPageHide(); } }) } .backgroundColor("#F1F3F5") } // 组件生命周期 aboutToAppear() { console.info('MyComponent aboutToAppear'); const firstFlutterEntry = new FlutterBoostEntry(getContext(this), { uri: 'firstFirst' }); const secondFlutterEntry = new FlutterBoostEntry(getContext(this), { uri: 'flutterPage' }); this.flutterEntries.push(firstFlutterEntry); this.flutterEntries.push(secondFlutterEntry); } // 组件生命周期 aboutToDisappear() { console.info('MyComponent aboutToDisappear'); } // 只有被@Entry装饰的组件才可以调用页面的生命周期 onPageShow() { ``` -------------------------------- ### iOS: FlutterBoostPlugin startFlutterWithPlatform (Before) Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md The original signature of the startFlutterWithPlatform method in FlutterBoostPlugin before the API change in version 0.1.5. It accepted an FLBPlatform protocol and a callback providing a FlutterViewController. ```Objective-C FlutterBoostPlugin - (void)startFlutterWithPlatform:(id)platform onStart:(void (^)(FlutterViewController *))callback; ``` -------------------------------- ### Include Flutter Module in Android settings.gradle (Groovy) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md Adds configuration to the Android project's settings.gradle file to include the Flutter module. This involves evaluating the include_flutter.groovy script and setting the project directory for the flutter_module. ```Groovy setBinding(new Binding([gradle: this])) evaluate(new File( settingsDir.parentFile, 'flutter_module/.android/include_flutter.groovy' )) include ':flutter_module' project(':flutter_module').projectDir = new File('../flutter_module') ``` -------------------------------- ### Register FlutterBoost Activity in Android Manifest (XML) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md Registers the `FlutterBoostActivity` and specifies the `flutterEmbedding` version within the `` tag in the Android Manifest file, which is required for FlutterBoost navigation. ```XML ``` -------------------------------- ### Returning Result from Flutter to Flutter - Flutter Boost (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Illustrates how one Flutter page can return a result to another Flutter page. The calling page uses await BoostNavigator.instance.push to open the next page and wait for a result. The called page uses BoostNavigator.instance.pop to close itself and pass the result back. ```Dart // 1. 打开一个Flutter页面,并处理返回结果 InkWell( child: Container( padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0), color: Colors.yellow, child: Text( 'open transparent widget', style: TextStyle(fontSize: 22.0, color: Colors.black), )), onTap: () { // 如果withContainer为false时,也可以使用原生的Navigator final result = await BoostNavigator.instance.push("AFlutterPage", withContainer: true, opaque: false); }, ), ``` ```Dart // 2. 页面关闭,并返回结果 // 这里也可以使用原生的 Navigator onTap: () => BoostNavigator.instance.pop({'retval' : 'I am from dart...'}), ``` -------------------------------- ### Open Flutter iOS Project in Xcode Source: https://github.com/alibaba/flutter_boost/blob/main/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md Use this command in your terminal from the project root to open the iOS part of your Flutter project in Xcode. This allows you to manage assets, including launch screen images, within the Xcode environment. ```Shell open ios/Runner.xcworkspace ``` -------------------------------- ### Binding Flutter Lifecycle in OHOS UIAbility Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md This snippet shows how to bind the Flutter lifecycle to the OHOS UIAbility lifecycle methods (onCreate, onDestroy, onWindowStageCreate, onWindowStageDestroy) using FlutterManager. This ensures Flutter's state is managed correctly alongside the native UIAbility lifecycle. ```TypeScript async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { FlutterManager.getInstance().pushUIAbility(this): } onDestroy(): void { FlutterManager.getInstance().popUIAbility(this); } onWindowStageCreate(windowStage: window.WindowStage): void { FlutterManager.getInstance().pushWindowStage(this, windowStage) } onWindowStageDestroy(): void { FlutterManager.getInstance().popWindowStage(this); } ``` -------------------------------- ### Returning Result from Flutter to Native - Flutter Boost (Android/Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Demonstrates how a Flutter page returns a result to the preceding Native Android page. The Native side uses startActivityForResult and handles the result in onActivityResult. The Flutter side uses BoostNavigator.instance.pop to close and pass the result. ```Java // 1. 打开Flutter页面,等待返回结果 Intent intent = new FlutterBoostActivity.CachedEngineIntentBuilder(FlutterBoostActivity.class) .backgroundMode(FlutterActivityLaunchConfigs.BackgroundMode.opaque) .destroyEngineWithActivity(false) .url("DialogPage") .urlParams(params) .build(this); startActivityForResult(intent, REQUEST_CODE); @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // 处理返回结果 } ``` ```Dart // 2. 关闭Flutter页面,返回结果 InkWell( child: Container( padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0), color: Colors.yellow, child: Text( 'Pop with Navigator', style: TextStyle(fontSize: 22.0, color: Colors.blue), )), // 这里也可以使用: Navigator.of(context).pop({'retval' : 'I am from dart...'}) onTap: () => BoostNavigator.instance.pop({'retval' : 'I am from dart...'}), ), ``` -------------------------------- ### Android: IPlatform Added Methods Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md Methods that were added to the IPlatform interface and its implementation in the Android API changes for FlutterBoost version 0.1.5. ```Java void registerPlugins(PluginRegistry registry) 方法 void openContainer(Context context,String url,Map urlParams,int requestCode,Map exts); void closeContainer(IContainerRecord record, Map result, Map exts); IFlutterEngineProvider engineProvider(); int whenEngineStart(); ``` -------------------------------- ### Opening Transparent Dialog (With Container) - Flutter Boost (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Explains how to open a transparent dialog that uses a new native container. Requires setting both withContainer: true and opaque: false when pushing the route. ```Dart BoostNavigator.instance.push("dialogPage", withContainer: true, ///如果开启新容器,需要指定opaque为false opaque: false); ``` -------------------------------- ### Opening Transparent Dialog (No Container) - Flutter Boost (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Describes how to create a transparent dialog within Flutter without a new native container. Requires setting opaque: false and barrierColor in the PageRouteBuilder for the route and then pushing it using BoostNavigator.instance.push. Shows how to receive results. ```Dart ///首先你需要在你的routeFactory路由表中这样指定弹窗页面 'dialogPage': (settings, uniqueId) { return PageRouteBuilder( ///透明弹窗页面这个需要是false opaque: false, ///背景蒙版颜色 barrierColor: Colors.black12, settings: settings, pageBuilder: (_, __, ___) => DialogPage()); }, ///然后这样弹出即可 BoostNavigator.instance.push("dialogPage"); ///如果要接收参数返回参数的形式 final result = await BoostNavigator.instance.push("dialogPage"); ``` -------------------------------- ### Returning Result from Native to Flutter - Flutter Boost (Dart/Android) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Shows how a Native Android page can return a result to the preceding Flutter page. The Flutter side opens the Native page using BoostNavigator.instance.push and handles the result in a .then() callback. The Native side sets the result using setResult before finishing. ```Dart // 1. 从Flutter页面打开一个Native页面,并处理返回结果 InkWell( child: Container( padding: const EdgeInsets.all(8.0), margin: const EdgeInsets.all(8.0), color: Colors.yellow, child: Text( 'open native page', style: TextStyle(fontSize: 22.0, color: Colors.black), )), onTap: () => BoostNavigator.instance .push("ANativePage") // Native页面路由 .then((value) => print('retval:$value')), ), ``` ```Java // 2. Native页面退出时,返回结果 @Override public void finish() { Intent intent = new Intent(); intent.putExtra("msg","This message is from Native!!!"); intent.putExtra("bool", true); intent.putExtra("int", 666); setResult(Activity.RESULT_OK, intent); // 返回结果给dart super.finish(); } ``` -------------------------------- ### Flutter Engine Accessibility Setting on iOS Simulator (C++) Source: https://github.com/alibaba/flutter_boost/blob/main/Frequently Asked Question.md Shows a snippet from the Flutter Engine source code illustrating how accessibility semantics are conservatively enabled on the iOS simulator (`TARGET_OS_SIMULATOR`). This setting is linked to a known bug that causes crashes when Voice Over is active on the simulator. ```C++ #if TARGET_OS_SIMULATOR // There doesn't appear to be any way to determine whether the accessibility // inspector is enabled on the simulator. We conservatively always turn on the // accessibility bridge in the simulator, but never assistive technology. platformView->SetSemanticsEnabled(true); platformView->SetAccessibilityFeatures(flags); #endif ``` -------------------------------- ### Closing Page - Flutter Boost (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Shows how to close the current page using BoostNavigator.instance.pop. Explains how to pass results back and notes the difference in result type (Map) when popping a page opened with a container or a Native page versus one opened without a container. ```Dart ///pop一次 BoostNavigator.instance.pop(result); ///pop两次,首次需要用await等待 await BoostNavigator.instance.pop(result); BoostNavigator.instance.pop(result); ``` -------------------------------- ### Adding FlutterBoost Dependency in pubspec.yaml Source: https://github.com/alibaba/flutter_boost/blob/main/README.md Adds the flutter_boost package as a dependency to your Flutter project's pubspec.yaml file, specifying the source as a Git repository and a specific tag (4.6.5) for the version. ```YAML flutter_boost: git: url: 'https://github.com/alibaba/flutter_boost.git' ref: '4.6.5' ``` -------------------------------- ### Add FlutterBoost Dependencies in Android build.gradle (Groovy) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/install.md Adds the necessary dependencies for the Flutter and flutter_boost modules to the application's build.gradle file, enabling their use in the Android project. ```Groovy implementation project(':flutter') implementation project(':flutter_boost') ``` -------------------------------- ### Closing Page with BoostNavigator (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/INTEGRATION.md Uses BoostNavigator.instance.pop to dismiss the current page. An optional argument can be passed back as a result to the page that opened it. ```Dart BoostNavigator.instance.pop('I am result for popping.'), ``` -------------------------------- ### iOS: FLBPlatform Protocol Definition (Before) Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md The original definition of the FLBPlatform protocol before the API change in version 0.1.5. It included optional methods like accessibilityEnable and flutterCanPop, and required methods for opening and closing pages. ```Objective-C @protocol FLBPlatform @optional //Whether to enable accessibility support. Default value is Yes. - (BOOL)accessibilityEnable; // flutter模块是否还可以pop - (void)flutterCanPop:(BOOL)canpop; @required - (void)openPage:(NSString *)name params:(NSDictionary *)params animated:(BOOL)animated completion:(void (^)(BOOL finished))completion; - (void)closePage:(NSString *)uid animated:(BOOL)animated params:(NSDictionary *)params completion:(void (^)(BOOL finished))completion; @end ``` -------------------------------- ### Android: IPlatform Removed Methods Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md Methods that were removed from the IPlatform interface and its implementation in the Android API changes for FlutterBoost version 0.1.5. ```Java Activity getMainActivity(); boolean startActivity(Context context,String url,int requestCode); Map getSettings(); ``` -------------------------------- ### Sending Result from Native to Flutter with Flutter Boost (Swift) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Illustrates how to send data from a native page back to the previous Flutter page. It requires specifying the native page's name and the arguments to send. This method does not close the native page. ```Swift //这里pageName是你push的这个原生的pageName,而不是上一个flutter页面的pageName //这句话并不会退出页面 FlutterBoost.instance().sendResultToFlutter(withPageName: "pageName", arguments: ["key":"value"]) ``` -------------------------------- ### Closing Page with Flutter Boost (Swift) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Shows the basic API call to close a page using its unique identifier. Note that this API is less frequently used compared to other methods. ```Swift FlutterBoost.instance().close(uniqueId) ``` -------------------------------- ### Open Xcode Workspace for Launch Screen Assets - Shell Source: https://github.com/alibaba/flutter_boost/blob/main/example_new_for_ios/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md This command opens the Xcode workspace file for the iOS runner project. This is necessary to access and modify the project's assets, including those used for the launch screen, within the Xcode development environment. ```Shell open ios/Runner.xcworkspace ``` -------------------------------- ### iOS: FLB2Platform Protocol Definition (After) Source: https://github.com/alibaba/flutter_boost/blob/main/CHANGELOG.md The updated definition of the FLB2Platform protocol after the API change in version 0.1.5. It removed accessibilityEnable and flutterCanPop, added entryForDart, and modified the required open and close methods. ```Objective-C @protocol FLB2Platform @optional - (NSString *)entryForDart; @required - (void)open:(NSString *)url urlParams:(NSDictionary *)urlParams exts:(NSDictionary *)exts completion:(void (^)(BOOL finished))completion; - (void)close:(NSString *)uid result:(NSDictionary *)result exts:(NSDictionary *)exts completion:(void (^)(BOOL finished))completion; @end ``` -------------------------------- ### Defining FlutterBoost Page Lifecycle Events (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/Frequently Asked Question.md Defines a custom enum `ContainerLifeCycle` used by FlutterBoost to manage the lifecycle events of Flutter pages within a mixed-stack navigation environment. This replaces the standard Flutter `AppLifecycleState` for better consistency. ```Dart enum ContainerLifeCycle { Init, Appear, WillDisappear, Disappear, Destroy, Background, Foreground } ``` -------------------------------- ### Checking FlutterBoost Container Visibility (Dart) Source: https://github.com/alibaba/flutter_boost/blob/main/Frequently Asked Question.md Provides a Dart API call using `FlutterBoost.BoostContainer.of(context).onstage` to determine if the Flutter widget or container associated with the given context is currently the top, visible container in the navigation stack. This helps avoid processing duplicate lifecycle messages. ```Dart bool isTopContainer = FlutterBoost.BoostContainer.of(context).onstage ``` -------------------------------- ### Closing Page - Flutter Boost (Android) Source: https://github.com/alibaba/flutter_boost/blob/main/docs/routeAPI.md Shows the Android API for closing a specific page using its unique ID. Notes that this method is used less frequently. ```Java FlutterBoost.instance().close(uniqueId); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.