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

标签 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: () {}),
          ),
        ),
      ),
    );
  }

关于dart - 如何将背景图像添加到 flutter 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53972876/

相关文章:

flutter - 未处理的异常:RangeError:值不在范围内:22

flutter - MediaQuery.of()一直显示

监听数据时出现 HttpClientResponse 错误

flutter - 如何在 Visual Studio Code 中运行 Flutter 官方示例

unit-testing - Flutter: 'package:shared_preferences/shared_preferences.dart':断言失败:第 33 行 pos 16: 'key.startsWith(_prefix)':不正确

loops - Dart:从foreach循环中的if退出函数

dart - 下载 pub.dartlang.org 上发布的软件包的统计信息?

java - 错误 : Could not find com. android.tools.build :gradle:3. 2.1

api - 通过 Flutter App 和 JSON Web Token 在 Django 中验证用户

image - 在加载高分辨率图像时显示加载窗口小部件