Flutter 顶部的图像()和图像下方带有文本的框

Flutter 顶部的图像()和图像下方带有文本的框,flutter,dart,Flutter,Dart,我需要做一些像附加的图像一样的事情 以下是我尝试过的: Container( height: 300.0, decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.fitWidth, alignment: FractionalOffset.center, image: CachedNetworkImageProvider(image_

我需要做一些像附加的图像一样的事情

以下是我尝试过的:

Container(
    height: 300.0,
    decoration: BoxDecoration(
        image: DecorationImage(
          fit: BoxFit.fitWidth,
          alignment: FractionalOffset.center,
          image: CachedNetworkImageProvider(image_url),
        )
    ),
    alignment: Alignment.bottomCenter,
    child: Container(
        margin: const EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
        width: MediaQuery.of(context).size.width * 0.92,
        child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: AutoSizeText(
                my_text,
                style: TextStyle(fontSize: 19),
                maxLines: 1,
                textAlign: TextAlign.center
            )
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.8),
              spreadRadius: 1,
              blurRadius: 3,
              offset: Offset(1, 1),
            ),
          ],
        )
    )
)
此代码的问题是:

  • 如果图像不够高,则在应用程序栏和图像之间的屏幕顶部会出现一个白色条
  • 文本框的位置取决于容器的高度:我需要框始终一半在图像内部,一半在图像外部

您必须使用堆叠小部件,但请确保使用BoxFit和as盖,以填充整个容器高度

Stack(
        alignment: Alignment.topCenter,
        children: <Widget>[
          Container(
            height: 300.0,
            decoration: BoxDecoration(
                image: DecorationImage(
              fit: BoxFit.cover,
              alignment: FractionalOffset.center,
              image: AssetImage('assets/images/image.jpg'),
            )),
          ),
          Container(
            margin: EdgeInsets.only(top: 280),
            width: MediaQuery.of(context).size.width * 0.92,
            child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text("jitesh",
                    style: TextStyle(fontSize: 19),
                    maxLines: 1,
                    textAlign: TextAlign.center)),
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.grey.withOpacity(0.8),
                  spreadRadius: 1,
                  blurRadius: 3,
                  offset: Offset(1, 1),
                ),
              ],
            ),
          )
        ],
      ),
堆栈(
对齐:alignment.topCenter,
儿童:[
容器(
高度:300.0,
装饰:盒子装饰(
图像:装饰图像(
适合:BoxFit.cover,
对齐:分馏loffset.center,
image:AssetImage('assets/images/image.jpg'),
)),
),
容器(
页边距:仅限边缘集(顶部:280),
宽度:MediaQuery.of(context).size.width*0.92,
孩子:填充(
填充:常数边集全部(8.0),
子:文本(“jitesh”,
样式:TextStyle(字体大小:19),
maxLines:1,
textAlign:textAlign.center),
装饰:盒子装饰(
颜色:颜色,白色,
boxShadow:[
箱形阴影(
颜色:颜色。灰色。不透明度(0.8),
扩展半径:1,
半径:3,
偏移量:偏移量(1,1),
),
],
),
)
],
),
更多信息

您必须使用堆叠小部件,但请确保使用BoxFit和as封面,以填充容器的整个高度

Stack(
        alignment: Alignment.topCenter,
        children: <Widget>[
          Container(
            height: 300.0,
            decoration: BoxDecoration(
                image: DecorationImage(
              fit: BoxFit.cover,
              alignment: FractionalOffset.center,
              image: AssetImage('assets/images/image.jpg'),
            )),
          ),
          Container(
            margin: EdgeInsets.only(top: 280),
            width: MediaQuery.of(context).size.width * 0.92,
            child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text("jitesh",
                    style: TextStyle(fontSize: 19),
                    maxLines: 1,
                    textAlign: TextAlign.center)),
            decoration: BoxDecoration(
              color: Colors.white,
              boxShadow: [
                BoxShadow(
                  color: Colors.grey.withOpacity(0.8),
                  spreadRadius: 1,
                  blurRadius: 3,
                  offset: Offset(1, 1),
                ),
              ],
            ),
          )
        ],
      ),
堆栈(
对齐:alignment.topCenter,
儿童:[
容器(
高度:300.0,
装饰:盒子装饰(
图像:装饰图像(
适合:BoxFit.cover,
对齐:分馏loffset.center,
image:AssetImage('assets/images/image.jpg'),
)),
),
容器(
页边距:仅限边缘集(顶部:280),
宽度:MediaQuery.of(context).size.width*0.92,
孩子:填充(
填充:常数边集全部(8.0),
子:文本(“jitesh”,
样式:TextStyle(字体大小:19),
maxLines:1,
textAlign:textAlign.center),
装饰:盒子装饰(
颜色:颜色,白色,
boxShadow:[
箱形阴影(
颜色:颜色。灰色。不透明度(0.8),
扩展半径:1,
半径:3,
偏移量:偏移量(1,1),
),
],
),
)
],
),
更多信息

这可以通过使用Stack小部件来实现。检查一下:这可以通过使用Stack小部件来实现。看看这个: