【发布时间】:2020-01-23 23:24:52
【问题描述】:
我正在尝试使下面的按钮根据不同的屏幕尺寸调整大小,但保持相同的比例(即文本和按钮大小应按比例更改,以便它们在所有屏幕上看起来都相同)。我正在使用 AutoSizeText 包根据屏幕大小调整文本大小,但文本在较小的屏幕上似乎并没有变小,这可能导致按钮奇怪地调整大小。
[![button 1][1]][1] - 更大的屏幕 [![按钮 2][2]][2] - 更小的屏幕
我尝试使用媒体查询来调整按钮的高度和宽度,但这似乎不起作用。
有推荐的方法吗?
class PurchaseButton extends StatelessWidget {
final Product product;
PurchaseButton({Key key, @required this.product}) : super(key: key);
@override
Widget build(BuildContext context) {
double deviceWidth = MediaQuery.of(context).size.width;
Container(
margin: EdgeInsets.symmetric(horizontal: 0.05 * deviceWidth),
child: Row(
children: <Widget>[
Expanded(
child: MaterialButton(
// height: SizeConfig.blockSizeVertical * 6,
onPressed: () async {
await Provider.of<SubscriptionModel>(context).makePurchase(product);
},
child: Text('Join now! Only ${product.priceString}',
style: Theme.of(context).textTheme.body1.copyWith(
fontWeight: FontWeight.w600, fontSize: 0.03 * deviceWidth)),
color: Theme.of(context).primaryColor,
),
),
],
),
);
return Container();
}
}
【问题讨论】: