[widget在背景中使用图像时隐藏在背景下,颜色没有问题

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

设置背景图片时,我无法使用Flutter小部件。如果我将颜色用作背景,则小部件将正确显示,否则仅显示该小部件的文本,其他小部件颜色将显示在背景图像下。

class SplashView extends StatelessWidget {
  const SplashView({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
      Positioned.fill(  
            child: Image(
                    image: AssetImage('assets/images/decent.jpg'),
                    fit : BoxFit.fill,
            ),
           // child: Container( color: Colors.amber)
          ), 
        Container(
          margin: EdgeInsets.only(top: 20),
          padding: EdgeInsets.symmetric(horizontal: 60, vertical: 12),
          child: Text(title,
                   style: TextStyle(
                   fontSize: 18,
                   color: Colors.white
                 ),
       ),
       decoration: BoxDecoration(
       color: primaryColor,
       borderRadius: BorderRadius.circular(5),
    ),
    );

      ],
    );
  }

}

screen with background-color only

小部件在此处正确显示(按钮在此处显示背景)

screen with background Image

这里只显示按钮小部件的文本,不显示按钮背景。

注意*我在WEB上遇到此问题。

flutter
2个回答
0
投票

我运行您的代码,它可以正常工作,没有任何问题enter image description here只需检查其他图像资产,然后卸载该应用程序,然后再次运行该项目


0
投票

您应该这样使用

 class SplashView extends StatelessWidget {
  const SplashView({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[

            Image.asset(
          "assets/login_bg.png",
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          fit: BoxFit.cover,
        ),
          ), 
        Container(
          margin: EdgeInsets.only(top: 20),
          padding: EdgeInsets.symmetric(horizontal: 60, vertical: 12),
          child: Text(title,
                   style: TextStyle(
                   fontSize: 18,
                   color: Colors.white
                 ),
       ),
       decoration: BoxDecoration(
       color: primaryColor,
       borderRadius: BorderRadius.circular(5),
    ),
    );

      ],
    );
  }
}

您可以进行一些更改,例如删除定位填充以进行设置具有

的列
crossAxisAlignment: CrossAxisAlignment.start,
  mainAxisSize: MainAxisSize.max,
  mainAxisAlignment: MainAxisAlignment.start,

并在其中设置子项。

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