容器的宽度在CustomScrollView中的SliverToBoxAdapter内不起作用



我有一个CustomScrollView包含一个SliverToBoxAdapter。我给出的宽度为MediaQuery.of(context).size.width / 1.75。但它占用了整个屏幕的宽度。在此处输入图像描述。如果容器放置在Customscrollview之外,则容器的宽度有效。

class ProfileView extends GetView<ProfileController> {
const ProfileView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Row(children: [
Expanded(
child: CustomScrollView(
shrinkWrap: true,
slivers: [
SliverToBoxAdapter(
child: Padding(
padding:
const EdgeInsets.only(top: 40.0, left: 45),
child: Container(
padding: EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border:
Border.all(color: Colors.red, width: 0.7),
color: Color(0xfffbfbfa),
),
child: Stack(
children: [
Positioned(
right: 0,
top: 0,
child: Align(
alignment: Alignment.topRight,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: Padding(
padding: const EdgeInsets.only(
right: 18.0),
child: Text(
"Edit",
textAlign: TextAlign.left,
style: GoogleFonts.inter(
color: AppColors.primaryColor,
fontSize: 13,
letterSpacing:
0
,
fontWeight: FontWeight.w400,
height: 1.5769230769230769),
),
),
),
),
),
Text("Text"),
],
),
),
),
)
],
),
)
])

);
}

您必须用Align小部件包装您的容器,如下所示:

SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 40.0, left: 45),
child: Align(
alignment: Alignment.center,
child: Container(
padding: const EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width / 1.75,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 0.7),
color: Colors.amber,
),
....

相关内容

  • 没有找到相关文章

最新更新