Flutter - Tab title overflow in Convex Bottom Bar - flutter

I am trying to use convex_bottom_bar lib, but when I try using a slightly longer title for a tab, it overflows. In the image below I tried to use the title Notifications, but it overflowed by 1 letter. I searched for solutions to this problem but I couldn't find any. Can someone help me?

Use auto_size_text package.
AutoSizeText(
'Notifications',
style: TextStyle(fontSize: 18),
minFontSize: 15,
maxLines: 1,
overflow: TextOverflow.ellipsis, // If you want to show ... after text like notifica...
)

Related

How to show overflow on textfield's value (ellipsis)

How can I achieve something like this?
That the textfields value is showing (...) when text is bigger than the remaining space
When the text input
I know we can use overflow: TextOverflow.ellipsis, in a Text widget. How can we do something similar in textfield value?
i think for now ,there is no parameter to set overflow on TextField
since the issue still open on official repository here.
maybe you can use another plugin like auto_size_text_field
AutoSizeTextField(
controller: _controller,
overflowReplacement: Text(
_controller.text,
style: const TextStyle(overflow: TextOverflow.ellipsis),
),

Flutter | auto_size_text inside of Expanded FittedBox

Disclaimer:
I am very new to flutter, this is my first solo project that I am creating. All other projects have only been very short tutorials. The problem I am having (described below) may seem like a very easy fix, but as I am new please do explain it in detail as best you can, being able to visualize what you are saying also helps (through code, diagrams etc). Thank you.
Problem:
Unable to get auto_size_text maxLines to work correctly. On top of this, unable to get MaxFontSize working.
Further Explanation
I am using the auto_size_text package, setup with the pubspec.yaml dependency: auto_size_text: ^2.1.0 and import: 'package:auto_size_text/auto_size_text.dart'. I also changed my pubspec.yaml environment from sdk: ">=2.12.0 <3.0.0" to sdk: ">=2.11.0 <3.0.0" to allow non null safe packages to work - as per direction of this tutorial.
I am creating a container inside of my app, inside of this container is a Column widget, inside the Column widget are several rows. One of these rows is intended as a title. The code for it is below:
Row( // Row is inside of a Column which is inside of a Container
children: [
const SizedBox(width: 55), // Used to create padding either side of text
Expanded(
child: FittedBox(
child: AutoSizeText(
'70 | Brighton - Abbotsford and Green Island', // Header Example
maxLines: 2, // Cannot get this to work, always remains one line
maxFontSize: 20, // Does not work, always resizes to max font in order to fill whole FittedBox
style: TextStyle(
fontSize: 20, // Unsure if I need this, adding or removing seems to have to effect.
color: color.AppColor.textMain.withOpacity(0.8),
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(width: 55), // Used to create padding either side of text
],
),
With this code I get this result - Note that the blue line is another row above the title but still inside of the same Column widget.
Desired Result:
The font is far too small, so I want it to be split among two lines. I am designing this container to be reused and I will later change it so the text is imported from a CSV file so name lengths will be varied. They all need to be readable, and while it's fine for smaller titles (example), larger ones need to have a bigger font while still fitting inside the same boundaries, so two lines is required. As also mentioned, I am unable to get the maxFontSize working, resulting in shorter titles having too large of a font.
Attempted Solutions:
I have tired using a null safe version of auto_size_text but was unable to get it working (as it's a prerelease I assume it isn't functioning properly).
I have another solution without using auto_size_text package
SizedBox(
child: TextField(
controller: _yourController,
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.all(8),
),
textInputAction: TextInputAction.done,
keyboardType: TextInputType.multiline,
maxLines: null,
),
),
keyboardType: TextInputType.multiline makes TextField can be resized automatically and move to new line if it reach max width, and
maxLines: null makes your text can be written with many lines, and then
decoration here i use to remove TextField box border
Solved
I solved my own problem almost accidently while playing around with the code I posted in the original question.
Solution:
Although not the most convenient, the solution is to replace the Expanded widget and FittedBox to a SizedBox. Below is the adjusted code including comments about changes made.
Row( // Row is inside of a Column which is inside of a Container
children: [
const SizedBox(width: 55), // Used to create padding either side of text
SizedBox( // Changed the Expanded and FittedBox to a sized box with a width of 280, source container has a width of 390, so text is allowed a width of 280 once you subtract the width 55 SizedBox's either side
width: 280,
child: AutoSizeText(
'70 | Brighton - Abbotsford and Green Island', // Header Example
maxLines: 2, // Cannot get this to work, always remains one line
maxFontSize: 20, // Does not work, always resizes to max font in order to fill whole FittedBox
style: TextStyle(
fontSize: 20, // Unsure if I need this, adding or removing seems to have to effect.
color: color.AppColor.textMain.withOpacity(0.8),
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 55), // Used to create padding either side of text
],
),
Thanks

Styling Html Widget in Flutter Dart

I am using the flutter_html package
I have this in my flutter project, i have been trying to style the line height property of the resulting text rendered in my view and its not working and i dont seem to find a solution anywhere.
Any help will be appreciated
Html(
data: detail.length >= 300 ? detail.substring(0, 300) + " ...": detail.substring(0),
style: {
"html":Style(
/* wordSpacing: 3, */
textAlign: TextAlign.justify,
whiteSpace: WhiteSpace.NORMAL
),
},
)
Currently the Html() widget from flutter_html: ^1.x.x is not supporting line-height property of css.
So you need to use HtmlWidget() from flutter_widget_from_html: ^0.5.x
HtmlWidget(
htmlData,
textStyle: TextStyle(height: 1.8)
)

Flutter: how to add icon to text?

I want to add an icon with text. I didn't find any clear answer. Please suggest to me how to do this in a flutter. Just like this one.
Here are two approaches, depending on exactly what you want.
RichText with WidgetSpan
Using RichText you can mix TextSpans with WidgetSpans. WidgetSpan allows you to place any Flutter widget inline with the text. For example:
RichText(
text: TextSpan(
style: Theme.of(context).textTheme.body1,
children: [
TextSpan(text: 'Created with '),
WidgetSpan(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Icon(Icons.airport_shuttle),
),
),
TextSpan(text: 'By Michael'),
],
),
)
Will give the following:
(Note: MaterialIcons did not include a heart when I answered, but does now with Icons.favorite)
This is a good general purpose solution, but for your specific example there's something simpler...
Emoji
Flutter's text supports Emoji out of the box. So you can do this:
Center(
child: Text(
'Created with ❤ ️by Michael',
maxLines: 1,
),
),
And you get this:
You can also use Unicode escapes in the string and get the same result:
'Created with \u2764️ by Michael'
Note that not all fonts have support for the full set of Emoji, so make sure you test on a variety of devices or use a specific font (see other answer below).
Regarding Emojis, in android not all emojis are supported (depending on OS version).
For full emoji compatibility you can use the google free font Noto Color Emoji at https://www.google.com/get/noto/#emoji-zsye-color
Add it to the fonts folder
add in pubspec.yaml
fonts:
- family: NotoEmoji
fonts:
- asset: fonts/NotoColorEmoji.ttf
weight: 400
use with TextStyle
Text("🤑", TextStyle(fontFamily: 'NotoEmoji'))

Is there any way of using Text with spritewidget in Flutter?

I'm developing a game in Flutter with spritewidget library. I'd like to know if is it possible to use text inside a SpriteWidget.
I know i can use regular Flutter widgets but i need that the text size is relative to SpriteWidget so it can be consistently shown in different screen sizes.
I have searched library documentation but i haven't found anything related to text render.
Any suggestion would be appreciated!!
You can absolutely use text inside a SpriteWidget. There is the Label node for that particular purpose. If you need more advanced text rendering, you can use the code from the Label as your starting point.
Example:
Label label = Label(
'My text label',
textAlign: TextAlign.center,
textStyle: new TextStyle(
fontFamily: 'Orbitron',
letterSpacing: 10.0,
color: Colors.white,
fontSize: 24.0,
fontWeight: FontWeight.w600
)
);
addChild(label);