首页 > 解决方案 > FLUTTER:如何为应用制作持久性背景图片

问题描述

我想为我的应用程序中的所有屏幕使用相同的背景图像,使其成为静态的,这样当我使用导航器时它就不会移动。你知道怎么做吗?

标签: flutterflutter-layout

解决方案


您可以定义一个带有背景图像的小部件,并在其上堆叠您想要的屏幕。

class BackgroundPage extends StatelessWidget {
  const BackgroundPage({
    Key key,
    @required this.child,
  }) : super(key: key);

  /// The widget to display
  final Widget child;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: ExactAssetImage('image.png'),
              ),
            ),
          ),
          child,
        ],
      ),
    );
  }
}

推荐阅读