颤振:SilverAppBar背景图像与文本

时间:2020-08-12 08:07:46

标签: flutter

我正在尝试使应用栏看起来像这样:

enter image description here

我希望使用SilverAppBar折叠大图像,但是我很难插入AssetImage(或Image.asset'). I almost exactly followed the code from the [official Flutter website][2], and unfortunately, both AssetImage and Image.asset`如下所示:

enter image description here

有什么办法吗?

3 个答案:

答案 0 :(得分:1)

使用Container小部件包装Image.asset

          Stack(
                  fit: StackFit.expand,
                  children: <Widget>[
                    Container(
                      child: Image.asset('name'),
                    )
                    ],
                ),

答案 1 :(得分:1)

也许您可以使用这样的背景:

<!-- these tags are blocked in firefox -->
<style nonce="Z2lnkA9A00KuJsXvx94P6hyDdyRUaxFCiV9lUS0XgWo"> some inline code ....
<script nonce="Z2lnkA9A00KuJsXvx94P6hyDdyRUaxFCiV9lUS0XgWo"> some inline code ....

<!-- this tag works as expected in all browsers-->
<script src="/scripts/utils.js"></script>

答案 2 :(得分:0)

请添加background_app_bar: ^1.0.0 依赖。

import 'package:background_app_bar/background_app_bar.dart';
...

SliverAppBar(
      backgroundColor: Colors.white,
      pinned: true,
      snap: true, 
      floating: true,
      expandedHeight: 160.0,
      flexibleSpace: new BackgroundFlexibleSpaceBar(    // Add this
          title: new Text('title'),
          centerTitle: false,
          titlePadding: const EdgeInsets.only(left: 5.0, bottom: 5.0),
          background: Image.asset('url'),
    ),
   ),