書接上回!!!查看上回api
上回咱們說到Flutter
內部跳轉而且完成傳值此次來個Flutter
跳轉Native
而且完成傳值bash
Flutter
TO Native
上面已經說到第二個Flutter
頁面了,咱們繼續從這裏開始app
class SecondRouteWidget extends StatefulWidget {
final Map<dynamic, dynamic> params;
SecondRouteWidget(this.params);
@override
_SecondRouteWidgetState createState() => _SecondRouteWidgetState();
}
<!--而後接受一下-->
class _SecondRouteWidgetState extends State<SecondRouteWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('secondPage'),
),
body: Center(
child: Column(
child: RaisedButton(
child: Text("跳轉原生界面"),
onPressed: () {
// 打開原生頁面
<!--這裏 open 打開的東西其實就是咱們原生裏面 PlatformRouterImp 類裏面的 open 方法,
後面的參數就是咱們 PlatformRouterImp 裏面open裏面的 url 經過這個 url 咱們能夠判斷打開咱們相應的界面,
一、urlParams 傳人頁面的參數; 如有特殊邏輯,能夠經過這個參數設置回調的id
二、exts 額外參數
三、completion 打開頁面的即時回調,頁面一旦打開即回調-->
FlutterBoost.singleton.open("sample://LoginPage",
urlParams: {"userName": "ryan", "password": "123456"},
exts:null(也能夠不寫這個參數名,他是可選的));
},
),
),
),
);
}
}
複製代碼
原生裏面咱們在 PlatformRouterImp
這個類裏面判斷一下ide
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;
}
if url.contains("sample://LoginPage") {
let vc = JTOrderDetailViewController()
vc.hidesBottomBarWhenPushed = true
vc.flutterdata = urlParams
topVC?.navigationController?.pushViewController(vc, animated: animated);
} else {
let vc = FLBFlutterViewContainer.init()
vc.setName(url, params: urlParams)
vc.navigation.bar.isHidden = true
vc.hidesBottomBarWhenPushed = true
topVC?.navigationController!.pushViewController(vc, animated: animated);
}
completion(true);
}
複製代碼
這樣就打開咱們原生界面了,而且傳過來的值也在urlParams
這裏面,額外參數咱們沒有作任何參數傳遞。post
最後一步咱們原生返回Flutter
頁面,這裏咱們須要本身寫一個通道了。它裏面沒有,直接上代碼 咱們在原生裏面監聽返回按鈕的點擊事件而後經過FlutterBoostPlugin.sharedInstance().sendEvent
這樣把東西傳過去學習
navigation.bar.backBarButtonItem?.didBack = {
self.navigationController?.popViewController(animated: true)
FlutterBoostPlugin.sharedInstance().sendEvent("NativeDetailPageCallback", arguments: ["name":"detailPage","number":"1000"]);
}
複製代碼
咱們在Dart
裏面ui
// 原生界面返回傳值獲取
FlutterBoost.singleton.channel.addEventListener(
"NativeDetailPageCallback",
(name, arguments) {
return handleMsg(name, arguments);
},
複製代碼
這裏咱們就能監聽到原生傳過來的值了。截止到如今基本上完成了從原生到Flutter
, 而後Flutter
到Flutter
,Flutter
到原生,之間的全部聯繫了。this
我是初學者,這裏是記錄一下本身在學習Flutter_boost
時候的學習筆記吧,和你們一塊兒分享一下。若是不妥的地方還請路過的大佬不吝賜教!!!!!!url