Scaling fonts with different screensizes - flutter

I am trying to scale my fonts so that they look the same on different screen sizes, large or small. I have the code below, which is linked to an underlying theme (flutter standard theme). I have tried manually changing the fontsize but this does not help since it looks different on all screen sizes.
Is there a recommended way to auto-scale fontsize depending on screen size?
Expanded(
child: Column(
children: <Widget>[
Padding(padding: EdgeInsets.all(MediaQuery.of(context).size.height/50)),
Text("We're finding your pizza!",
textAlign: TextAlign.center,
style: theme.textTheme.title.copyWith(fontSize: 26),
),
Padding(padding: EdgeInsets.all(MediaQuery.of(context).size.height/40)),
Text(
"We'll notify you when we've found one.",
textAlign: TextAlign.center,
style: theme.textTheme.title),
Padding(padding: EdgeInsets.all(MediaQuery.of(context).size.height/40)),
Text(
"Estimated wait time:",
textAlign: TextAlign.center,
style: theme.textTheme.title),
Padding(padding: EdgeInsets.all(MediaQuery.of(context).size.height/80)),
Text(
"< 1 minute.",
textAlign: TextAlign.center,
style: theme.textTheme.title,
)],
),
),

You can try auto_size_text
Installing
add this to your pubspec.yaml
auto_size_text: ^2.1.0
Usage
AutoSizeText(
'Your auto size text',
style: TextStyle(fontSize: 20),//minimum font size
maxLines: 2,//if needed
)

Related

Add text field with text paragraph in Flutter

I am trying to add a text field inside the paragraph in flutter but not getting success below screen shot what I want to achive.
I am trying the below code
RichText(
text: TextSpan(
text: "“",
style: TextStyle(
color:
const Color(0xff56A1D5),
fontSize: 20.sp),
children: <InlineSpan>[
WidgetSpan(
child: Text(
"I want to talk with you about ",
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(
0xff506274),
fontSize: 20.sp),
),
),
const WidgetSpan(
child: SizedBox(
width: 120,
child: TextField(
decoration:
InputDecoration(
isDense: true,
contentPadding:
EdgeInsets.all(0),
),
),
),
),
WidgetSpan(
child: Text(
"(the actions, attitude, or behavior)",
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(
0xff506274),
fontSize: 20.sp),
),
),
],
),
),
But My output is look like below.
Can anyone show me where I am going to wrong or How can I achieve the same as the above image without leaving extra space?
Thanks in advance.
Your code is perfectly right. as (the actions, attitude, or behavior) this text does not fit in the screen it came into a new line. For checking this reduce your text then you may understand the issue.
Your code output when I run your code:
Desktop:
Mobile:

Flutter: when I click on other widget, SelectableText not deselect

when selecting text from SelectableText and wanting to change the selected text both SelectableText remain as they're selected.
Code:
Column(
children:[
SelectableText(
'1004',
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.center,
),
SelectableText(
'1005',
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.center,
),
]
)
*I used 2 separated SelectableText.

Text resize while maintaining multiline

Code:
Container(
constraints:
BoxConstraints(maxHeight: mediaQuery.height*0.1, minHeight: mediaQuery.height*0.05),
child: Text(
output['title'],
textAlign: TextAlign.start,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
),
),
As the screen won't be scrollable, I determine the max height for the container. With the current text, it takes 3 lines with the font size 16. If its bigger, won't appear. How to resize the fontSize if the text is bigger while mantaining multine text? Have already tried FittedBox then fit but it takes only one line
You can check auto_size_text.
Demo
AutoSizeText(
'The text to display',
style: TextStyle(fontSize: 20),
maxLines: 3,
)

fittedbox with maximum two lines in flutter

Container(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 60),
child: Text(
// subCategoryName,
"This is a very Long Text takes more space",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline3
.copyWith(color: Colors.white, fontSize: 32),
),
),
),
Look this Picture
I need this line to be a maximum of two lines and shrink the size like a FittedBox (with BoxFit.fitWidth) if the text gets even longer
When I used the FittedBox it looking like this. But I need to take it up to 2 lines if needed.. Any solution is appreciated
Got it working by the reply of Sam Chan.
I used the AutoSizeText Package
If you don't want to add an pakage, here is workaround. You can check the length of the text and based on that you can handle it.
// declare a widget
Widget titleTextWidget = Text(
title,
style: TextStyle(
fontWeight: FontWeight.w600,
),
maxLines: 2,
textAlign: TextAlign.center,
);
// use condition to render it.
title.length > 45
? FittedBox(
child: titleTextWidget,
)
: titleTextWidget,

Flutter ellipsis broken when using a custom font

I have an issue. I am using the Oxygen font from Google Fonts (Oxygen-Regular.ttf) and when I use:
child: Text(
item.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
softWrap: false,
style: TextStyle(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.left,
),
The display of ellipsis gets really weird, a small square appears:
Whereas when I use the default font of the flutter app, ... three dots appear, as I want. So, how can I solve this issue?