En una aplicación de Flutter, me gustaría volver a cargar la página de Webview cuando presiono el botón del icono de actualización en la barra de aplicaciones. Estoy usando el webview_flutter oficial y no quiero usar flutter_webview_plugin ya que tengo un cajón lateral. ¿Alguna idea sobre cómo actualizar la página de vista web?
Intenté usar setState () para reconstruir la misma página pero la aplicación no se reconstruye. También intenté usar navigator.push () pero esto dirige a una vista web de pantalla completa y cubre el cajón y la barra de aplicaciones.
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text(widget.drawerItems[_selectedDrawerIndex].title, style: TextStyle(
shadows: <Shadow>[
Shadow(
offset: Offset(1.0, 1.0),
blurRadius: 10.0,
color: Color(0xff185B1E),
),
],
color: Colors.white,
),
),
backgroundColor: Color(0xff9ABDFF),
iconTheme: IconThemeData(color: Colors.white),
actions: <Widget>[
IconButton(
icon: Icon(Icons.refresh),
color: Colors.white,
onPressed: () {
setState((){
_selectedDrawerIndex = 3;
//refresh webview here
});
},
),
]
body: _getDrawerItemWidget(_selectedDrawerIndex),
//_getDrawerItemWidget refers to a webview page
),
}
A continuación se muestra mi widget de vista web:
class Web1 extends StatelessWidget{
@override
Widget build(BuildContext ctxt) {
return WebView(
key: UniqueKey(),
javascriptMode: JavascriptMode.unrestricted,
initialUrl: 'http://www.google.com',
);
}
}