如何修复"底部溢出4.0像素颤动"错误



我使用的是一个构建在Flutter上的包。一些安卓设备出现错误。我在解决这个问题时遇到了麻烦,并寻找一些解决方案,其中人们更喜欢使用名为";展开的";但它不起作用。我需要包东西吗?如果是,怎么做?这个错误意味着什么?

你可以在这里看到这个图像中的错误,点击查看

final addProductToCart =
Provider.of<CartModel>(context, listen: false).addProductToCart;
final currency = Provider.of<AppModel>(context, listen: false).currencyCode;
final currencyRate = Provider.of<AppModel>(context).currencyRate;
var salePercent = 0;
if (item == null) return Container();
double regularPrice = 0.0;
var productImage = width * (ratioProductImage ?? 1.2);
// ignore: unrelated_type_equality_checks
if (item.regularPrice != null &&
item.regularPrice.isNotEmpty &&
item.regularPrice != '0.0') {
regularPrice = (double.tryParse(item.regularPrice.toString()));
}
final gauss = offset != null
? math.exp(-(math.pow(offset.abs() - 0.5, 2) / 0.08))
: 0.0;
/// Calculate the Sale price
bool isSale = (item.onSale ?? false) &&
Tools.getPriceProductValue(item, currency, onSale: true) !=
Tools.getPriceProductValue(item, currency, onSale: false);
if (isSale && regularPrice != 0) {
salePercent =
(double.parse(item.salePrice) - regularPrice) * 100 ~/ regularPrice;
}
if (item.type == 'variable') {
isSale = item.onSale ?? false;
}
if (hideDetail) {
return _buildImageFeature(
context,
() => _onTapProduct(context),
);
}
var priceProduct = Tools.getPriceProductValue(
item,
currency,
onSale: true,
);
/// Sold by widget
Widget _soldByStore = item.store != null && item.store.name != ""
? Padding(
padding: const EdgeInsets.only(top: 2, bottom: 2),
child: Text(
S.of(context).soldBy + " " + item.store.name,
style: const TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
),
)
: Container();
/// product name
Widget _productTitle = Text(
item.name + 'n' ?? '',
style: Theme.of(context).textTheme.subtitle1.apply(
fontSizeFactor: 0.9,
),
maxLines: 2,
);
/// Product Pricing
Widget _productPricing = Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
Text(
item.type == 'grouped'
? '${S.of(context).from} ${Tools.getPriceProduct(item, currencyRate, currency, onSale: true)}'
: priceProduct == '0.0'
? S.of(context).loading
: Config().isListingType()
? Tools.getCurrencyFormatted(
item.price ?? item.regularPrice ?? '0', null)
: Tools.getPriceProduct(item, currencyRate, currency,
onSale: true),
style: Theme.of(context)
.textTheme
.headline6
.copyWith(
fontWeight: FontWeight.w600,
)
.apply(fontSizeFactor: 0.8),
),
/// Not show regular price for variant product (product.regularPrice = "").
if (isSale && item.type != 'variable') ...[
const SizedBox(width: 5),
Text(
item.type == 'grouped'
? ''
: Tools.getPriceProduct(item, currencyRate, currency,
onSale: false),
style: Theme.of(context)
.textTheme
.caption
.copyWith(
fontWeight: FontWeight.w300,
color: Theme.of(context).accentColor.withOpacity(0.6),
decoration: TextDecoration.lineThrough,
)
.apply(fontSizeFactor: 0.8),
),
]
],
);
/// Product Stock Status
Widget _stockStatus = _buildStockStatus(context);
/// product rating, Hide rating for onSale layout.
Widget _rating = (kAdvanceConfig['EnableRating']) &&
(kAdvanceConfig['hideEmptyProductListRating'] == false ||
(item.ratingCount != null && item.ratingCount > 0)) &&
!(showProgressBar ?? false)
? SmoothStarRating(
allowHalfRating: true,
starCount: 5,
rating: item.averageRating ?? 0.0,
size: 10.0,
color: kColorRatingStar,
borderColor: kColorRatingStar,
label: Text(
item.ratingCount == 0 || item.ratingCount == null
? ''
: '${item.ratingCount}',
style: Theme.of(context)
.textTheme
.caption
.apply(fontSizeFactor: 0.7),
),
spacing: 0.0)
: Container();
/// Show Cart button
Widget _showCart = (showCart &&
!item.isEmptyProduct() &&
item.inStock != null &&
item.inStock &&
item.type != "variable")
? IconButton(
icon: const Icon(Icons.add_shopping_cart, size: 18),
onPressed: () {
String message =
addProductToCart(product: item, context: context);
_showFlashNotification(item, message, context);
})
: Container(width: 30, height: 30);
/// Show Stock status & Rating
Widget _productStockRating = Align(
alignment: Alignment.bottomLeft,
child: Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_stockStatus,
_rating,
const SizedBox(height: 4),
],
),
),
const SizedBox(width: 10),
],
),
Positioned(
right: 0,
top: -8,
child: _showCart,
)
],
),
);
Widget _productImage = Stack(
children: <Widget>[
Container(
constraints: BoxConstraints(maxHeight: productImage),
child: Transform.translate(
offset: Offset(18 * gauss, 0.0),
child: _buildImageFeature(
context,
() => _onTapProduct(context),
),
),
),
/// Not show sale percent for variant product (product.regularPrice = "").
if (isSale &&
(item.regularPrice?.isNotEmpty ?? false) &&
regularPrice != null &&
regularPrice != 0.0 &&
item.type != 'variable')
Positioned(
left: 0,
top: 0,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
decoration: const BoxDecoration(
color: Colors.redAccent,
borderRadius:
BorderRadius.only(bottomRight: Radius.circular(12))),
child: Text(
'$salePercent%',
style: Theme.of(context)
.textTheme
.caption
.copyWith(
fontWeight: FontWeight.w700,
color: Colors.white,
)
.apply(fontSizeFactor: 0.9),
),
),
),
/// Show On Sale label for variant product.
if (isSale && item.type == 'variable')
Align(
alignment: Alignment.topLeft,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: const BoxDecoration(
color: Colors.redAccent,
borderRadius:
BorderRadius.only(bottomRight: Radius.circular(8))),
child: Text(
S.of(context).onSale,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
),
],
);
Widget _productInfo = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
_productTitle,
_soldByStore,
const SizedBox(height: 5),
_productPricing,
const SizedBox(height: 2),
_productStockRating,
],
);
return GestureDetector(
onTap: () => _onTapProduct(context),
behavior: HitTestBehavior.opaque,
child: Stack(
children: <Widget>[
Container(
constraints: BoxConstraints(maxWidth: maxWidth ?? width),
width: width - 6,
margin: const EdgeInsets.only(top: 4, right: 4),
padding: const EdgeInsets.symmetric(horizontal: 6.0),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(3.0),
// border: Border.all(width: 1.0, color: Colors.grey),
// boxShadow: [
//   const BoxShadow(
//     color: Colors.black12,
//     offset: Offset(0, 1),
//     blurRadius: 2,
//   ),
// ],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
children: <Widget>[
_productImage,
_productInfo,
],
),
),
if (showHeart && !item.isEmptyProduct())
Positioned(
top: 5,
right: 5,
child: HeartButton(product: item, size: 18),
)
],
),
);
}```

我可以看到有两行的_productTitle,使小部件的高度可以容纳两行,或者使用FittedBox作为父级。请在此处查看详细信息。

查看扩展或灵活的小部件,它们只会占用可用空间,不会溢出

最新更新