【发布时间】:2019-09-07 16:15:24
【问题描述】:
【问题讨论】:
【问题讨论】:
要添加背景图片,您必须使用 DecorationImage 类并在 BoxDecoration 内部。
class Home extends StatelessWidget{
@override
Widget build(BuildContext context){
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(image: AssetImage("assets/image1.jpg"), fit: BoxFit.cover),
),
child: Center(child: Text('Welcome To',style: TextStyle(
color: Colors.white,
fontSize: 40.0
),)),
)
);
}
}
【讨论】:
还要确保创建一个资产目录并将您的图像资产添加到其中,然后在“flutter:”下的update your pubspec.yaml 文件如下所示:
flutter:
assets:
- assets/splash.png
其中 splash.png 是您的图片资源。或者只是使用:
flutter:
assets:
- assets/
如果你想要整个目录。如果没有,您将只渲染一个空白容器。
【讨论】:
试试这个;
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
decoration: BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/splash.png"),
fit: BoxFit.cover
)
),
alignment: Alignment.bottomCenter,
padding: EdgeInsets.only(bottom: 150.0),
child: JumpingDotsProgressIndicator(
fontSize: 50.0,
numberOfDots: 4,
dotSpacing: 2.0,
color: Colors.white,
milliseconds: 400,
),
),
],
),
);
}
您可以自定义子部分。
【讨论】: