import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: WebViewClass()
)
);
}
}
class WebViewClass extends StatefulWidget {
WebViewState createState() => WebViewState();
}
class WebViewState extends State<WebViewClass>{
num position = 1 ;
final key = UniqueKey();
doneLoading(String A) {
setState(() {
position = 0;
});
}
startLoading(String A){
setState(() {
position = 1;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Show ProgressBar While Loading Webview')),
body: IndexedStack(
index: position,
children: <Widget>[
WebView(
initialUrl: 'https://Google.com',
javascriptMode: JavascriptMode.unrestricted,
key: key ,
onPageFinished: doneLoading,
onPageStarted: startLoading,
),
Container(
color: Colors.white,
child: Center(
child: CircularProgressIndicator()),
),
])
);
}
}
为什么会显示此错误?基本上,我想在加载完整的网站之前,在FlitterWebView上添加进度条.经过多次搜索,我得到了这段代码,但我也显示了错误.此代码中是否有任何问题,或者如果可以,请帮助我使用新代码.