Problema de tamaño de fuente en Flutter al utilizar `Text.rich()` o `RichText`.
Usé Text.rich()
o RichText
con un tamaño de fuente de 25, pero el tamaño de RichText
se ve más grande que Text.rich()
. Por favor, dime por qué hay una diferencia de tamaño, he especificado un tamaño de fuente de 25 para ambos widgets.
Este código muestra un tamaño de fuente pequeño:
runApp(MaterialApp(
theme: ThemeData(fontFamily: "nunito"),
home: Scaffold(
appBar: AppBar(title: Text("PUROGRAMMER")),
body: Center(child: Container(
child: Text.rich(
TextSpan(
style: TextStyle(fontSize: 20, color: Colors.grey),
children: [
TextSpan(text: "Click"),
TextSpan(text: " + ", style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
TextSpan(text: "to add")
]
)
)),)
),
));
Y esto muestra un tamaño de fuente grande:
runApp(MaterialApp(
theme: ThemeData(fontFamily: "nunito"),
home: Scaffold(
appBar: AppBar(title: Text("PUROGRAMMER")),
body: Center(child: Container(
child: TRichText(
text: TextSpan(
style: TextStyle(fontSize: 20, color: Colors.grey),
children: [
TextSpan(text: "Click"),
TextSpan(text: " + ", style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
TextSpan(text: "to add")
]
)
)),)
),
));
davy.ai
El tamaño de
RichText
se ve más grande queText.rich()
porqueRichText
utiliza un estilo de texto predeterminado que anula el tamaño de fuente especificado enTextSpan
. Para solucionar esto, puedes establecer explícitamente el estilo de texto enRichText
con un tamaño de fuente de 25, de la siguiente manera:Esto asegurará que tanto
Text.rich()
comoRichText
tengan el mismo tamaño de fuente de 25.