Flutter 无法根据宽度展开堆栈的子级
我希望文本占据缓存网络图像的宽度,但它不会扩展到图像的整个宽度 我的代码:-Flutter 无法根据宽度展开堆栈的子级,flutter,flutter-layout,Flutter,Flutter Layout,我希望文本占据缓存网络图像的宽度,但它不会扩展到图像的整个宽度 我的代码:- Container( margin: EdgeInsets.all(10), child: Stack( children: [ CachedNetworkImage( fit: BoxFit.fill,
Container(
margin: EdgeInsets.all(10),
child: Stack(
children: [
CachedNetworkImage(
fit: BoxFit.fill,
imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR9f_RbuB35f9pjcb2FigHaYKa0FwQYFW6DnQ&usqp=CAU',
width: MediaQuery.of(context).size.width,
),
Wrap(
direction: Axis.vertical,
children: [
RotatedBox(
quarterTurns: 3,
child: Container(
padding: EdgeInsets.only(top: 5,bottom: 5),
alignment: Alignment.center,
color: Colors.blue[200],
child: FittedBox(
fit: BoxFit.fitWidth,
child: Text(
'D A Y - ${index+1}',
style: GoogleFonts.gugi(
textStyle: TextStyle(
fontWeight: FontWeight.w400,
color: Colors.grey[300]
),
),
),
),
),
),
],
),
],
),
)
当前结果:-
预期结果:-
您应该尝试使用Align+RotatedBox将小部件放在屏幕的左侧,而不是包装 您可能需要使用另一个小部件来扩展RotatedBox
您可以将
定位
用作堆栈的子级
,属性为顶部:0、底部:0、左侧:0
。这将迫使它的子对象像您需要的那样扩展UPD:然后使用Text
上的Transform.rotate
小部件对其进行旋转
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“材料应用程序”,
家:脚手架(
appBar:appBar(
标题:文本(“材质应用栏”),
),
主体:容器(
保证金:所有(10),
子:堆栈(
儿童:[
形象(
图片:NetworkImage(
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR9f_RbuB35f9pjcb2FigHaYKa0FwQYFW6DnQ&usqp=CAU'),
fit:BoxFit.fill,
宽度:double.infinity,
),
定位(
左:0,,
排名:0,
底部:0,
子:容器(
宽度:100,//根据您的喜好设置宽度
颜色:颜色,蓝色,
儿童:中心(
子对象:Transform.rotate(
角度:-3.14/
2、//使用math软件包中的pi获得更精确的结果
子:文本('brownfox'),
),
),
),
),
],
),
)),
);
}
}