Flutter - text and icons not displaying sometimes - flutter

Sometimes after turning on my app, user see not rendered screen.
Buttons are available, but no labels and icons are printed.
I didn't notice it with debug version, only release.
In some cases restarting app helps, and sometimes user has to install the app again.
What may be causing this issue?
Broken screen:
And this is how it should look like
Code seems to be rather standard, e.g. logo, 'Slift' string is created this way:
#override
Widget build(BuildContext context) {
return BorderedText(
strokeWidth: strokeWidth,
strokeColor: ThemeColors.getColor3(),
child: Text(
'SLift',
style: GoogleFonts.baloo(
textStyle:
TextStyle(decoration: TextDecoration.none, fontSize: fontSize),
),
));
}

are you using MediaQuery in your code? Because sometimes it works differently on release and debug mode.

Related

How can I show the right animated text in flutter?

I need to show an animated sentence in the correct translation for the user. On first start, however, flutter is as if it were loading the animation first and then looking for the right translation even though I used InitState and DidChangeDependencies. If I switch windows and return, the translation with the animation is shown correctly, only on the first start it causes problems. Here is the animation code:
AnimatedTextKit(
isRepeatingAnimation: false,
animatedTexts: [
TypewriterAnimatedText(_frase,
textAlign: TextAlign.center,
textStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 21),
speed: Duration(milliseconds: 30))
])
This is the code of the variable "_frase":
#override
void didChangeDependencies() async {
super.didChangeDependencies();
_frase =
"${AppLocalizations.of(context)!.ext} ${DateFormat.MMMM("${AppLocalizations.of(context)!.codice}").format(DateTime.now()).capitalize()} $annoAttuale";
...
l10n.yaml:
arb-dir: lib/traduzioni
//in the animation, the first printout makes this translation, then the correct one for the user
template-arb-file: app_it.arb
output-localization-file: app_localizations.dart

Which one is performance wise better Text or extracted TextWidget function?

In my flutter code when I am creating an UI lot of places using Text widget. So I converted this Text widget into a function and calling everywhere? Text widget also including some styling. So calling the function or calling the Text widget is better (execution speed)?
Example code:
Text('Time left to Entrance exam',style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black
),);
or
Text buildText(String text,double fontSize, Color color) {
return Text(text,
style: TextStyle(
fontSize: fontSize,
color: color
),);
}
TextWidget function is more useful than multiple texts. It's absolutely a good practice and if any changes need you can able to change centrally and it's time-saving with clean code. You do not get the execution speed issue. And more important things, in both widget and function you just call a single Text widget. That's why there is no performance issue. You go for the second one for good practice.

Layout bug: Not code related but design related

This time the bug i'm facing is not code related but design related. In the login page I have;
text view just saying Log In, then I have two input fields for email and password, the third widget is where the bug is. It is Forgot Password and it is constrained to the right side of the phone screen.
Now on my device, it is like "Forgot Password". But when I installed the application on another device, it went like
"Fo
rgo
t
Pa
ss
wor
d?"
Words scattered vertically.
Here are the code screenshots,
The forgot password widget, I mentioned.
then finally the button login.
I dont know whats up? Any suggestion guys?
Remove the padding and add below code
Align(
alignment: Alignment(1.2, 0),
child: FlatButton( // You can use your own widget here
child: Text(
"Forgot Password?",
style: your text style;
),
onPressed: () {},
),
),
Add maxLines: 1, to your Text Widget:
Text(
"Forgot Password?",
maxLines: 1,
),

Check for color during widget test?

The goal is to verify the color of a RaisedButton.icon
During my widget tests, I have the ability to look for text with find.text as well as icons with find.byIcon. There is no built in method for finding color.
How does one do the equivalent of find.color?
And example of my code is
RaisedButton.icon(
color: Color(_isAttendingEvent ? 0xFFD9FFB3 : 0xFFE3FFC7),
icon: Icon(_isAttendingEvent ? Icons.star : Icons.star_border),
label: Text(
_isAttendingEvent ? 'Attending' : 'Attend',
),
),
I'm trying to determine whether there is color: Color(0xFFD9FFB3) or color: Color(0xFFE3FFC7)
And I'm not sure if this is possible
I am not sure with RaisedButton.icon, but if it is just an icon you can try using:
expect((tester.firstWidget(find.byType(Icon)) as Icon).color, Color(0xFFE3FFC7));
If it not the first icon widget that appears on your screen, you can specific an index of it by:
expect((tester.widget(find.byType(Icon).at(/*index*/)) as Icon).color, Color(0xFFE3FFC7));
Note: To find a widget colour, you need to cast that widget to be something that contain a color property
For example:
To find Material color you can use:
expect((tester.firstWidget(find.byType(Material)) as Material).color, Colors.black);
To find Container with BoxDecoration color:
expect(((tester.firstWidget(find.byType(Container)) as Container).decoration
as BoxDecoration).color, Colors.black);
To find Text color:
expect(((tester.firstWidget(find.text('text')) as Text).style).color, Colors.black);
To find Appbar Material. color
final appbar = tester.widget<AppBar>(find.byKey(Key("appbar")));
expect(appbar.backgroundColor,Colors.white);
To find Text color Material
final text = tester.widget<Text>(find.text("text"));
expect(text.style.color, Colors.grey);
expect(text.style.fontSize, 15);
Update you flutter version. It's working now, i am able to access color in widget test. My current flutter version is "Flutter 1.15.18 • channel dev".
Earlier it was not working with version "Flutter v1.12.13+hotfix.5"
Hope this will help. More details here
If you're using a TextButton, ElevatedButton, or Outlined button, the background color will be a MaterialStateProperty. You can verify the color in almost the same way as mentioned above:
expect(
tester.widget(textButton.first),
isA<TextButton>().having(
(w) => w.style?.backgroundColor?.resolve({}),
'button color',
Colors.grey,
));

Flutter text not rendering correctly in some cases

I am developing a flutter app to display speed itself. But sometime, the speed isn't rendered correctly in the UI. This doesn't happen always but happens say 5-10% of the time.
I tried to add another text field, with lesser size below it(just to debug), and the same text renders there correctly.
2 screenshots - One correct and one with the bug
I am using a column widget to display the text and this is how I am building the children list:
List<Widget> children = [];
children.add(Container(
child: Text(listenerSpeedText,
style: TextStyle(color: Colors.lightGreen, fontSize: 100.00)),
padding: EdgeInsets.only(bottom: 5.00)));
children.add(Text(
'digitalSpeed: ' + listenerSpeedText,
style: TextStyle(
color: Colors.red,
fontSize: 25.00,
),
));
return children;
Any help would be appreciated. I am not sure what is going on. Do I need to give extra width or height to container?