Procházet zdrojové kódy

Formatting and cleaning of code.

Simon Lightfoot před 7 roky
rodič
revize
9f4964ef7b

+ 68 - 69
example/lib/main.dart

@@ -10,59 +10,62 @@ const kAndroidUserAgent =
 String selectedUrl = 'https://flutter.io';
 String selectedUrl = 'https://flutter.io';
 
 
 void main() {
 void main() {
-  runApp(new MyApp());
+  runApp(MyApp());
 }
 }
 
 
 class MyApp extends StatelessWidget {
 class MyApp extends StatelessWidget {
-  final flutterWebviewPlugin = new FlutterWebviewPlugin();
+  final flutterWebViewPlugin = FlutterWebviewPlugin();
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    return new MaterialApp(
+    return MaterialApp(
       title: 'Flutter WebView Demo',
       title: 'Flutter WebView Demo',
-      theme: new ThemeData(
+      theme: ThemeData(
         primarySwatch: Colors.blue,
         primarySwatch: Colors.blue,
       ),
       ),
       routes: {
       routes: {
         '/': (_) => const MyHomePage(title: 'Flutter WebView Demo'),
         '/': (_) => const MyHomePage(title: 'Flutter WebView Demo'),
-        '/widget': (_) => new WebviewScaffold(
-              url: selectedUrl,
-              appBar: new AppBar(
-                title: const Text('Widget webview'),
-              ),
-              withZoom: true,
-              withLocalStorage: true,
-              hidden: true,
-              initialChild: Container(
-                color: Colors.redAccent,
-                child: const Center(
-                  child: Text('Waiting.....'),
-                ),
+        '/widget': (_) {
+          return WebviewScaffold(
+            url: selectedUrl,
+            appBar: AppBar(
+              title: const Text('Widget WebView'),
+            ),
+            withZoom: true,
+            withLocalStorage: true,
+            hidden: true,
+            initialChild: Container(
+              color: Colors.redAccent,
+              child: const Center(
+                child: Text('Waiting.....'),
               ),
               ),
-              bottomNavigationBar: BottomAppBar(
-                  child: Row(
+            ),
+            bottomNavigationBar: BottomAppBar(
+              child: Row(
                 children: <Widget>[
                 children: <Widget>[
                   IconButton(
                   IconButton(
                     icon: const Icon(Icons.arrow_back_ios),
                     icon: const Icon(Icons.arrow_back_ios),
                     onPressed: () {
                     onPressed: () {
-                      flutterWebviewPlugin.goBack();
+                      flutterWebViewPlugin.goBack();
                     },
                     },
                   ),
                   ),
                   IconButton(
                   IconButton(
                     icon: const Icon(Icons.arrow_forward_ios),
                     icon: const Icon(Icons.arrow_forward_ios),
                     onPressed: () {
                     onPressed: () {
-                      flutterWebviewPlugin.goForward();
+                      flutterWebViewPlugin.goForward();
                     },
                     },
                   ),
                   ),
                   IconButton(
                   IconButton(
                     icon: const Icon(Icons.autorenew),
                     icon: const Icon(Icons.autorenew),
                     onPressed: () {
                     onPressed: () {
-                      flutterWebviewPlugin.reload();
+                      flutterWebViewPlugin.reload();
                     },
                     },
                   ),
                   ),
                 ],
                 ],
-              )),
-            )
+              ),
+            ),
+          );
+        },
       },
       },
     );
     );
   }
   }
@@ -74,12 +77,12 @@ class MyHomePage extends StatefulWidget {
   final String title;
   final String title;
 
 
   @override
   @override
-  _MyHomePageState createState() => new _MyHomePageState();
+  _MyHomePageState createState() => _MyHomePageState();
 }
 }
 
 
 class _MyHomePageState extends State<MyHomePage> {
 class _MyHomePageState extends State<MyHomePage> {
   // Instance of WebView plugin
   // Instance of WebView plugin
-  final flutterWebviewPlugin = new FlutterWebviewPlugin();
+  final flutterWebViewPlugin = FlutterWebviewPlugin();
 
 
   // On destroy stream
   // On destroy stream
   StreamSubscription _onDestroy;
   StreamSubscription _onDestroy;
@@ -96,12 +99,11 @@ class _MyHomePageState extends State<MyHomePage> {
 
 
   StreamSubscription<double> _onScrollXChanged;
   StreamSubscription<double> _onScrollXChanged;
 
 
-  final _urlCtrl = new TextEditingController(text: selectedUrl);
+  final _urlCtrl = TextEditingController(text: selectedUrl);
 
 
-  final _codeCtrl =
-      new TextEditingController(text: 'window.navigator.userAgent');
+  final _codeCtrl = TextEditingController(text: 'window.navigator.userAgent');
 
 
-  final _scaffoldKey = new GlobalKey<ScaffoldState>();
+  final _scaffoldKey = GlobalKey<ScaffoldState>();
 
 
   final _history = [];
   final _history = [];
 
 
@@ -109,23 +111,22 @@ class _MyHomePageState extends State<MyHomePage> {
   void initState() {
   void initState() {
     super.initState();
     super.initState();
 
 
-    flutterWebviewPlugin.close();
+    flutterWebViewPlugin.close();
 
 
     _urlCtrl.addListener(() {
     _urlCtrl.addListener(() {
       selectedUrl = _urlCtrl.text;
       selectedUrl = _urlCtrl.text;
     });
     });
 
 
     // Add a listener to on destroy WebView, so you can make came actions.
     // Add a listener to on destroy WebView, so you can make came actions.
-    _onDestroy = flutterWebviewPlugin.onDestroy.listen((_) {
+    _onDestroy = flutterWebViewPlugin.onDestroy.listen((_) {
       if (mounted) {
       if (mounted) {
         // Actions like show a info toast.
         // Actions like show a info toast.
-        _scaffoldKey.currentState.showSnackBar(
-            const SnackBar(content: const Text('Webview Destroyed')));
+        _scaffoldKey.currentState.showSnackBar(const SnackBar(content: const Text('Webview Destroyed')));
       }
       }
     });
     });
 
 
     // Add a listener to on url changed
     // Add a listener to on url changed
-    _onUrlChanged = flutterWebviewPlugin.onUrlChanged.listen((String url) {
+    _onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((String url) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
           _history.add('onUrlChanged: $url');
           _history.add('onUrlChanged: $url');
@@ -133,27 +134,23 @@ class _MyHomePageState extends State<MyHomePage> {
       }
       }
     });
     });
 
 
-    _onScrollYChanged =
-        flutterWebviewPlugin.onScrollYChanged.listen((double y) {
+    _onScrollYChanged = flutterWebViewPlugin.onScrollYChanged.listen((double y) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
-          _history.add("Scroll in  Y Direction: $y");
+          _history.add('Scroll in Y Direction: $y');
         });
         });
       }
       }
     });
     });
 
 
-    _onScrollXChanged =
-        flutterWebviewPlugin.onScrollXChanged.listen((double x) {
+    _onScrollXChanged = flutterWebViewPlugin.onScrollXChanged.listen((double x) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
-          _history.add("Scroll in  X Direction: $x");
+          _history.add('Scroll in X Direction: $x');
         });
         });
       }
       }
     });
     });
 
 
-    _onStateChanged =
-        flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged state) {
-
+    _onStateChanged = flutterWebViewPlugin.onStateChanged.listen((WebViewStateChanged state) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
           _history.add('onStateChanged: ${state.type} ${state.url}');
           _history.add('onStateChanged: ${state.type} ${state.url}');
@@ -161,8 +158,7 @@ class _MyHomePageState extends State<MyHomePage> {
       }
       }
     });
     });
 
 
-    _onHttpError =
-        flutterWebviewPlugin.onHttpError.listen((WebViewHttpError error) {
+    _onHttpError = flutterWebViewPlugin.onHttpError.listen((WebViewHttpError error) {
       if (mounted) {
       if (mounted) {
         setState(() {
         setState(() {
           _history.add('onHttpError: ${error.code} ${error.url}');
           _history.add('onHttpError: ${error.code} ${error.url}');
@@ -181,58 +177,61 @@ class _MyHomePageState extends State<MyHomePage> {
     _onScrollXChanged.cancel();
     _onScrollXChanged.cancel();
     _onScrollYChanged.cancel();
     _onScrollYChanged.cancel();
 
 
-    flutterWebviewPlugin.dispose();
+    flutterWebViewPlugin.dispose();
 
 
     super.dispose();
     super.dispose();
   }
   }
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    return new Scaffold(
+    return Scaffold(
       key: _scaffoldKey,
       key: _scaffoldKey,
-      appBar: new AppBar(
+      appBar: AppBar(
         title: const Text('Plugin example app'),
         title: const Text('Plugin example app'),
       ),
       ),
       body: SingleChildScrollView(
       body: SingleChildScrollView(
-        child: new Column(
+        child: Column(
           mainAxisAlignment: MainAxisAlignment.center,
           mainAxisAlignment: MainAxisAlignment.center,
           children: [
           children: [
-            new Container(
+            Container(
               padding: const EdgeInsets.all(24.0),
               padding: const EdgeInsets.all(24.0),
-              child: new TextField(controller: _urlCtrl),
+              child: TextField(controller: _urlCtrl),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
-                flutterWebviewPlugin.launch(selectedUrl,
-                    rect: new Rect.fromLTWH(0.0, 0.0, MediaQuery.of(context).size.width, 300.0), userAgent: kAndroidUserAgent);
+                flutterWebViewPlugin.launch(
+                  selectedUrl,
+                  rect: Rect.fromLTWH(0.0, 0.0, MediaQuery.of(context).size.width, 300.0),
+                  userAgent: kAndroidUserAgent,
+                );
               },
               },
               child: const Text('Open Webview (rect)'),
               child: const Text('Open Webview (rect)'),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
-                flutterWebviewPlugin.launch(selectedUrl, hidden: true);
+                flutterWebViewPlugin.launch(selectedUrl, hidden: true);
               },
               },
               child: const Text('Open "hidden" Webview'),
               child: const Text('Open "hidden" Webview'),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
-                flutterWebviewPlugin.launch(selectedUrl);
+                flutterWebViewPlugin.launch(selectedUrl);
               },
               },
               child: const Text('Open Fullscreen Webview'),
               child: const Text('Open Fullscreen Webview'),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
                 Navigator.of(context).pushNamed('/widget');
                 Navigator.of(context).pushNamed('/widget');
               },
               },
               child: const Text('Open widget webview'),
               child: const Text('Open widget webview'),
             ),
             ),
-            new Container(
+            Container(
               padding: const EdgeInsets.all(24.0),
               padding: const EdgeInsets.all(24.0),
-              child: new TextField(controller: _codeCtrl),
+              child: TextField(controller: _codeCtrl),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
-                final future = flutterWebviewPlugin.evalJavascript(_codeCtrl.text);
+                final future = flutterWebViewPlugin.evalJavascript(_codeCtrl.text);
                 future.then((String result) {
                 future.then((String result) {
                   setState(() {
                   setState(() {
                     _history.add('eval: $result');
                     _history.add('eval: $result');
@@ -241,18 +240,18 @@ class _MyHomePageState extends State<MyHomePage> {
               },
               },
               child: const Text('Eval some javascript'),
               child: const Text('Eval some javascript'),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
                 setState(() {
                 setState(() {
                   _history.clear();
                   _history.clear();
                 });
                 });
-                flutterWebviewPlugin.close();
+                flutterWebViewPlugin.close();
               },
               },
               child: const Text('Close'),
               child: const Text('Close'),
             ),
             ),
-            new RaisedButton(
+            RaisedButton(
               onPressed: () {
               onPressed: () {
-                flutterWebviewPlugin.getCookies().then((m) {
+                flutterWebViewPlugin.getCookies().then((m) {
                   setState(() {
                   setState(() {
                     _history.add('cookies: $m');
                     _history.add('cookies: $m');
                   });
                   });
@@ -260,7 +259,7 @@ class _MyHomePageState extends State<MyHomePage> {
               },
               },
               child: const Text('Cookies'),
               child: const Text('Cookies'),
             ),
             ),
-            new Text(_history.join('\n'))
+            Text(_history.join('\n'))
           ],
           ],
         ),
         ),
       ),
       ),

+ 3 - 3
ios/Classes/FlutterWebviewPlugin.m

@@ -14,10 +14,10 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
     channel = [FlutterMethodChannel
     channel = [FlutterMethodChannel
                methodChannelWithName:CHANNEL_NAME
                methodChannelWithName:CHANNEL_NAME
                binaryMessenger:[registrar messenger]];
                binaryMessenger:[registrar messenger]];
-    
+
     UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
     UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
     FlutterWebviewPlugin* instance = [[FlutterWebviewPlugin alloc] initWithViewController:viewController];
     FlutterWebviewPlugin* instance = [[FlutterWebviewPlugin alloc] initWithViewController:viewController];
-    
+
     [registrar addMethodCallDelegate:instance channel:channel];
     [registrar addMethodCallDelegate:instance channel:channel];
 }
 }
 
 
@@ -48,7 +48,7 @@ static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
         result(nil);
         result(nil);
     } else if ([@"reloadUrl" isEqualToString:call.method]) {
     } else if ([@"reloadUrl" isEqualToString:call.method]) {
         [self reloadUrl:call];
         [self reloadUrl:call];
-        result(nil);	
+        result(nil);
     } else if ([@"show" isEqualToString:call.method]) {
     } else if ([@"show" isEqualToString:call.method]) {
         [self show];
         [self show];
         result(nil);
         result(nil);

+ 50 - 62
lib/src/base.dart

@@ -1,6 +1,5 @@
 import 'dart:async';
 import 'dart:async';
 import 'dart:ui';
 import 'dart:ui';
-import 'dart:io';
 
 
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:flutter/services.dart';
@@ -12,25 +11,24 @@ enum WebViewState { shouldStart, startLoad, finishLoad }
 
 
 // TODO: use an id by webview to be able to manage multiple webview
 // TODO: use an id by webview to be able to manage multiple webview
 
 
-/// Singleton Class that communicate with a Webview Instance
-/// Have to be instanciate after `runApp` called.
+/// Singleton class that communicate with a Webview Instance
 class FlutterWebviewPlugin {
 class FlutterWebviewPlugin {
-  final _channel = const MethodChannel(_kChannel);
+  factory FlutterWebviewPlugin() => _instance ??= FlutterWebviewPlugin._();
 
 
-  final _onDestroy = new StreamController<Null>.broadcast();
-  final _onUrlChanged = new StreamController<String>.broadcast();
-  final _onStateChanged = new StreamController<WebViewStateChanged>.broadcast();
-  final _onScrollXChanged = new StreamController<double>.broadcast();
-  final _onScrollYChanged = new StreamController<double>.broadcast();
-  final _onHttpError = new StreamController<WebViewHttpError>.broadcast();
+  FlutterWebviewPlugin._() {
+    _channel.setMethodCallHandler(_handleMessages);
+  }
 
 
   static FlutterWebviewPlugin _instance;
   static FlutterWebviewPlugin _instance;
 
 
-  factory FlutterWebviewPlugin() => _instance ??= new FlutterWebviewPlugin._();
+  final _channel = const MethodChannel(_kChannel);
 
 
-  FlutterWebviewPlugin._() {
-    _channel.setMethodCallHandler(_handleMessages);
-  }
+  final _onDestroy = StreamController<Null>.broadcast();
+  final _onUrlChanged = StreamController<String>.broadcast();
+  final _onStateChanged = StreamController<WebViewStateChanged>.broadcast();
+  final _onScrollXChanged = StreamController<double>.broadcast();
+  final _onScrollYChanged = StreamController<double>.broadcast();
+  final _onHttpError = StreamController<WebViewHttpError>.broadcast();
 
 
   Future<Null> _handleMessages(MethodCall call) async {
   Future<Null> _handleMessages(MethodCall call) async {
     switch (call.method) {
     switch (call.method) {
@@ -40,21 +38,21 @@ class FlutterWebviewPlugin {
       case 'onUrlChanged':
       case 'onUrlChanged':
         _onUrlChanged.add(call.arguments['url']);
         _onUrlChanged.add(call.arguments['url']);
         break;
         break;
-      case "onScrollXChanged":
-        _onScrollXChanged.add(call.arguments["xDirection"]);
+      case 'onScrollXChanged':
+        _onScrollXChanged.add(call.arguments['xDirection']);
         break;
         break;
-      case "onScrollYChanged":
-        _onScrollYChanged.add(call.arguments["yDirection"]);
+      case 'onScrollYChanged':
+        _onScrollYChanged.add(call.arguments['yDirection']);
         break;
         break;
-      case "onState":
+      case 'onState':
         _onStateChanged.add(
         _onStateChanged.add(
-          new WebViewStateChanged.fromMap(
-              new Map<String, dynamic>.from(call.arguments)),
+          WebViewStateChanged.fromMap(
+            Map<String, dynamic>.from(call.arguments),
+          ),
         );
         );
         break;
         break;
       case 'onHttpError':
       case 'onHttpError':
-        _onHttpError.add(
-            WebViewHttpError(call.arguments['code'], call.arguments['url']));
+        _onHttpError.add(WebViewHttpError(call.arguments['code'], call.arguments['url']));
         break;
         break;
     }
     }
   }
   }
@@ -96,23 +94,23 @@ class FlutterWebviewPlugin {
   /// - [withLocalUrl]: allow url as a local path
   /// - [withLocalUrl]: allow url as a local path
   ///     Allow local files on iOs > 9.0
   ///     Allow local files on iOs > 9.0
   /// - [scrollBar]: enable or disable scrollbar
   /// - [scrollBar]: enable or disable scrollbar
-  Future<Null> launch(String url,
-      {Map<String, String> headers,
-      bool withJavascript,
-      bool clearCache,
-      bool clearCookies,
-      bool hidden,
-      bool enableAppScheme,
-      Rect rect,
-      String userAgent,
-      bool withZoom,
-      bool withLocalStorage,
-      bool withLocalUrl,
-      bool scrollBar,
-      bool supportMultipleWindows,
-      bool appCacheEnabled,
-      bool allowFileURLs,
-    }) async {
+  Future<Null> launch(String url, {
+    Map<String, String> headers,
+    bool withJavascript,
+    bool clearCache,
+    bool clearCookies,
+    bool hidden,
+    bool enableAppScheme,
+    Rect rect,
+    String userAgent,
+    bool withZoom,
+    bool withLocalStorage,
+    bool withLocalUrl,
+    bool scrollBar,
+    bool supportMultipleWindows,
+    bool appCacheEnabled,
+    bool allowFileURLs,
+  }) async {
     final args = <String, dynamic>{
     final args = <String, dynamic>{
       'url': url,
       'url': url,
       'withJavascript': withJavascript ?? true,
       'withJavascript': withJavascript ?? true,
@@ -127,7 +125,7 @@ class FlutterWebviewPlugin {
       'scrollBar': scrollBar ?? true,
       'scrollBar': scrollBar ?? true,
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'supportMultipleWindows': supportMultipleWindows ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,
       'appCacheEnabled': appCacheEnabled ?? false,
-      "allowFileURLs": allowFileURLs ?? false,
+      'allowFileURLs': allowFileURLs ?? false,
     };
     };
 
 
     if (headers != null) {
     if (headers != null) {
@@ -139,7 +137,7 @@ class FlutterWebviewPlugin {
         'left': rect.left,
         'left': rect.left,
         'top': rect.top,
         'top': rect.top,
         'width': rect.width,
         'width': rect.width,
-        'height': rect.height
+        'height': rect.height,
       };
       };
     }
     }
     await _channel.invokeMethod('launch', args);
     await _channel.invokeMethod('launch', args);
@@ -170,7 +168,7 @@ class FlutterWebviewPlugin {
   // Shows the webview
   // Shows the webview
   Future show() => _channel.invokeMethod('show');
   Future show() => _channel.invokeMethod('show');
 
 
-  // Reload webview with a new url
+  // Reload webview with a url
   Future reloadUrl(String url) async {
   Future reloadUrl(String url) async {
     final args = <String, String>{'url': url};
     final args = <String, String>{'url': url};
     await _channel.invokeMethod('reloadUrl', args);
     await _channel.invokeMethod('reloadUrl', args);
@@ -180,17 +178,7 @@ class FlutterWebviewPlugin {
   Future cleanCookies() async => _channel.invokeMethod('cleanCookies');
   Future cleanCookies() async => _channel.invokeMethod('cleanCookies');
 
 
   // Stops current loading process
   // Stops current loading process
-  Future stopLoading() => _channel.invokeMethod("stopLoading");
-
-  /// adds the plugin as ActivityResultListener
-  /// Only needed and used on Android
-  Future registerAcitivityResultListener() =>
-      _channel.invokeMethod('registerAcitivityResultListener');
-
-  /// removes the plugin as ActivityResultListener
-  /// Only needed and used on Android
-  Future removeAcitivityResultListener() =>
-      _channel.invokeMethod('removeAcitivityResultListener');
+  Future stopLoading() => _channel.invokeMethod('stopLoading');
 
 
   /// Close all Streams
   /// Close all Streams
   void dispose() {
   void dispose() {
@@ -224,17 +212,13 @@ class FlutterWebviewPlugin {
       'left': rect.left,
       'left': rect.left,
       'top': rect.top,
       'top': rect.top,
       'width': rect.width,
       'width': rect.width,
-      'height': rect.height
+      'height': rect.height,
     };
     };
     await _channel.invokeMethod('resize', args);
     await _channel.invokeMethod('resize', args);
   }
   }
 }
 }
 
 
 class WebViewStateChanged {
 class WebViewStateChanged {
-  final WebViewState type;
-  final String url;
-  final int navigationType;
-
   WebViewStateChanged(this.type, this.url, this.navigationType);
   WebViewStateChanged(this.type, this.url, this.navigationType);
 
 
   factory WebViewStateChanged.fromMap(Map<String, dynamic> map) {
   factory WebViewStateChanged.fromMap(Map<String, dynamic> map) {
@@ -250,13 +234,17 @@ class WebViewStateChanged {
         t = WebViewState.finishLoad;
         t = WebViewState.finishLoad;
         break;
         break;
     }
     }
-    return new WebViewStateChanged(t, map['url'], map['navigationType']);
+    return WebViewStateChanged(t, map['url'], map['navigationType']);
   }
   }
+
+  final WebViewState type;
+  final String url;
+  final int navigationType;
 }
 }
 
 
 class WebViewHttpError {
 class WebViewHttpError {
+  WebViewHttpError(this.code, this.url);
+
   final String url;
   final String url;
   final String code;
   final String code;
-
-  WebViewHttpError(this.code, this.url);
 }
 }

+ 34 - 35
lib/src/webview_scaffold.dart

@@ -7,8 +7,34 @@ import 'package:flutter/rendering.dart';
 import 'base.dart';
 import 'base.dart';
 
 
 class WebviewScaffold extends StatefulWidget {
 class WebviewScaffold extends StatefulWidget {
+
+  const WebviewScaffold({
+    Key key,
+    this.appBar,
+    @required this.url,
+    this.headers,
+    this.withJavascript,
+    this.supportMultipleWindows,
+    this.appCacheEnabled,
+    this.clearCache,
+    this.clearCookies,
+    this.enableAppScheme,
+    this.userAgent,
+    this.primary = true,
+    this.persistentFooterButtons,
+    this.bottomNavigationBar,
+    this.withZoom,
+    this.withLocalStorage,
+    this.withLocalUrl,
+    this.scrollBar,
+    this.hidden = false,
+    this.initialChild,
+    this.allowFileURLs,
+  }) : super(key: key);
+
   final PreferredSizeWidget appBar;
   final PreferredSizeWidget appBar;
   final String url;
   final String url;
+  final Map<String, String> headers;
   final bool withJavascript;
   final bool withJavascript;
   final bool supportMultipleWindows;
   final bool supportMultipleWindows;
   final bool appCacheEnabled;
   final bool appCacheEnabled;
@@ -22,44 +48,17 @@ class WebviewScaffold extends StatefulWidget {
   final bool withZoom;
   final bool withZoom;
   final bool withLocalStorage;
   final bool withLocalStorage;
   final bool withLocalUrl;
   final bool withLocalUrl;
-  final bool allowFileURLs;
   final bool scrollBar;
   final bool scrollBar;
   final bool hidden;
   final bool hidden;
   final Widget initialChild;
   final Widget initialChild;
-
-  final Map<String, String> headers;
-
-  const WebviewScaffold(
-      {Key key,
-      this.appBar,
-      @required this.url,
-      this.headers,
-      this.withJavascript,
-      this.supportMultipleWindows,
-      this.appCacheEnabled,
-      this.clearCache,
-      this.clearCookies,
-      this.enableAppScheme,
-      this.userAgent,
-      this.primary = true,
-      this.persistentFooterButtons,
-      this.bottomNavigationBar,
-      this.withZoom,
-      this.withLocalStorage,
-      this.withLocalUrl,
-      this.scrollBar,
-      this.hidden = false,
-      this.initialChild,
-      this.allowFileURLs,
-      })
-      : super(key: key);
+  final bool allowFileURLs;
 
 
   @override
   @override
-  _WebviewScaffoldState createState() => new _WebviewScaffoldState();
+  _WebviewScaffoldState createState() => _WebviewScaffoldState();
 }
 }
 
 
 class _WebviewScaffoldState extends State<WebviewScaffold> {
 class _WebviewScaffoldState extends State<WebviewScaffold> {
-  final webviewReference = new FlutterWebviewPlugin();
+  final webviewReference = FlutterWebviewPlugin();
   Rect _rect;
   Rect _rect;
   Timer _resizeTimer;
   Timer _resizeTimer;
   StreamSubscription<WebViewStateChanged> _onStateChanged;
   StreamSubscription<WebViewStateChanged> _onStateChanged;
@@ -139,7 +138,7 @@ class _WebviewPlaceholder extends SingleChildRenderObjectWidget {
     @required this.onRectChanged,
     @required this.onRectChanged,
     Widget child,
     Widget child,
   }) : super(key: key, child: child);
   }) : super(key: key, child: child);
-  
+
   final ValueChanged<Rect> onRectChanged;
   final ValueChanged<Rect> onRectChanged;
 
 
   @override
   @override
@@ -148,7 +147,7 @@ class _WebviewPlaceholder extends SingleChildRenderObjectWidget {
       onRectChanged: onRectChanged,
       onRectChanged: onRectChanged,
     );
     );
   }
   }
-  
+
   @override
   @override
   void updateRenderObject(BuildContext context, _WebviewPlaceholderRender renderObject) {
   void updateRenderObject(BuildContext context, _WebviewPlaceholderRender renderObject) {
     renderObject..onRectChanged = onRectChanged;
     renderObject..onRectChanged = onRectChanged;
@@ -156,15 +155,15 @@ class _WebviewPlaceholder extends SingleChildRenderObjectWidget {
 }
 }
 
 
 class _WebviewPlaceholderRender extends RenderProxyBox {
 class _WebviewPlaceholderRender extends RenderProxyBox {
-  ValueChanged<Rect> _callback;
-  Rect _rect;
-
   _WebviewPlaceholderRender({
   _WebviewPlaceholderRender({
     RenderBox child,
     RenderBox child,
     ValueChanged<Rect> onRectChanged,
     ValueChanged<Rect> onRectChanged,
   })  : _callback = onRectChanged,
   })  : _callback = onRectChanged,
         super(child);
         super(child);
 
 
+  ValueChanged<Rect> _callback;
+  Rect _rect;
+
   Rect get rect => _rect;
   Rect get rect => _rect;
 
 
   set onRectChanged(ValueChanged<Rect> callback) {
   set onRectChanged(ValueChanged<Rect> callback) {