如何根据 Flutter 中的屏幕大小调整测试大小?
How to resize test based on screen size in Flutter?
我正在 Flutter 上开发一个应用程序,我的主页中有一个包含两个文本小部件的列。问题是在手机 phone 上,文字大小是正常的,但在平板电脑上,文字太小了,看不清。您能否建议一种根据屏幕尺寸动态放大文本的方法?
小部件:
Column(
children: [
Text(
widget.label,
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.white,
fontWeight: FontWeight.bold),
),
Text(
widget.description,
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.white,
fontWeight: FontWeight.w100),
)
],
),
谢谢
此包在这里:
auto_size_text
, https://pub.dev/packages/auto_size_text
会有帮助。
你可以有两种方法:
- 使用
auto_size_text
包
- 使用
MediaQuery.of(context).size.width
和 MediaQuery.of(context).size.height
访问屏幕的宽度和高度,然后使用它们调整 SizedBox
的大小并将您的文本作为 FittedBox(child:YourTextWidget)
传递给此小部件.例如:
SizedBox(
width: 0.5 * screenWidth, // change 0.5 to whatever your want
child:FittedBox(
child: Text("Your Text")
))
我正在 Flutter 上开发一个应用程序,我的主页中有一个包含两个文本小部件的列。问题是在手机 phone 上,文字大小是正常的,但在平板电脑上,文字太小了,看不清。您能否建议一种根据屏幕尺寸动态放大文本的方法?
小部件:
Column(
children: [
Text(
widget.label,
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.white,
fontWeight: FontWeight.bold),
),
Text(
widget.description,
style: TextStyle(
fontFamily: 'Roboto',
color: Colors.white,
fontWeight: FontWeight.w100),
)
],
),
谢谢
此包在这里:
auto_size_text
, https://pub.dev/packages/auto_size_text
会有帮助。
你可以有两种方法:
- 使用
auto_size_text
包 - 使用
MediaQuery.of(context).size.width
和MediaQuery.of(context).size.height
访问屏幕的宽度和高度,然后使用它们调整SizedBox
的大小并将您的文本作为FittedBox(child:YourTextWidget)
传递给此小部件.例如:
SizedBox(
width: 0.5 * screenWidth, // change 0.5 to whatever your want
child:FittedBox(
child: Text("Your Text")
))