Trying to display the title of the webpage in the AppBar using the getTitle() method of webview_flutter.
It seems to work intermittently when the Hot reload is used on the debug bar but when I navigate to another page, it doesn’t update.
Here is what I’ve tried
@override
Widget build(BuildContext context) {
var appBarWebpageTitle = FutureBuilder(
future: controller.getTitle(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text("${snapshot.data}");
} else {
return Text("Loading");
}
},
);
return Scaffold(
appBar: AppBar(
title: appBarWebpageTitle,
backgroundColor: const Color.fromARGB(255, 0, 0, 0),
actions: [
PopupMenuButton(itemBuilder: (context) {
return [
const PopupMenuItem<int>(
value: 0,
child: Text("Dashboard"),
),
];
}, onSelected: (value) {
if (value == 0) {
// print("My account menu is selected.");
}
}),
],
),
body: WebViewWidget(
controller: controller,
),
);
}
}
2
Answers
Using @youknowbaron's flow i was able to solve the problem. Below is the code in case it helps
When you navigate to another screen, you must update your Future
appBarWebpageTitle
because the last Future is already done, and nothing changed. This is a solution:appBarWebpageTitle
to a global variable.WebViewWidget
.appBarWebpageTitle
= [a new Future] and callsetState(() {})