【问题标题】:Can't remove title area of AppBar无法删除 AppBar 的标题区域
【发布时间】:2020-03-25 16:27:40
【问题描述】:

安卓工作室 3.6

class MainScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text("Title")),
        body: new SingleChildScrollView(
            child: new Container(
      margin: const EdgeInsets.only(
          left: Constants.DEFAULT_MARGIN,
          top: Constants.DEFAULT_MARGIN,
          right: Constants.DEFAULT_MARGIN),
              child: new Text("text"),
    )));
  }
}

结果

如何删除显示 Title 的 AppBar 部分?只有这一部分。状态栏必须保留。

【问题讨论】:

  • 我不明白...你能制作一张你要存档的模型图片吗

标签: android flutter


【解决方案1】:

SafeArea 包裹你的body: SingleChildScrollView() 并删除appBar。请阅读SafeArea here

Scaffold(
  body: SafeArea(child: SingleChildScrollView(child: /*...*/))
)

【讨论】:

    【解决方案2】:

    如果我正确理解了这个问题,您可以通过省略标题参数来从应用栏中删除标题:

    class MainScreen extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            body: new SingleChildScrollView(
                child: new Container(
          margin: const EdgeInsets.only(
              left: Constants.DEFAULT_MARGIN,
              top: Constants.DEFAULT_MARGIN,
              right: Constants.DEFAULT_MARGIN),
                  child: new Text("text"),
        )));
      }
    }
    

    【讨论】:

      【解决方案3】:

      如果您只想摆脱标题文本但保留应用栏,您可以这样做:

           class MainScreen extends StatelessWidget {
           @override
          Widget build(BuildContext context) {
      return new Scaffold(
        appBar: new AppBar(),
          body: new SingleChildScrollView(
              child: new Container(
        margin: const EdgeInsets.only(
            left: Constants.DEFAULT_MARGIN,
            top: Constants.DEFAULT_MARGIN,
            right: Constants.DEFAULT_MARGIN),
                child: new Text("text"),
      )));
         }
         }
      

      如果你只想去掉标题文本和应用栏,你可以这样做:

           class MainScreen extends StatelessWidget {
           @override
          Widget build(BuildContext context) {
      return new Scaffold(
      
          body: new SingleChildScrollView(
              child: new Container(
        margin: const EdgeInsets.only(
            left: Constants.DEFAULT_MARGIN,
            top: Constants.DEFAULT_MARGIN,
            right: Constants.DEFAULT_MARGIN),
                child: new Text("text"),
      )));
         }
         }
      

      【讨论】:

        猜你喜欢
        • 2019-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多