How to hide AppBar in the application created in Flutter

假如想象 提交于 2021-02-11 12:37:56

问题


I have this code below, I want to hide the bar app, is it possible? I've tried straight through the Android Theme but I did not get Success. :(

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      appBar: AppBar(
        title: TextField(
          autofocus: false,
          controller: controller,
          textInputAction: TextInputAction.go,
          onSubmitted: (url) => launchUrl(),
          style: TextStyle(color: Colors.white),
          decoration: InputDecoration(
            border: InputBorder.none,
            hintText: "Digite a URL",
            hintStyle: TextStyle(color: Colors.white),
          ),
        ),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.navigate_next),
            onPressed: () => launchUrl(),
          )
        ],
      ),

回答1:


Just don't build the AppBar depending on a boolean flag:

return WebviewScaffold(
    appBar: _ifHideAppBar ? null : AppBar(
        ...
    ),
    ...
);



回答2:


To hide the appBar simply set the appBar property as null in any screen. This change will be reflected in IOS as well as Android. :)

  Widget build(BuildContext context) {
    return WebviewScaffold(
       url: "https://flutter.dev/",                    // Your url
       appBar: null                                    // No action bar will build
       );
    }



回答3:


You can also use Visibility widget to do this but note that appBar required type of PreferredSizedWidget and Visibility is of type Widget because of that we have to wrap with PreferedSize widget and give sizes(Checking if null is less code but in this way you can have your custom app bar).

WebviewScaffold(
  appBar: PreferredSize(
    preferredSize: Size(double.infinity, 56),
    child: Visibility(
      visible: true,
      child: AppBar(),
    ),
  ),
  //....
);


来源:https://stackoverflow.com/questions/54486349/how-to-hide-appbar-in-the-application-created-in-flutter

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