@@ -10,59 +10,62 @@ const kAndroidUserAgent =
1010String selectedUrl = 'https://flutter.io' ;
1111
1212void main () {
13- runApp (new MyApp ());
13+ runApp (MyApp ());
1414}
1515
1616class MyApp extends StatelessWidget {
17- final flutterWebviewPlugin = new FlutterWebviewPlugin ();
17+ final flutterWebViewPlugin = FlutterWebviewPlugin ();
1818
1919 @override
2020 Widget build (BuildContext context) {
21- return new MaterialApp (
21+ return MaterialApp (
2222 title: 'Flutter WebView Demo' ,
23- theme: new ThemeData (
23+ theme: ThemeData (
2424 primarySwatch: Colors .blue,
2525 ),
2626 routes: {
2727 '/' : (_) => const MyHomePage (title: 'Flutter WebView Demo' ),
28- '/widget' : (_) => new WebviewScaffold (
29- url : selectedUrl,
30- appBar : new AppBar (
31- title : const Text ( 'Widget webview' ),
32- ),
33- withZoom : true ,
34- withLocalStorage : true ,
35- hidden : true ,
36- initialChild : Container (
37- color : Colors .redAccent,
38- child : const Center (
39- child: Text ( 'Waiting.....' ),
40- ),
28+ '/widget' : (_) {
29+ return WebviewScaffold (
30+ url : selectedUrl,
31+ appBar : AppBar (
32+ title : const Text ( 'Widget WebView' ),
33+ ) ,
34+ withZoom : true ,
35+ withLocalStorage : true ,
36+ hidden : true ,
37+ initialChild : Container (
38+ color : Colors .redAccent,
39+ child: const Center (
40+ child : Text ( 'Waiting.....' ),
4141 ),
42- bottomNavigationBar: BottomAppBar (
43- child: Row (
42+ ),
43+ bottomNavigationBar: BottomAppBar (
44+ child: Row (
4445 children: < Widget > [
4546 IconButton (
4647 icon: const Icon (Icons .arrow_back_ios),
4748 onPressed: () {
48- flutterWebviewPlugin .goBack ();
49+ flutterWebViewPlugin .goBack ();
4950 },
5051 ),
5152 IconButton (
5253 icon: const Icon (Icons .arrow_forward_ios),
5354 onPressed: () {
54- flutterWebviewPlugin .goForward ();
55+ flutterWebViewPlugin .goForward ();
5556 },
5657 ),
5758 IconButton (
5859 icon: const Icon (Icons .autorenew),
5960 onPressed: () {
60- flutterWebviewPlugin .reload ();
61+ flutterWebViewPlugin .reload ();
6162 },
6263 ),
6364 ],
64- )),
65- )
65+ ),
66+ ),
67+ );
68+ },
6669 },
6770 );
6871 }
@@ -74,12 +77,12 @@ class MyHomePage extends StatefulWidget {
7477 final String title;
7578
7679 @override
77- _MyHomePageState createState () => new _MyHomePageState ();
80+ _MyHomePageState createState () => _MyHomePageState ();
7881}
7982
8083class _MyHomePageState extends State <MyHomePage > {
8184 // Instance of WebView plugin
82- final flutterWebviewPlugin = new FlutterWebviewPlugin ();
85+ final flutterWebViewPlugin = FlutterWebviewPlugin ();
8386
8487 // On destroy stream
8588 StreamSubscription _onDestroy;
@@ -96,73 +99,66 @@ class _MyHomePageState extends State<MyHomePage> {
9699
97100 StreamSubscription <double > _onScrollXChanged;
98101
99- final _urlCtrl = new TextEditingController (text: selectedUrl);
102+ final _urlCtrl = TextEditingController (text: selectedUrl);
100103
101- final _codeCtrl =
102- new TextEditingController (text: 'window.navigator.userAgent' );
104+ final _codeCtrl = TextEditingController (text: 'window.navigator.userAgent' );
103105
104- final _scaffoldKey = new GlobalKey <ScaffoldState >();
106+ final _scaffoldKey = GlobalKey <ScaffoldState >();
105107
106108 final _history = [];
107109
108110 @override
109111 void initState () {
110112 super .initState ();
111113
112- flutterWebviewPlugin .close ();
114+ flutterWebViewPlugin .close ();
113115
114116 _urlCtrl.addListener (() {
115117 selectedUrl = _urlCtrl.text;
116118 });
117119
118120 // Add a listener to on destroy WebView, so you can make came actions.
119- _onDestroy = flutterWebviewPlugin .onDestroy.listen ((_) {
121+ _onDestroy = flutterWebViewPlugin .onDestroy.listen ((_) {
120122 if (mounted) {
121123 // Actions like show a info toast.
122- _scaffoldKey.currentState.showSnackBar (
123- const SnackBar (content: const Text ('Webview Destroyed' )));
124+ _scaffoldKey.currentState.showSnackBar (const SnackBar (content: const Text ('Webview Destroyed' )));
124125 }
125126 });
126127
127128 // Add a listener to on url changed
128- _onUrlChanged = flutterWebviewPlugin .onUrlChanged.listen ((String url) {
129+ _onUrlChanged = flutterWebViewPlugin .onUrlChanged.listen ((String url) {
129130 if (mounted) {
130131 setState (() {
131132 _history.add ('onUrlChanged: $url ' );
132133 });
133134 }
134135 });
135136
136- _onScrollYChanged =
137- flutterWebviewPlugin.onScrollYChanged.listen ((double y) {
137+ _onScrollYChanged = flutterWebViewPlugin.onScrollYChanged.listen ((double y) {
138138 if (mounted) {
139139 setState (() {
140- _history.add (" Scroll in Y Direction: $y " );
140+ _history.add (' Scroll in Y Direction: $y ' );
141141 });
142142 }
143143 });
144144
145- _onScrollXChanged =
146- flutterWebviewPlugin.onScrollXChanged.listen ((double x) {
145+ _onScrollXChanged = flutterWebViewPlugin.onScrollXChanged.listen ((double x) {
147146 if (mounted) {
148147 setState (() {
149- _history.add (" Scroll in X Direction: $x " );
148+ _history.add (' Scroll in X Direction: $x ' );
150149 });
151150 }
152151 });
153152
154- _onStateChanged =
155- flutterWebviewPlugin.onStateChanged.listen ((WebViewStateChanged state) {
156-
153+ _onStateChanged = flutterWebViewPlugin.onStateChanged.listen ((WebViewStateChanged state) {
157154 if (mounted) {
158155 setState (() {
159156 _history.add ('onStateChanged: ${state .type } ${state .url }' );
160157 });
161158 }
162159 });
163160
164- _onHttpError =
165- flutterWebviewPlugin.onHttpError.listen ((WebViewHttpError error) {
161+ _onHttpError = flutterWebViewPlugin.onHttpError.listen ((WebViewHttpError error) {
166162 if (mounted) {
167163 setState (() {
168164 _history.add ('onHttpError: ${error .code } ${error .url }' );
@@ -181,58 +177,61 @@ class _MyHomePageState extends State<MyHomePage> {
181177 _onScrollXChanged.cancel ();
182178 _onScrollYChanged.cancel ();
183179
184- flutterWebviewPlugin .dispose ();
180+ flutterWebViewPlugin .dispose ();
185181
186182 super .dispose ();
187183 }
188184
189185 @override
190186 Widget build (BuildContext context) {
191- return new Scaffold (
187+ return Scaffold (
192188 key: _scaffoldKey,
193- appBar: new AppBar (
189+ appBar: AppBar (
194190 title: const Text ('Plugin example app' ),
195191 ),
196192 body: SingleChildScrollView (
197- child: new Column (
193+ child: Column (
198194 mainAxisAlignment: MainAxisAlignment .center,
199195 children: [
200- new Container (
196+ Container (
201197 padding: const EdgeInsets .all (24.0 ),
202- child: new TextField (controller: _urlCtrl),
198+ child: TextField (controller: _urlCtrl),
203199 ),
204- new RaisedButton (
200+ RaisedButton (
205201 onPressed: () {
206- flutterWebviewPlugin.launch (selectedUrl,
207- rect: new Rect .fromLTWH (0.0 , 0.0 , MediaQuery .of (context).size.width, 300.0 ), userAgent: kAndroidUserAgent);
202+ flutterWebViewPlugin.launch (
203+ selectedUrl,
204+ rect: Rect .fromLTWH (0.0 , 0.0 , MediaQuery .of (context).size.width, 300.0 ),
205+ userAgent: kAndroidUserAgent,
206+ );
208207 },
209208 child: const Text ('Open Webview (rect)' ),
210209 ),
211- new RaisedButton (
210+ RaisedButton (
212211 onPressed: () {
213- flutterWebviewPlugin .launch (selectedUrl, hidden: true );
212+ flutterWebViewPlugin .launch (selectedUrl, hidden: true );
214213 },
215214 child: const Text ('Open "hidden" Webview' ),
216215 ),
217- new RaisedButton (
216+ RaisedButton (
218217 onPressed: () {
219- flutterWebviewPlugin .launch (selectedUrl);
218+ flutterWebViewPlugin .launch (selectedUrl);
220219 },
221220 child: const Text ('Open Fullscreen Webview' ),
222221 ),
223- new RaisedButton (
222+ RaisedButton (
224223 onPressed: () {
225224 Navigator .of (context).pushNamed ('/widget' );
226225 },
227226 child: const Text ('Open widget webview' ),
228227 ),
229- new Container (
228+ Container (
230229 padding: const EdgeInsets .all (24.0 ),
231- child: new TextField (controller: _codeCtrl),
230+ child: TextField (controller: _codeCtrl),
232231 ),
233- new RaisedButton (
232+ RaisedButton (
234233 onPressed: () {
235- final future = flutterWebviewPlugin .evalJavascript (_codeCtrl.text);
234+ final future = flutterWebViewPlugin .evalJavascript (_codeCtrl.text);
236235 future.then ((String result) {
237236 setState (() {
238237 _history.add ('eval: $result ' );
@@ -241,26 +240,26 @@ class _MyHomePageState extends State<MyHomePage> {
241240 },
242241 child: const Text ('Eval some javascript' ),
243242 ),
244- new RaisedButton (
243+ RaisedButton (
245244 onPressed: () {
246245 setState (() {
247246 _history.clear ();
248247 });
249- flutterWebviewPlugin .close ();
248+ flutterWebViewPlugin .close ();
250249 },
251250 child: const Text ('Close' ),
252251 ),
253- new RaisedButton (
252+ RaisedButton (
254253 onPressed: () {
255- flutterWebviewPlugin .getCookies ().then ((m) {
254+ flutterWebViewPlugin .getCookies ().then ((m) {
256255 setState (() {
257256 _history.add ('cookies: $m ' );
258257 });
259258 });
260259 },
261260 child: const Text ('Cookies' ),
262261 ),
263- new Text (_history.join ('\n ' ))
262+ Text (_history.join ('\n ' ))
264263 ],
265264 ),
266265 ),
0 commit comments