Commit 86336d7a authored by hym's avatar hym

add platform view test page

parent 0057dc63
......@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application;
import android.content.Context;
import com.idlefish.flutterboost.BoostChannel;
import com.idlefish.flutterboost.BoostEngineProvider;
import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.FlutterBoost;
......@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication {
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context,url,urlParams,requestCode);
PageRouter.openPageByUrl(context, url, urlParams, requestCode);
}
@Override
public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider(){
return new BoostEngineProvider() {
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
"main"), "/");
}
};
}
......@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication {
return ANY_ACTIVITY_CREATED;
}
});
BoostChannel.addActionAfterRegistered(new BoostChannel.ActionAfterRegistered() {
@Override
public void onChannelRegistered(BoostChannel channel) {
//platform view register should use FlutterPluginRegistry instread of BoostPluginRegistry
TextPlatformViewPlugin.register(FlutterBoost.singleton().engineProvider().tryGetEngine().getPluginRegistry());
}
});
}
}
package com.taobao.idlefish.flutterboostexample;
import android.content.Context;
import android.view.View;
import android.widget.TextView;
import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;
public class TextPlatformViewFactory extends PlatformViewFactory {
public TextPlatformViewFactory(MessageCodec<Object> createArgsCodec) {
super(createArgsCodec);
}
@Override
public PlatformView create(Context context, int i, Object o) {
return new TextPlatformView(context);
}
private static class TextPlatformView implements PlatformView {
private TextView platformTv;
public TextPlatformView(Context context) {
platformTv = new TextView(context);
platformTv.setText("PlatformView Demo");
}
@Override
public View getView() {
return platformTv;
}
@Override
public void dispose() {
}
}
}
package com.taobao.idlefish.flutterboostexample;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.plugin.common.StandardMessageCodec;
public class TextPlatformViewPlugin {
public static void register(FlutterPluginRegistry registry) {
registry.getPlatformViewsController().getRegistry().registerViewFactory("plugins.test/view",
new TextPlatformViewFactory(StandardMessageCodec.INSTANCE));
}
}
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost_example/text_platform_view.dart';
class FirstRouteWidget extends StatelessWidget {
@override
......@@ -12,13 +13,11 @@ class FirstRouteWidget extends StatelessWidget {
child: RaisedButton(
child: Text('Open second route'),
onPressed: () {
print("open second page!");
FlutterBoost.singleton.open("second").then((Map value){
FlutterBoost.singleton.open("second").then((Map value) {
print("did recieve second route result");
print("did recieve second route result $value");
});
},
),
),
......@@ -38,8 +37,10 @@ class SecondRouteWidget extends StatelessWidget {
onPressed: () {
// Navigate back to first route when tapped.
BoostContainerSettings settings = BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"});
BoostContainerSettings settings =
BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,
result: {"result": "data from second"});
},
child: Text('Go back with result!'),
),
......@@ -103,7 +104,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () =>
FlutterBoost.singleton.open("sample://nativePage", urlParams:{
FlutterBoost.singleton.open("sample://nativePage", urlParams: {
"query": {"aaa": "bbb"}
}),
),
......@@ -120,7 +121,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb
onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage", urlParams:{
FlutterBoost.singleton.open("sample://flutterPage", urlParams: {
"query": {"aaa": "bbb"}
}),
),
......@@ -141,14 +142,26 @@ class FlutterRouteWidget extends StatelessWidget {
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: Text(
'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => FlutterBoost.singleton
.open("sample://flutterFragmentPage"),
onTap: () =>
FlutterBoost.singleton.open("sample://flutterFragmentPage"),
),
InkWell(
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(8.0),
color: Colors.yellow,
child: Text(
'open platform view page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => Navigator.of(context).push(
new MaterialPageRoute(builder: (_) => TextPlatformViewPage())),
)
],
),
......@@ -196,8 +209,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open native page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () =>
FlutterBoost.singleton.open("sample://nativePage"),
onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
),
InkWell(
child: Container(
......@@ -208,8 +220,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage"),
onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
),
InkWell(
child: Container(
......@@ -220,8 +231,8 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black),
)),
onTap: () => FlutterBoost.singleton
.open("sample://flutterFragmentPage"),
onTap: () =>
FlutterBoost.singleton.open("sample://flutterFragmentPage"),
)
],
),
......@@ -268,6 +279,6 @@ class _PushWidgetState extends State<PushWidget> {
@override
Widget build(BuildContext context) {
return FlutterRouteWidget(message:"Pushed Widget");
return FlutterRouteWidget(message: "Pushed Widget");
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment