【问题标题】:FLUTTER: How to make a persitent background image for appFLUTTER:如何为应用制作持久的背景图片
【发布时间】:2021-08-19 11:37:34
【问题描述】:

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

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

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

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,
        ],
      ),
    );
  }
}

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2020-08-04
    • 2020-07-09
    • 1970-01-01
    • 2021-10-12
    • 2022-01-04
    相关资源
    最近更新 更多