dart - 如何将背景图像添加到 flutter 应用程序?

我正在尝试将背景图片添加到我的 Flutter 应用程序中,并且我已经解决了关于 SO 的所有类似问题。应用程序 m 运行良好,但图像没有出现。

这是我的小部件代码:

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
        actions: <Widget>[
          new IconButton(icon: const Icon(Icons.list), onPressed: _loadWeb)
        ],
      ),
      body: new Stack(
        children: <Widget>[
          Container(
            child: new DecoratedBox(
              decoration: new BoxDecoration(
                image: new DecorationImage(
                  image: new AssetImage("images/logo.png"),
                  fit: BoxFit.fill,
                ),
              ),
            ),
          ),
          Center(
            child: _authList(),
          )
        ],
      ),

      floatingActionButton: FloatingActionButton(
        onPressed: getFile,
        tooltip: 'Select file',
        child: Icon(Icons.sd_storage),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    ));
  }

应用程序运行良好,堆栈上的第二个小部件,即 listView 正常工作,但图像未显示。

有什么想法吗?

最佳答案

Scaffold 不支持背景图像的任何概念。您可以做的是给 Scaffold 一个透明颜色并将其放入 Container 并使用 decoration 属性拉入所需的背景图像.应用栏也是透明的。

Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage("images/logo.png"), fit: BoxFit.cover)),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          appBar: AppBar(
            elevation: 0,
            backgroundColor: Colors.transparent,
            title: Text('My App'),
            centerTitle: true,
            leading: IconButton(
                icon: Icon(
                  Icons.list,
                  color: Colors.white,
                ),
                onPressed: () {}),
          ),
        ),
      ),
    );
  }

https://stackoverflow.com/questions/53972876/

相关文章:

dart - 添加点击功能 flutter

amazon-web-services - 如何在不使用原生 SDK 的情况下使用 AWS Cogn

dart - Flutter Navigator.replace() 示例

dart - 使用 Navigator.popUntil 和没有固定名称的路由

android - Flutter Launcher 图标没有改变?

dart - 如何在 Flutter 中创建带有圆角的自定义模糊形状

flutter - 如何将小部件动态添加到 Flutter 中的列?

Flutter - 我想将变量从一个类传递到另一个类

android - Flutter - Image.network 失败时的默认图像

image - Flutter:如何将 Canvas/CustomPainter 保存到图像文件中?