How can you set title and icon for a flutter web app?

我怕爱的太早我们不能终老 提交于 2020-12-23 11:12:28

问题


What I'm trying to do is build a flutter web app that, when displayed in the browser, the tab shows an icon and a title (as currently it only shows the world icon and the localhost... title).

Actual Result :

Desired Result :

Edit: I can now add the title, as this is set in the main function

Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      leading: Icon(Icons.menu, color: Colors.white,),
      title: Text(_your title here_),
    )
    ...
  );
}

So, the only thing I need to edit is the favicon


回答1:


Assuming you already have a favicon.ico file, placing it inside the your_project_dir\web folder alongside index.html as shown below is enough for the browser to pick it up.

Following is the result of placing a favicon.ico' in theweb` folder. Make sure to do a clean build.

In other case you can manually mention it using the link tag inside your index.html as explained here in this Wikipedia page.




回答2:


In order to change the title to what you desire, you need to add the parameter title (Which is a String) to your MaterialApp widget.

return MaterialApp(
  title: "MyTitle", 
  home: MyHomeWidget());


来源:https://stackoverflow.com/questions/59220989/how-can-you-set-title-and-icon-for-a-flutter-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!