Home > Mobile >  How to change the title of tab page in flutter web
How to change the title of tab page in flutter web

Time:06-21

I'm building a Flutter web project and I need to be able to change the title of the tab when I navigate to another page. I have tried the ongenerateRoute property but it isn't working. Here's how I did it.

import 'package:./routes.dart';
import 'package:flutter/material.dart';

String? routePath;

String getTabTitle(BuildContext context) {

  if (routePath == loginRoute) {
    return 'Login';
  } else if (routePath == dashboardRoute) {
    return 'Dashboard';
  } else if (routePath == overviewRoute) {
    return 'Overview';
  } else if (routePath == settingsRoute) {
    return 'Settings';
  } else {
    return 'Admin | Borku Africa';
  }
}

It seems the ongenerateRoute property only works for localizations. Please any way to work it around would be appreciated. Thanks.

CodePudding user response:

I found the solution here guys. Easy peasy. https://www.kindacode.com/article/flutter-web-2-ways-to-change-page-title-dynamically/

CodePudding user response:

Flutter provide Title widget that can be used to change the title.

return Title(
  title: "Home Page",
  color: Colors.white,
  child: Scaffold(

More about Title.

  • Related