2019-11-18 21:21:35 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
|
|
|
|
import 'package:flutter_downloader/flutter_downloader.dart';
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
import 'package:flutter/services.dart' show rootBundle;
|
|
|
|
|
|
|
|
class InAppWebViewExampleScreen extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_InAppWebViewExampleScreenState createState() =>
|
|
|
|
new _InAppWebViewExampleScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
|
|
|
|
InAppWebViewController webView;
|
|
|
|
String url = "";
|
|
|
|
double progress = 0;
|
2019-11-25 00:42:27 +00:00
|
|
|
CookieManager cookieManager = CookieManager.instance();
|
2019-11-18 21:21:35 +00:00
|
|
|
|
|
|
|
TextEditingController _textFieldController = TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
2019-11-20 01:30:16 +00:00
|
|
|
_textFieldController.dispose();
|
2019-11-18 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(
|
|
|
|
"InAppWebView",
|
|
|
|
)),
|
|
|
|
drawer: Drawer(
|
|
|
|
child: ListView(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children: <Widget>[
|
|
|
|
DrawerHeader(
|
|
|
|
child: Text('flutter_inappbrowser example'),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('InAppBrowser'),
|
|
|
|
onTap: () {
|
2019-11-21 01:19:43 +00:00
|
|
|
Navigator.pushReplacementNamed(context, '/InAppBrowser');
|
2019-11-18 21:21:35 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('ChromeSafariBrowser'),
|
|
|
|
onTap: () {
|
2019-11-21 01:19:43 +00:00
|
|
|
Navigator.pushReplacementNamed(context, '/ChromeSafariBrowser');
|
2019-11-18 21:21:35 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('InAppWebView'),
|
|
|
|
onTap: () {
|
2019-11-21 01:19:43 +00:00
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
2019-11-18 21:21:35 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: Column(children: <Widget>[
|
2019-11-25 11:12:10 +00:00
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(20.0),
|
|
|
|
child: Text(
|
|
|
|
"CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: progress < 1.0
|
|
|
|
? LinearProgressIndicator(value: progress)
|
|
|
|
: Container()),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.all(10.0),
|
|
|
|
decoration:
|
|
|
|
BoxDecoration(border: Border.all(color: Colors.blueAccent)),
|
|
|
|
child: InAppWebView(
|
|
|
|
initialUrl: "https://flutter.dev/",
|
|
|
|
initialHeaders: {},
|
|
|
|
initialOptions: InAppWebViewWidgetOptions(
|
|
|
|
inAppWebViewOptions: InAppWebViewOptions(
|
|
|
|
debuggingEnabled: true,
|
|
|
|
clearCache: true
|
|
|
|
)
|
|
|
|
),
|
|
|
|
onWebViewCreated: (InAppWebViewController controller) {
|
|
|
|
webView = controller;
|
|
|
|
},
|
|
|
|
onLoadStart: (InAppWebViewController controller, String url) {
|
|
|
|
setState(() {
|
|
|
|
this.url = url;
|
2019-11-18 21:21:35 +00:00
|
|
|
});
|
2019-11-25 11:12:10 +00:00
|
|
|
},
|
|
|
|
onLoadStop: (InAppWebViewController controller, String url) async {
|
|
|
|
setState(() {
|
|
|
|
this.url = url;
|
2019-11-18 21:21:35 +00:00
|
|
|
});
|
|
|
|
},
|
2019-11-25 11:12:10 +00:00
|
|
|
onProgressChanged: (InAppWebViewController controller, int progress) {
|
|
|
|
setState(() {
|
|
|
|
this.progress = progress / 100;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2019-11-18 21:21:35 +00:00
|
|
|
),
|
2019-11-25 11:12:10 +00:00
|
|
|
ButtonBar(
|
|
|
|
alignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
RaisedButton(
|
|
|
|
child: Icon(Icons.arrow_back),
|
|
|
|
onPressed: () {
|
|
|
|
if (webView != null) {
|
|
|
|
webView.goBack();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
RaisedButton(
|
|
|
|
child: Icon(Icons.arrow_forward),
|
|
|
|
onPressed: () {
|
|
|
|
if (webView != null) {
|
|
|
|
webView.goForward();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
RaisedButton(
|
|
|
|
child: Icon(Icons.refresh),
|
|
|
|
onPressed: () {
|
|
|
|
if (webView != null) {
|
|
|
|
webView.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2019-11-18 21:21:35 +00:00
|
|
|
),
|
|
|
|
])));
|
|
|
|
}
|
|
|
|
}
|