Hadrien Lejard 8 năm trước cách đây
mục cha
commit
f2b4436fa9
4 tập tin đã thay đổi với 47 bổ sung20 xóa
  1. 2 0
      .analysis_options
  2. 7 0
      CHANGELOG.md
  3. 37 19
      lib/flutter_webview_plugin.dart
  4. 1 1
      pubspec.yaml

+ 2 - 0
.analysis_options

@@ -0,0 +1,2 @@
+analyzer:
+  strong-mode: true

+ 7 - 0
CHANGELOG.md

@@ -0,0 +1,7 @@
+# 0.0.3
+
+- Documentation
+
+# 0.0.2
+
+- Initial version for Android

+ 37 - 19
lib/flutter_webview_plugin.dart

@@ -2,21 +2,52 @@ import 'dart:async';
 
 import 'package:flutter/services.dart';
 
+const _kChannel = 'flutter_webview_plugin';
+
+/// Singleton Class that communicate with a fullscreen Webview Instance
+/// Have to be instanciate after `runApp` called.
 class FlutterWebviewPlugin {
+
+  final MethodChannel _channel = const MethodChannel(_kChannel);
+  StreamController<Null> _onDestroy = new StreamController.broadcast();
+  StreamController<Null> _onBackPressed = new StreamController.broadcast();
+
   static FlutterWebviewPlugin _instance;
   FlutterWebviewPlugin._() {
     _init();
   }
+
   factory FlutterWebviewPlugin() => _instance ??= new FlutterWebviewPlugin._();
 
-  StreamController<Null> _onDestroy = new StreamController.broadcast();
+  _init() {
+    _channel.setMethodCallHandler(_handleMessages);
+  }
+
+  Future<Null> _handleMessages(MethodCall call) async {
+    switch (call.method) {
+      case "onDestroy":
+        _onDestroy.add(null);
+        break;
+      case "onBackPressed":
+        _onBackPressed.add(null);
+        break;
+    }
+  }
+
+  //////////////////////
+
+  /// Listening the OnDestroy LifeCycle Event for Android
+  ///
   Stream<Null> get onDestroy => _onDestroy.stream;
 
-  StreamController<Null> _onBackPressed = new StreamController.broadcast();
+  /// Listening the onBackPressed Event for Android
+  ///
   Stream<Null> get onBackPressed => _onBackPressed.stream;
 
-  final MethodChannel _channel = const MethodChannel('flutter_webview_plugin');
-
+  /// Start the Webview with [url]
+  /// - [withJavascript] enable Javascript or not for the Webview
+  /// - [clearCache] clear the cache of the Webview
+  /// - clearCookies] clear all cookies of the Webview
   Future<Null> launch(String url,
           {bool withJavascript: true,
           bool clearCache: false,
@@ -28,20 +59,7 @@ class FlutterWebviewPlugin {
         "clearCookies": clearCookies
       });
 
+  /// Close the Webview
+  /// Will trigger the [onDestroy] event
   Future<Null> close() => _channel.invokeMethod("close");
-
-  _init() {
-    _channel.setMethodCallHandler(_handleMessages);
-  }
-
-  Future<Null> _handleMessages(MethodCall call) async {
-    switch (call.method) {
-      case "onDestroy":
-        _onDestroy.add(null);
-        break;
-      case "onBackPressed":
-        _onBackPressed.add(null);
-        break;
-    }
-  }
 }

+ 1 - 1
pubspec.yaml

@@ -2,7 +2,7 @@ name: flutter_webview_plugin
 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
+version: 0.0.3
 
 flutter:
   plugin: