在颤动中添加背景图像

问题描述 投票:1回答:2

我正在尝试在Flutter中创建附加的屏幕。如何添加背景图像并在特定位置添加文本(忽略白色文本框)。

谢谢你的帮助

enter image description here

flutter flutter-layout
2个回答
1
投票

要添加背景图像,您必须使用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
            ),)),
            )
        );
      }
    }

enter image description here


0
投票

试试这个;

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,
        ),
      ),

    ],
  ),
);
}

您可以自定义子部分。

© www.soinside.com 2019 - 2024. All rights reserved.