How to auto update webview flutter/dart

66 views Asked by At

Please, how do I update the WebView (refresh or reload ) automatically when changing data in Firebase without the user needing to press the refresh button?

It would be a digital picture frame that when changing the image in the database instantly updates the image on the display!

It would be possible?

Thanks

class Screen_Teste_Web_View extends StatefulWidget {
@override
_Screen_Teste_Web_ViewState createState() => _Screen_Teste_Web_ViewState();
}
class _Screen_Teste_Web_ViewState extends State<Screen_Teste_Web_View> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
void initState() {
super.initState();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
}
@override
Widget build(BuildContext context) {
var screenHeight = MediaQuery.of(context).size.height;
var screenWidth = MediaQuery.of(context).size.width;

return Scaffold(
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('col').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
return PageView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: snapshot.data?.docs.length,
itemBuilder: (BuildContext context, int index) {
return WebView(
initialUrl: snapshot.data?.docs.elementAt(
index)['imag2'],
javascriptMode: JavascriptMode.unrestricted,);},
);
} else {
debugPrint('Carregando...');
return Container(
height: screenHeight * 0.9,
width: screenWidth * 0.9,
decoration: const BoxDecoration(
image: const DecorationImage(
'assets/images/logo',
),
fit: BoxFit.cover)));
}
},
),
);} }`
0

There are 0 answers