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.
Related
I am displaying Tooltip on top of a Text, letting user see the full name of person, but it shows Tooltip, either when text has overflown or not:
child: Tooltip(
message: fullNameWithTitle,
child: Text(
fullNameWithTitle,
style: const TextStyle(
color: Colors.white,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
),
But how can I set Tooltip in such a way that displays just if text is trimmed by ellipsis?
I am creating an App Login page using Flutter framework and I want the the TextButton as well as the "Forgot password?" text to be horizontally aligned in the screen, but the following code displays the button below the "Forgot Password?" text. I tried modifying the button's height and width parameters as well as modifying the spacing in the Wrap widget but I still didn't get the expected outcome. Wrapping the TextButton with SizedBox widget too didn't worked as it hid the button from the screen. Is there any other way to get the desired outcome?
Part of the screen where the TextButton and "Forgot password?" text is displayed
Wrap(
children: [
Text(
"Forgot password?",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
),
TextButton(
onPressed: () {},
child: Text(
"Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
),
),
],
),
if you want to Align your two buttons horizontally, just wrap them with a Row widget, userSizedbox to adjust space between them, and if necessary wrap the Row with Padding to adjust the location of buttons like;
Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Row(
children: [
Text(
"Forgot password?",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
),
SizedBox(height: 10,),
TextButton(
onPressed: () {},
child: Text(
"Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
),
),
],
),
),
Try to below code hope its helpful to you. Wrap your Text and TextButton widget inside Row().
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
"Forgot password?",
),
TextButton(
onPressed: () {
//Write here your onPressed function call
print('Button Pressed!');
},
child: Text(
"Click here",
),
),
],
),
Your Result Screen->
There is another approach to overcome this with RichText, TextSpan and TapGestureRecognizer.
To use TapGestureRecognizer, you will have to import 'package:flutter/gestures.dart'
RichText(
text: TextSpan(
text: "Forgot password? ",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
),
children: [
TextSpan(
text: "Click here",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 16.0,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => {},
),
],
),
)
You can use this instead of using a TextButton.
Result is as below.
I have a RichText widget that displays a time like "5:21" where the minutes are in bold and the seconds are not.
I am using the widget inspector tool to observe the bounds of the text.
The region of the RichText widget has a large amount of padding above and below the text (like 10 dp top and bottom). On the horizontal, there is no pad at all, the region is snug to the edges of the font. How can I get the region to be snug to the top and bottom of the font when using RichText?
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: "$minutes:",
style: textStyle,
),
TextSpan(
text: "$seconds".padLeft(2, '0'),
style: textStyle.copyWith(fontWeight: FontWeight.w100),
),
],
),
),
Text(
"time",
),
],
);
try this
Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: "$minutes:",
style: textStyle,
),
TextSpan(
text: "$seconds".padLeft(2, '0'),
style: textStyle.copyWith(fontWeight: FontWeight.w100),
),
],
),
),
),
Text(
"time",
),
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,
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
)