Commit 86336d7a authored by hym's avatar hym

add platform view test page

parent 0057dc63
...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample; ...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import com.idlefish.flutterboost.BoostChannel;
import com.idlefish.flutterboost.BoostEngineProvider; import com.idlefish.flutterboost.BoostEngineProvider;
import com.idlefish.flutterboost.BoostFlutterEngine; import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.FlutterBoost; import com.idlefish.flutterboost.FlutterBoost;
...@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication { ...@@ -34,18 +35,18 @@ public class MyApplication extends FlutterApplication {
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { 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 @Override
public IFlutterEngineProvider engineProvider() { public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider(){ return new BoostEngineProvider() {
@Override @Override
public BoostFlutterEngine createEngine(Context context) { public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint( return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(), context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context), FlutterMain.findAppBundlePath(context),
"main"),"/"); "main"), "/");
} }
}; };
} }
...@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication { ...@@ -55,5 +56,13 @@ public class MyApplication extends FlutterApplication {
return ANY_ACTIVITY_CREATED; 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/material.dart';
import 'package:flutter_boost/flutter_boost.dart'; import 'package:flutter_boost/flutter_boost.dart';
import 'package:flutter_boost_example/text_platform_view.dart';
class FirstRouteWidget extends StatelessWidget { class FirstRouteWidget extends StatelessWidget {
@override @override
...@@ -12,13 +13,11 @@ class FirstRouteWidget extends StatelessWidget { ...@@ -12,13 +13,11 @@ class FirstRouteWidget extends StatelessWidget {
child: RaisedButton( child: RaisedButton(
child: Text('Open second route'), child: Text('Open second route'),
onPressed: () { onPressed: () {
print("open second page!"); 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");
print("did recieve second route result $value"); print("did recieve second route result $value");
}); });
}, },
), ),
), ),
...@@ -37,9 +36,11 @@ class SecondRouteWidget extends StatelessWidget { ...@@ -37,9 +36,11 @@ class SecondRouteWidget extends StatelessWidget {
child: RaisedButton( child: RaisedButton(
onPressed: () { onPressed: () {
// Navigate back to first route when tapped. // Navigate back to first route when tapped.
BoostContainerSettings settings = BoostContainer.of(context).settings; BoostContainerSettings settings =
FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"}); BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,
result: {"result": "data from second"});
}, },
child: Text('Go back with result!'), child: Text('Go back with result!'),
), ),
...@@ -103,7 +104,7 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -103,7 +104,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。 ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb ///例如:sample://nativePage?aaa=bbb
onTap: () => onTap: () =>
FlutterBoost.singleton.open("sample://nativePage", urlParams:{ FlutterBoost.singleton.open("sample://nativePage", urlParams: {
"query": {"aaa": "bbb"} "query": {"aaa": "bbb"}
}), }),
), ),
...@@ -120,7 +121,7 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -120,7 +121,7 @@ class FlutterRouteWidget extends StatelessWidget {
///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。 ///后面的参数会在native的IPlatform.startActivity方法回调中拼接到url的query部分。
///例如:sample://nativePage?aaa=bbb ///例如:sample://nativePage?aaa=bbb
onTap: () => onTap: () =>
FlutterBoost.singleton.open("sample://flutterPage", urlParams:{ FlutterBoost.singleton.open("sample://flutterPage", urlParams: {
"query": {"aaa": "bbb"} "query": {"aaa": "bbb"}
}), }),
), ),
...@@ -141,14 +142,26 @@ class FlutterRouteWidget extends StatelessWidget { ...@@ -141,14 +142,26 @@ class FlutterRouteWidget extends StatelessWidget {
InkWell( InkWell(
child: Container( child: Container(
padding: const EdgeInsets.all(8.0), 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, color: Colors.yellow,
child: Text( child: Text(
'open flutter fragment page', 'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => FlutterBoost.singleton onTap: () =>
.open("sample://flutterFragmentPage"), 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 { ...@@ -196,8 +209,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open native page', 'open native page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
FlutterBoost.singleton.open("sample://nativePage"),
), ),
InkWell( InkWell(
child: Container( child: Container(
...@@ -208,8 +220,7 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -208,8 +220,7 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter page', 'open flutter page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
FlutterBoost.singleton.open("sample://flutterPage"),
), ),
InkWell( InkWell(
child: Container( child: Container(
...@@ -220,8 +231,8 @@ class FragmentRouteWidget extends StatelessWidget { ...@@ -220,8 +231,8 @@ class FragmentRouteWidget extends StatelessWidget {
'open flutter fragment page', 'open flutter fragment page',
style: TextStyle(fontSize: 22.0, color: Colors.black), style: TextStyle(fontSize: 22.0, color: Colors.black),
)), )),
onTap: () => FlutterBoost.singleton onTap: () =>
.open("sample://flutterFragmentPage"), FlutterBoost.singleton.open("sample://flutterFragmentPage"),
) )
], ],
), ),
...@@ -268,6 +279,6 @@ class _PushWidgetState extends State<PushWidget> { ...@@ -268,6 +279,6 @@ class _PushWidgetState extends State<PushWidget> {
@override @override
Widget build(BuildContext context) { 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