Flutter 中 textScaleX 和 autoSizeTextType 的等价物是什么
What is the equivalent of textScaleX and autoSizeTextType in Flutter
在Android中,我使用了textScaleX来拉伸字体。我还使用 autoSizeTextType 使字体大小响应。知道如何在 Flutter 中做到这一点吗?
<Button
android:id="@+id/buttonMinus"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="-"
android:textScaleX="1.8"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="36sp" />
您可以使用许多软件包来使文本响应所有手机,例如:
https://github.com/layounisl/responsive_flutter
https://pub.dev/packages/auto_size_text
但在我看来,最好的选择是使用 FittedBox 小部件。
只需将您的文本小部件包装到 FittedBox 小部件即可。就像我在下面的代码中使用 fittedBox 来调整到 appbar 的宽度。
AppBar(
centerTitle: true,
title: FittedBox(
fit: BoxFit.fitWidth,
child: Text('Hey this is my long text appbar title')
),
),
这将始终将您的文本保留在框中。试一试 fit 参数,您就会知道它是如何工作的。
在Android中,我使用了textScaleX来拉伸字体。我还使用 autoSizeTextType 使字体大小响应。知道如何在 Flutter 中做到这一点吗?
<Button
android:id="@+id/buttonMinus"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="-"
android:textScaleX="1.8"
app:autoSizeTextType="uniform"
app:autoSizeMaxTextSize="36sp" />
您可以使用许多软件包来使文本响应所有手机,例如:
https://github.com/layounisl/responsive_flutter
https://pub.dev/packages/auto_size_text
但在我看来,最好的选择是使用 FittedBox 小部件。 只需将您的文本小部件包装到 FittedBox 小部件即可。就像我在下面的代码中使用 fittedBox 来调整到 appbar 的宽度。
AppBar(
centerTitle: true,
title: FittedBox(
fit: BoxFit.fitWidth,
child: Text('Hey this is my long text appbar title')
),
),
这将始终将您的文本保留在框中。试一试 fit 参数,您就会知道它是如何工作的。