Want to change the app bar title in flutter? You could also split your code, assuming that your database fetch will be asynchronous.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | class HomeScreenState extends State<HomeScreen> { var appBarTitleText = new Text("eClerx Parking"); Future getUser() async { var user = await db.getUser(); if (user != null) { user.then((val) { if (val == null) { return; } print("user data : " + val.emailId); setState(() { appBarTitleText = Text(val.emailId); }); }); } } @override void initState() { super.initState(); getUser(); } @override Widget build(BuildContext context) { ... |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.