I have a problem with a personalized text - flutter

THe principal problem is when i a put a text with textile with personalized font the heigh by default is 0.0, but when i try to change the height the space is infinite and the text dissapear.
Container(
//height: 200,
//width: 20,
alignment: Alignment.centerLeft,
child: Text(
"Parece que olvidaste tu\ncontraseña, ¿Qué deseas hacer?",
textAlign: TextAlign.start,
style: TextStyle(
//fontFamily: 'GothamBook',
height: 0.6,
fontSize: 16.0,
fontStyle: FontStyle.normal,
),
))

Related

Text is shifted vertically in Flutter

I have the following code:
AutoSizeText.rich(
TextSpan(children: [
const TextSpan(
text: "\$",
style: TextStyle(
color: Colors.white,
fontSize: 45,
height: 1.0,
letterSpacing: .0,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: widget.budget.truncate().toString(),
style: const TextStyle(
color: Colors.white,
fontSize: 90,
),
),
TextSpan(
text: ".${widget.budget.toStringAsFixed(2).split(".")[1]}",
style: const TextStyle(
color: Colors.white,
fontSize: 45,
),
),
]),
style: GoogleFonts.manrope(
fontSize: 45,
letterSpacing: -4.5,
height: 1.0,
fontWeight: FontWeight.w600,
textStyle: const TextStyle(
leadingDistribution: TextLeadingDistribution.even,
)),
textAlign: TextAlign.center,
maxLines: 1,
);
The code results in this (I also tried with Text.rich instead of AutoSizeText but the result is the same):
In the image, I have wrapped the text in a red container to check its bounding box.
I am implementing this element following a design I made in Figma:
Similatly, in this image the red frame has an autolayout applied with all padding set to 0, in a way that simulates wrapping the text in a Container.
The text looks the same in both the design and the Flutter implementation, but the Flutter one is shifted upwards, which on big text sizes is really noticeable. I figured it might have something to do with the vertical alignment of the text but I could not find any way to fix it.
Is this an expected behaviour or am I doing something wrong?

How to add a colored background which looks like an underline BENEATH the text in a sentence in Flutter?

The first word is underlined but if you look closely, the text overlaps a part of the colored shape/part. It is not just under the text.
Here is what I am trying to achieve:
Here's my current code:
text: TextSpan(children: <TextSpan>[
TextSpan(
text: "Welcome",
style: TextStyle(
color: HSColors.darkBlue,
decoration: TextDecoration.underline,
decorationColor: HSColors.cream,
decorationThickness: 5.h,
fontSize: 30.sp,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
),
TextSpan(
text: " to Veritas Monitoring Services",
style: TextStyle(
color: HSColors.darkBlue,
fontSize: 30.sp,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
)
]),
),
Here is what it currently looks like:
Moreover, if I use other text, it overlaps and looks like this:
You need to work with decorationThickness value.
decorationThickness: 5.h,
I have lower the decorationThickness value to
decorationThickness: 0.2.h,
Here's the result on iPhone 12 simulator
You can acheive this using Stack as shown below. Set the behind container's height and width as per your need. Thanks
Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
height: 15,
width: 130,
color: Colors.amber,
),
Text("Welcome",
style: TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.w700,
height: 1.1,
letterSpacing: -0.03),
),
],
),

Child already specified | Flutter container with headline and subheadline

When there are no results loaded on the app, there is a headline and subheadline explaining how to work the application.
However, when results are loaded into the app the Headline and subheadline disappear, and then show the imageArray in place of both
I am unable to group the headline and subheadline together because I am following a specific UI, and thus they require different font styles, but adding them both in a separate child seems to throw an error as the child is already specified.
What's the best way to rectify this?
Container(
margin: EdgeInsets.only(top: 0, left: 0, right: 0, bottom: 0),
height: MediaQuery.of(context).size.height * .8,
child: imageArray.isEmpty
? Center(
child: Text(
‘HEADLINE’,
style: TextStyle(
fontSize: 19,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
child: Text(
‘SUBHEADLINE’,
style: TextStyle(
fontSize: 16,
fontFamily: 'Avenir',
fontWeight: FontWeight.w500,
),
),
)
: GridView.count(
crossAxisCount: 2,
children: List.generate(imageArray.length, (index) {
var img = imageArray[index];
return Container(child: Image.file(img));
})))
]),
)
]));
}
}
According to the official documentation:
All layout widgets have either of the following:
A child property if they take a single child—for example, Center or Container
A children property if they take a list of widgets—for example, Row, Column, ListView, or Stack.
The problem with the code is that Center only takes a single widget as its child. In order to display both of your Text, you'll need to use something such as Column with children property. This should work:
Container(
margin: EdgeInsets.only(top: 0, left: 0, right: 0, bottom: 0),
height: MediaQuery.of(context).size.height * .8,
child: imageArray.isEmpty
? Column( // Use the Column here instead of Center
children: [
Text(
'TITLE',
style: TextStyle(
fontSize: 19,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
Text( // Remove the `child:` property
'SUBTITLE',
style: TextStyle(
fontSize: 16,
fontFamily: 'Avenir',
fontWeight: FontWeight.w500,
),
),
],
)
: GridView.count(
crossAxisCount: 2,
children: List.generate(
imageArray.length,
(index) {
var img = imageArray[index];
return Container(child: Image.file(img));
},
),
),
);
Change your Center to a Column this can take a List<Widget> called children as opposed to a singular child
Container(
margin: EdgeInsets.only(top: 0, left: 0, right: 0, bottom: 0),
height: MediaQuery.of(context).size.height * .8,
child: imageArray.isEmpty
? Column(
children: [ Text(
‘HEADLINE’,
style: TextStyle(
fontSize: 19,
fontFamily: 'Avenir',
fontWeight: FontWeight.w900,
),
),
Text(
‘SUBHEADLINE’,
style: TextStyle(
fontSize: 16,
fontFamily: 'Avenir',
fontWeight: FontWeight.w500,
),
),
]
)
: GridView.count(
crossAxisCount: 2,
children: List.generate(imageArray.length, (index) {
var img = imageArray[index];
return Container(child: Image.file(img));
})))
]),
)
]));
}
You could also add a Column to the child of your Center if you would prefer that styling.
But Column has the built in functionality to display its children where you want with mainAxisAlignment

Bottom overflowed by 100.0 pxl

I have this UI :UI
And the text is showing this yellow bar, even when I set the maxlines to 3..
I put them in a container and its still like this!
child: Container(
height: 150,
width: 200,
child: Column(children: [
Text(
allRecipes[index].name,
style: TextStyle(color: Colors.black54,
fontSize: 20,),
),
Text(
allRecipes[index].about,
softWrap: true,
maxLines: 3,
style: TextStyle(
fontSize: 14,)
),
Also, I need help from you so I can make more space between the food cards??
Its because your Container Height.
try to increase this and check,
your Container height is 150
increase this 200 or 250. as per your design requirement.
Container(
height: 250,//like this
width: 200,
child: Column(children: [
Text(
allRecipes[index].name,
style: TextStyle(color: Colors.black54,
fontSize: 20,),
),
Text(
allRecipes[index].about,
softWrap: true,
maxLines: 3,
style: TextStyle(
fontSize: 14,)
),
]
)

How to make a multi line text in Flutter

Sometimes, the text widget does a line break, and sometimes don't. I tried to add overflow and maxline but it doesn't work.
This is the code:
Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
This is what, I will try to build:
You can use FittedBox class.
Scales and positions its child within itself according to fit. The fit and alignment arguments must not be null.
FittedBox(
Key key,
fit: BoxFit.none,
alignment: Alignment.center,
child: Text(
ArticleData().articleBank[index].articleTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.black,
),
),
)