【问题标题】:How to hide AppBar in the application created in Flutter [duplicate]如何在 Flutter 中创建的应用程序中隐藏 AppBar [重复]
【发布时间】:2019-02-01 19:53:36
【问题描述】:

我下面有这段代码,我想隐藏栏应用,可以吗?我已经尝试直接通过 Android 主题,但我没有成功。 :(

  @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(),
          )
        ],
      ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    要隐藏 appBar,只需在任何屏幕中将 appBar 属性设置为 null。这一变化将反映在 IOS 和 Android 中。 :)

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

    【讨论】:

      【解决方案2】:

      只是不要根据布尔标志构建 AppBar:

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

      【讨论】:

        【解决方案3】:

        您也可以使用Visibility 小部件来执行此操作,但请注意appBar 所需的PreferredSizedWidgetVisibility 类型是Widget,因为我们必须用PreferedSize 小部件包装并给出尺寸(检查null 的代码是否更少,但这样您就可以拥有自定义应用栏)。

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

        【讨论】:

          猜你喜欢
          • 2021-04-03
          • 1970-01-01
          • 2019-01-27
          • 1970-01-01
          • 1970-01-01
          • 2015-12-28
          • 1970-01-01
          • 2014-03-17
          • 1970-01-01
          相关资源
          最近更新 更多