mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-08-23 10:10:44 +08:00
@ -4,15 +4,14 @@
|
|||||||
/// @Last Modified time: 2019-01-14 19:47:14
|
/// @Last Modified time: 2019-01-14 19:47:14
|
||||||
|
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'dart:math';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
|
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
|
||||||
|
|
||||||
import 'package:flutter_go/model/collection.dart';
|
/// import 'package:flutter_go/model/collection.dart';
|
||||||
import 'package:flutter_go/event/event_bus.dart';
|
import 'package:flutter_go/event/event_bus.dart';
|
||||||
import 'package:flutter_go/event/event_model.dart';
|
import 'package:flutter_go/event/event_model.dart';
|
||||||
import 'package:flutter_go/api/api.dart';
|
import 'package:flutter_go/api/api.dart';
|
||||||
import 'package:flutter_go/routers/application.dart' show Application;
|
|
||||||
|
|
||||||
class WebViewPage extends StatefulWidget {
|
class WebViewPage extends StatefulWidget {
|
||||||
final String url;
|
final String url;
|
||||||
@ -22,10 +21,7 @@ class WebViewPage extends StatefulWidget {
|
|||||||
_WebViewPageState createState() => _WebViewPageState();
|
_WebViewPageState createState() => _WebViewPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _WebViewPageState extends State<WebViewPage> with AutomaticKeepAliveClientMixin{
|
class _WebViewPageState extends State<WebViewPage> {
|
||||||
@override
|
|
||||||
bool get wantKeepAlive => true;
|
|
||||||
|
|
||||||
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
||||||
|
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
@ -33,10 +29,8 @@ class _WebViewPageState extends State<WebViewPage> with AutomaticKeepAliveClient
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
dialog = dialogContext(false);
|
|
||||||
|
|
||||||
flutterWebviewPlugin.onUrlChanged.listen((String url) {
|
flutterWebviewPlugin.onUrlChanged.listen((String url) {
|
||||||
|
|
||||||
print('url change:$url');
|
print('url change:$url');
|
||||||
if (url.indexOf('loginSuccess') > -1) {
|
if (url.indexOf('loginSuccess') > -1) {
|
||||||
String urlQuery = url.substring(url.indexOf('?') + 1);
|
String urlQuery = url.substring(url.indexOf('?') + 1);
|
||||||
@ -68,75 +62,21 @@ class _WebViewPageState extends State<WebViewPage> with AutomaticKeepAliveClient
|
|||||||
flutterWebviewPlugin.close();
|
flutterWebviewPlugin.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
flutterWebviewPlugin.onStateChanged.listen((state) async {
|
|
||||||
print('url state:$state');
|
|
||||||
if(state.type == WebViewState.finishLoad) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget dialogContext(bool isShow){
|
|
||||||
if(!isShow){
|
|
||||||
return Container(child:Text(""));
|
|
||||||
}
|
|
||||||
return Container(
|
|
||||||
height: 200,
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
children: <Widget>[
|
|
||||||
SizedBox(height: 20),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
children: <Widget>[
|
|
||||||
Text('分享到',style: TextStyle(fontSize:16,color: Colors.deepOrange)),
|
|
||||||
FlatButton(
|
|
||||||
child: Text('取消',style: TextStyle(fontSize:16,color: Colors.black45),),
|
|
||||||
onPressed: (){
|
|
||||||
setState(() {
|
|
||||||
dialog = dialogContext(false);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Container dialog;
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
// actions: <Widget>[
|
),
|
||||||
// IconButton(
|
body: WebviewScaffold(
|
||||||
// icon: Icon(Icons.announcement),
|
url: widget.url,
|
||||||
// onPressed: () {
|
withZoom: false,
|
||||||
// /// flutterWebviewPlugin.evalJavascript("alert('Flutter Go H5 版本')");
|
withLocalStorage: true,
|
||||||
// setState(() {
|
withJavascript: true,
|
||||||
// dialog = dialogContext(true);
|
),
|
||||||
// });
|
);
|
||||||
// },
|
|
||||||
// )
|
|
||||||
// ],
|
|
||||||
),
|
|
||||||
body: WebviewScaffold(
|
|
||||||
url: widget.url,
|
|
||||||
withZoom: true,
|
|
||||||
withLocalStorage: true,
|
|
||||||
withJavascript: true,
|
|
||||||
userAgent: "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36",
|
|
||||||
bottomNavigationBar:dialog,
|
|
||||||
initialChild: Container(
|
|
||||||
color: Colors.white,
|
|
||||||
child: const Center(
|
|
||||||
child: Text("Loading...."),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user