From a8ba6798aca6051b70a0a117d9a6f2aa9ea6a50a Mon Sep 17 00:00:00 2001
From: "yangwu.jia" <yangwu.jia@taobao.com>
Date: Thu, 24 Oct 2019 15:48:50 +0800
Subject: [PATCH] =?UTF-8?q?add=E3=80=82Platform=20view=20demo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../flutterboostexample/MyApplication.java    |  7 ++-
 .../TextPlatformViewPlugin.java               |  5 +-
 example/lib/main.dart                         |  1 +
 example/lib/platform_view.dart                | 51 +++++++++++++++++++
 example/lib/simple_page_widgets.dart          | 38 ++++++++++++++
 5 files changed, 96 insertions(+), 6 deletions(-)
 create mode 100644 example/lib/platform_view.dart

diff --git a/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java b/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
index ba26fcf..b09b321 100755
--- a/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
+++ b/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/MyApplication.java
@@ -5,12 +5,10 @@ import android.content.Context;
 
 import android.util.Log;
 import com.idlefish.flutterboost.*;
-import com.idlefish.flutterboost.interfaces.IContainerRecord;
 
 import java.util.Map;
 
 import com.idlefish.flutterboost.interfaces.INativeRouter;
-import io.flutter.app.FlutterApplication;
 import io.flutter.plugin.common.MethodChannel;
 
 public class MyApplication extends Application {
@@ -36,8 +34,10 @@ public class MyApplication extends Application {
 
             @Override
             public void onPluginsRegistered() {
-                MethodChannel mMethodChannel = new MethodChannel( NewFlutterBoost.instance().engineProvider().getDartExecutor(), "boosttest");
+                MethodChannel mMethodChannel = new MethodChannel( NewFlutterBoost.instance().engineProvider().getDartExecutor(), "methodChannel");
                 Log.e("MyApplication","MethodChannel create");
+                TextPlatformViewPlugin.register(NewFlutterBoost.instance().getPluginRegistry().registrarFor("TextPlatformViewPlugin"));
+
             }
 
             @Override
@@ -56,6 +56,5 @@ public class MyApplication extends Application {
 
 
 
-
     }
 }
diff --git a/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/TextPlatformViewPlugin.java b/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/TextPlatformViewPlugin.java
index 8ed60aa..95e0d77 100644
--- a/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/TextPlatformViewPlugin.java
+++ b/example/android/app/src/main/java/com/taobao/idlefish/flutterboostexample/TextPlatformViewPlugin.java
@@ -1,11 +1,12 @@
 package com.taobao.idlefish.flutterboostexample;
 
 import io.flutter.app.FlutterPluginRegistry;
+import io.flutter.plugin.common.PluginRegistry;
 import io.flutter.plugin.common.StandardMessageCodec;
 
 public class TextPlatformViewPlugin {
-    public static void register(FlutterPluginRegistry registry) {
-        registry.getPlatformViewsController().getRegistry().registerViewFactory("plugins.test/view",
+    public static void register(PluginRegistry.Registrar registrar) {
+        registrar.platformViewRegistry().registerViewFactory("plugins.test/view",
                 new TextPlatformViewFactory(StandardMessageCodec.INSTANCE));
     }
 }
diff --git a/example/lib/main.dart b/example/lib/main.dart
index e4f3563..3331ee9 100755
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -20,6 +20,7 @@ class _MyAppState extends State<MyApp> {
       'first': (pageName, params, _) => FirstRouteWidget(),
       'second': (pageName, params, _) => SecondRouteWidget(),
       'tab': (pageName, params, _) => TabRouteWidget(),
+      'platformView': (pageName, params, _) => PlatformRouteWidget(),
       'flutterFragment': (pageName, params, _) => FragmentRouteWidget(params),
       ///可以在native层通过 getContainerParams 来传递参数
       'flutterPage': (pageName, params, _) {
diff --git a/example/lib/platform_view.dart b/example/lib/platform_view.dart
new file mode 100644
index 0000000..26d5b91
--- /dev/null
+++ b/example/lib/platform_view.dart
@@ -0,0 +1,51 @@
+import 'dart:async';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
+typedef void TextViewCreatedCallback(TextViewController controller);
+
+class TextView extends StatefulWidget {
+  const TextView({
+    Key key,
+    this.onTextViewCreated,
+  }) : super(key: key);
+
+  final TextViewCreatedCallback onTextViewCreated;
+
+  @override
+  State<StatefulWidget> createState() => _TextViewState();
+}
+
+class _TextViewState extends State<TextView> {
+  @override
+  Widget build(BuildContext context) {
+    if (defaultTargetPlatform == TargetPlatform.android) {
+      return AndroidView(
+        viewType: 'plugins.test/view',
+        onPlatformViewCreated: _onPlatformViewCreated,
+      );
+    }
+    return Text(
+        '$defaultTargetPlatform is not yet supported by the text_view plugin');
+  }
+
+  void _onPlatformViewCreated(int id) {
+    if (widget.onTextViewCreated == null) {
+      return;
+    }
+    widget.onTextViewCreated(new TextViewController._(id));
+  }
+}
+
+class TextViewController {
+  TextViewController._(int id)
+      : _channel = new MethodChannel('plugins.felix.angelov/textview_$id');
+
+  final MethodChannel _channel;
+
+  Future<void> setText(String text) async {
+    assert(text != null);
+    return _channel.invokeMethod('setText', text);
+  }
+}
\ No newline at end of file
diff --git a/example/lib/simple_page_widgets.dart b/example/lib/simple_page_widgets.dart
index 1dbee6f..c905c34 100755
--- a/example/lib/simple_page_widgets.dart
+++ b/example/lib/simple_page_widgets.dart
@@ -1,6 +1,7 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_boost/flutter_boost.dart';
+import 'package:flutter_boost_example/platform_view.dart';
 
 class FirstRouteWidget extends StatelessWidget {
   @override
@@ -68,6 +69,28 @@ class TabRouteWidget extends StatelessWidget {
   }
 }
 
+class PlatformRouteWidget extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(
+        title:Text("Platform Route"),
+      ),
+      body: Center(
+        child: RaisedButton(
+          child: TextView(),
+          onPressed: () {
+            print("open second page!");
+            FlutterBoost.singleton.open("second").then((Map value) {
+              print(
+                  "call me when page is finished. did recieve second route result $value");
+            });
+          },
+        ),
+      ),
+    );
+  }
+}
 class FlutterRouteWidget extends StatefulWidget {
   FlutterRouteWidget({this.params,this.message});
   final Map params;
@@ -216,6 +239,21 @@ class _FlutterRouteWidgetState extends State<FlutterRouteWidget> {
                         MaterialPageRoute(builder: (_) => PushWidget()));
                   },
                 ),
+
+              InkWell(
+                child: Container(
+                    padding: const EdgeInsets.all(8.0),
+                    margin: const EdgeInsets.all(8.0),
+                    color: Colors.yellow,
+                    child: Text(
+                      'push Platform demo',
+                      style: TextStyle(fontSize: 22.0, color: Colors.black),
+                    )),
+                onTap: () {
+                  Navigator.push(context,
+                      MaterialPageRoute(builder: (_) => PlatformRouteWidget()));
+                },
+              ),
                 InkWell(
                   child: Container(
                       padding: const EdgeInsets.all(8.0),
-- 
2.26.2