【发布时间】:2021-08-19 11:37:34
【问题描述】:
我想为我的应用程序中的所有屏幕使用相同的背景图片,将其设为静态,这样当我使用导航器时它就不会移动。你知道怎么做吗?
【问题讨论】:
我想为我的应用程序中的所有屏幕使用相同的背景图片,将其设为静态,这样当我使用导航器时它就不会移动。你知道怎么做吗?
【问题讨论】:
您可以定义一个带有背景图像的小部件,然后在其上堆叠您想要的屏幕。
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,
],
),
);
}
}
【讨论】: