这里是代码,我需要紧急回复
// ignore_for_file: prefer_const_constructors, file_names, prefer_const_literals_to_create_immutables, use_full_hex_values_for_flutter_colors
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class RowItemsWidget extends StatelessWidget {
const RowItemsWidget({super.key});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Container(
margin: EdgeInsets.only(top: 10, bottom: 10, left: 15),
padding: EdgeInsets.symmetric(horizontal: 10),
height: 180,
// width: 200,
decoration: BoxDecoration(
color: Color(0xfff5f9fd),
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color(0xff47569).withOpacity(0.3),
blurRadius: 5,
spreadRadius: 1,
)
]),
child: Row(children: [
Stack(
alignment: Alignment.center,
children: [
Container(
// margin: EdgeInsets.only(top: 20, right: 70),
height: 120,
width: 130,
decoration: BoxDecoration(
color: Color(0xFF475269),
borderRadius: BorderRadius.circular(10),
),
),
Image.asset(
"images/1.png",
height: 150,
width: 150,
fit: BoxFit.contain,
)
],
),
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Nike Shoe',
style: TextStyle(
color: Color(0xff475269),
fontSize: 23,
fontWeight: FontWeight.w500,
),
),
SizedBox(
height: 5,
),
Text(
"Men's Shoe",
style: TextStyle(
color: Color(0xff475269).withOpacity(0.8),
fontSize: 16),
)
]),
),
Spacer(),
Row(
children: [
Text(
"\$50",
style: TextStyle(
color: Colors.redAccent,
fontSize: 22,
fontWeight: FontWeight.w500,
),
),
SizedBox(width: 70),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Color(0xff475269),
borderRadius: BorderRadius.circular(10)),
child: Icon(
CupertinoIcons.cart_fill_badge_plus,
color: Colors.white,
size: 25,
),
),
],
)
]),
)
]),
);
}
}
我试图用一个 sizedBox 包裹我的 cintainer,但它抛出了一个错误。我真的不知道该怎么办
Spacer()
不适合您当前的小部件树。将 Spacer
替换为 SizedBox。您可以在脚手架主体上使用 LayoutBuilder 来获取布局约束。
class RowItemsWidget extends StatelessWidget {
const RowItemsWidget({super.key});
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Container(
margin: EdgeInsets.only(top: 10, bottom: 10, left: 15),
padding: EdgeInsets.symmetric(horizontal: 10),
height: 180,
// width: 200,
decoration: BoxDecoration(
color: Color(0xfff5f9fd),
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color(0xff47569).withOpacity(0.3),
blurRadius: 5,
spreadRadius: 1,
)
]),
child: Row(children: [
Stack(
alignment: Alignment.center,
children: [
Container(
// margin: EdgeInsets.only(top: 20, right: 70),
height: 120,
width: 130,
decoration: BoxDecoration(
color: Color(0xFF475269),
borderRadius: BorderRadius.circular(10),
),
),
Image.asset(
"images/1.png",
height: 150,
width: 150,
fit: BoxFit.contain,
)
],
),
Padding(
padding: EdgeInsets.symmetric(vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Nike Shoe',
style: TextStyle(
color: Color(0xff475269),
fontSize: 23,
fontWeight: FontWeight.w500,
),
),
SizedBox(
height: 5,
),
Text(
"Men's Shoe",
style: TextStyle(
color: Color(0xff475269).withOpacity(0.8),
fontSize: 16),
)
]),
),
// Spacer(),
Row(
children: [
Text(
"\$50",
style: TextStyle(
color: Colors.redAccent,
fontSize: 22,
fontWeight: FontWeight.w500,
),
),
SizedBox(width: 70),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Color(0xff475269),
borderRadius: BorderRadius.circular(10)),
child: Icon(
CupertinoIcons.cart_fill_badge_plus,
color: Colors.white,
size: 25,
),
),
],
)
]),
)
]),
);
}
}