Procházet zdrojové kódy

update plugin registration

Hadrien Lejard před 8 roky
rodič
revize
122ba7c940

+ 6 - 0
README.md

@@ -18,6 +18,12 @@ For help getting started with Flutter, view our online
 [documentation](http://flutter.io/).
 
 
+### Dart
+
+```dart
+FlutterWebviewPlugin flutterWebviewPlugin = new FlutterWebviewPlugin();
+```
+
 ### Android
 
 Add the Activity to you `AndroidManifest.xml`

+ 11 - 9
android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

@@ -1,12 +1,14 @@
 package com.flutter_webview_plugin;
 
 import android.content.Intent;
+import android.app.Activity;
+import android.content.Context;
 
 import io.flutter.app.FlutterActivity;
 import io.flutter.plugin.common.MethodCall;
 import io.flutter.plugin.common.MethodChannel;
 import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
-import io.flutter.plugin.common.MethodChannel.Result;
+import io.flutter.plugin.common.PluginRegistry;
 
 /**
  * FlutterWebviewPlugin
@@ -15,20 +17,20 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
   private FlutterActivity activity;
   public static MethodChannel channel;
   private final int WEBVIEW_ACTIVITY_CODE = 1;
-  private final String CHANNEL = "flutter_webview_plugin";
+  private static final String CHANNEL_NAME = "flutter_webview_plugin";
 
-  public static FlutterWebviewPlugin register(FlutterActivity activity) {
-    return new FlutterWebviewPlugin(activity);
+  public static void registerWith(PluginRegistry.Registrar registrar) {
+    channel = new MethodChannel(registrar.messenger(), CHANNEL_NAME);
+    FlutterWebviewPlugin instance = new FlutterWebviewPlugin((FlutterActivity) registrar.activity());
+    channel.setMethodCallHandler(instance);
   }
 
   private FlutterWebviewPlugin(FlutterActivity activity) {
     this.activity = activity;
-    channel = new MethodChannel(activity.getFlutterView(), CHANNEL);
-    channel.setMethodCallHandler(this);
   }
 
   @Override
-  public void onMethodCall(MethodCall call, Result result) {
+  public void onMethodCall(MethodCall call, MethodChannel.Result result) {
     switch (call.method) {
       case "launch":
         openUrl(call, result);
@@ -42,7 +44,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
     }
   }
 
-  private void openUrl(MethodCall call, Result result) {
+  private void openUrl(MethodCall call, MethodChannel.Result result) {
     Intent intent = new Intent(activity, WebviewActivity.class);
 
     intent.putExtra(WebviewActivity.URL_KEY, (String) call.argument("url"));
@@ -55,7 +57,7 @@ public class FlutterWebviewPlugin implements MethodCallHandler {
     result.success(null);
   }
 
-  private void close(MethodCall call, Result result) {
+  private void close(MethodCall call, MethodChannel.Result result) {
     activity.finishActivity(WEBVIEW_ACTIVITY_CODE);
     result.success(null);
   }

+ 2 - 3
ios/Classes/FlutterWebviewPlugin.h

@@ -1,5 +1,4 @@
 #import <Flutter/Flutter.h>
 
-@interface FlutterWebviewPlugin : NSObject
-- initWithController:(FlutterViewController *)controller;
-@end
+@interface FlutterWebviewPlugin : NSObject<FlutterPlugin>
+@end

+ 7 - 18
ios/Classes/FlutterWebviewPlugin.m

@@ -1,25 +1,14 @@
 #import "FlutterWebviewPlugin.h"
 
 @implementation FlutterWebviewPlugin {
-}
++ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
+  FlutterMethodChannel *channel =
+       [FlutterMethodChannel methodChannelWithName:CHANNEL_NAME binaryMessenger:registrar.messenger];
+   [channel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) {
+     NSString *method = [call method];
+     NSDictionary *arguments = [call arguments];
 
-- (instancetype)initWithController:(FlutterViewController *)controller {
-  self = [super init];
-  if (self) {
-    FlutterMethodChannel *channel = [FlutterMethodChannel
-        methodChannelWithName:@"flutter_webview_plugin"
-              binaryMessenger:controller];
-    [channel setMethodCallHandler:^(FlutterMethodCall *call,
-                                    FlutterResult result) {
-      if ([@"getPlatformVersion" isEqualToString:call.method]) {
-        result([@"iOS " stringByAppendingString:[[UIDevice currentDevice]
-                                                    systemVersion]]);
-      } else {
-        result(FlutterMethodNotImplemented);
-      }
-    }];
-  }
-  return self;
+     result(FlutterMethodNotImplemented);
 }
 
 @end

+ 0 - 1
lib/flutter_webview_plugin.dart

@@ -1,6 +1,5 @@
 import 'dart:async';
 
-import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 
 class FlutterWebviewPlugin {

+ 3 - 1
pubspec.yaml

@@ -1,6 +1,8 @@
 name: flutter_webview_plugin
-description: A new flutter plugin project.
+description: Plugin that allow Flutter to communicate with a native Webview.
 author: Hadrien Lejard <hadrien.lejard@gmail.com>
+homepage: https://github.com/dart-flitter/flutter_webview_plugin
+version: 0.0.2
 
 flutter:
   plugin: