FlutterBoost3.0的集成与使⽤详解⼀.FlutterBoost3.0介绍
1. flutter sdk升级不需要升级boost
2. 简化架构
3. 简化接⼝
4. 双端接⼝设计统⼀
5. 解决了top issue
6. android不需要区分androidx 和support
其他介绍参照:
⼆.FlutterBoost3.0接⼊
下⾯来介绍⼀下完整的接⼊流程:
开发⼯具:AndroidStudio&Xcode(⾄于vsCode⾃⼰琢磨哈)
1.创建项⽬,FlutterBoost3.0创建项⽬跟创建⼀个flutter项⽬⼀致
2.添加FlutterBoost依赖
flutter_boost:
git:
url: 'github/alibaba/flutter_boost.git'
ref: 'v3.0-preview.16'
3.在Dart端的main.dart进⾏修改如下:
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:test_flutter_boost/other_page.dart';
import 'package:test_flutter_boost/splash_page.dart';
void main() {
PageVisibilityBinding.instance
.addGlobalObserver(AppGlobalPageVisibilityObserver());
CustomFlutterBinding();
runApp(MyApp());
}
class AppGlobalPageVisibilityObserver extends GlobalPageVisibilityObserver {
@override
void onPagePush(Route<dynamic> route) {
Logger.log(
'boost_lifecycle: PageCreate route:${route.settings.name}');  }
@override
void onPageShow(Route<dynamic> route) {
Logger.log(
'boost_lifecycle: PageShow route:${route.settings.name}');  }
@override
void onPageHide(Route<dynamic> route) {
Logger.log(
'boost_lifecycle: PageHide route:${route.settings.name}');
}
@override
void onPagePop(Route<dynamic> route) {
Logger.log(
'boost_lifecycle: PageDestroy route:${route.settings.name}');  }
@override
void onForeground(Route route) {
Logger.log(
'boost_lifecycle: Foreground route:${route.settings.name}');  }
@override
void onBackground(Route<dynamic> route) {
Logger.log(
'boost_lifecycle: Background route:${route.settings.name}');  }
}
class CustomFlutterBinding extends WidgetsFlutterBinding
with BoostFlutterBinding {}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static Map<String, FlutterBoostRouteFactory> routerMap = {
'splash': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings,
pageBuilder: (_, __, ___) => SplashPage());
},
'otherPage': (settings, uniqueId) {
return PageRouteBuilder<dynamic>(
settings: settings,
pageBuilder: (_, __, ___) => OtherPage());
},
};
Route<dynamic> routeFactory(RouteSettings settings, String uniqueId) {
FlutterBoostRouteFactory func = routerMap[settings.name];
if (func == null) {
return null;
}
return func(settings, uniqueId);
}
安卓intent用法
@override
void initState() {
super.initState();
}
Widget appBuilder(Widget home) {
return MaterialApp(
home: home,
debugShowCheckedModeBanner: true,
///必须加上builder参数,否则showDialog等会出问题
builder: (_, __) {
return home;
},
)
;
}
@override
Widget build(BuildContext context) {
return FlutterBoostApp(
routeFactory,
appBuilder: appBuilder,
initialRoute: "splash",
);
}
}
class BoostNavigatorObserver extends NavigatorObserver {
@override
@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
print('boost-didPush' + route.settings.name);
}
@override
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
print('boost-didPop' + route.settings.name);
}
@override
void didRemove(Route<dynamic> route, Route<dynamic> previousRoute) {
print('boost-didRemove' + route.settings.name);
}
@override
void didStartUserGesture(Route<dynamic> route, Route<dynamic> previousRoute) {    print('boost-didStartUserGesture' + route.settings.name);
}
}
SplashPage()代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
class SplashPage extends StatefulWidget {
@override
_SplashPageState createState() => _SplashPageState(); }
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
Logger.log('boost-SplashPage $mounted');
}
@override
Widget build(BuildContext context) {
Logger.log('boost-SplashPage $mounted');
return Scaffold(
appBar: AppBar(
title:  Text("Flutter 页⾯"),
),
body: Flex(
direction: Axis.vertical,
children: [
GestureDetector(
onTap: (){
BoostNavigator.instance.push("native");
},
child: Text(
"打开源⽣页⾯"
),
)
],
),
);
}
}
OtherPage()代码:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。