我正在尝试构建一个Webview项目,我想在加载指示器后转到下一页,但是它不起作用,我有什么想念的东西吗?我想在加载指示器后,加载的Webview网站会自动显示。我正在尝试构建一个Webview项目,我想在加载指示器后转到下一页,但是它不起作用,是否有任何我错过或弄乱的东西?我想在加载指示器后,我加载的webviewsite会自动显示
这是我的代码-
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
import 'package:web2app/widgets/drawer.dart';
import 'package:webview_flutter/webview_flutter.dart';
const String flutterUrl = 'https://flutter.dev/';
const String wikiUrl = 'https://google.com/';
class X extends StatefulWidget {
XState createState() => XState();
}
class XState extends State<X> {
WebViewController _controller;
bool isLoading = false;
@override
void initState() {
setState(() {
isLoading = true;
});
super.initState();
}
_back() async {
if (await _controller.canGoBack()) {
await _controller.goBack();
}
}
_forward() async {
if (await _controller.canGoForward()) {
await _controller.goForward();
}
}
_loadPage() async {
var url = await _controller.currentUrl();
_controller.loadUrl(
url == flutterUrl ? wikiUrl : flutterUrl,
);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepOrange,
title: Text('Web2App'),
actions: <Widget>[
IconButton(icon: Icon(Icons.arrow_back_ios), onPressed: _back),
IconButton(
icon: Icon(Icons.arrow_forward_ios), onPressed: _forward),
SizedBox(
width: 10,
),
],
),
drawer: Drawer(
child: DrawerPage(),
),
floatingActionButton: FloatingActionButton(
onPressed: _loadPage,
child: Icon(Icons.refresh),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
isLoading
? Container(
child: CircularPercentIndicator(
radius: 120.0,
lineWidth: 13.0,
animation: true,
animationDuration: 4500,
percent: 1,
footer: new Text(
"Loading...",
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 17.0),
),
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.purple,
),
)
: WebView(
key: Key('webview'),
initialUrl: flutterUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated:
(WebViewController webViewController) {
_controller = webViewController;
},
)
]),
));
}
}
[好像您已经将isLoading
设置为true却从未更改。
`void initState() {
setState(() {
isLoading = true;
});
super.initState();
}`
但是您没有再次将isLoading
设置为false来加载下一个屏幕
`isLoading ? Container()
//all your code for loading screen
//you could set the state of isLoading to false here
: WebView()
//All your WebView code`
您是说isLoading == true
是否继续加载,但是在窗口小部件中没有将其设置为false的情况。