flutter: Bug? only FlatButton but not CupertinoButton showing Text - flutter

Did you ever experience this? Does it make sense to register this as a bug and how would I do this?
For one of my screens I have now this situation for the 2nd time: I insert a CupertinoButton with Text as a child, however, the text does not show up. In the 1st occurrence, 2 pixels of text appeared to be rendered (I saw 2 dots). I have also copied a CupertinoButton from another line and left it unchanged. No change, text does not appear. If I then only change the widget name from CupertinoButton to FlatButton (leaving everything else untouched), the text appears.
Since CupertinoButtons are typically working for me, I guess I would have to submit the whole project for a bug report, since isolating the issue does not to be appear like a straight forward job.

Please consider adding padding like this:
CupertinoButton(
padding: EdgeInsets.symmetric(vertical: 0, horizontal: 5),
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(12)),
child: Text(
'Login',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white),
),
onPressed: () => {},
),

Related

Flutter disable and enable buttons

i had made a function that enabled the second button when i press the first one, everything is working fine but when the second button is enabled i want to go to another page when i press on the second one but i can t do that, how can I reach that. Here is my code:
child: MaterialButton(
elevation: 0,
// ignore: avoid_returning_null_for_void
onPressed: isDisable ? () => null : clickButton(),
child: Text(
'Done',
style: TextStyle(
fontSize: 16.sp, fontWeight: FontWeight.w400),
),
),
I want here on pressed to go to another page but i cant in this form how can i reach that? Thank in advance
I've tried with setState
You like provide null directly instead of method body. Use like.
onPressed: isDisable ? null:() => clickButton(),
Or can be
onPressed: isDisable ? null: clickButton, //depend on `clickButton`
This way, you will be able to see the disable state on ui.

Why do parts of TextStyle trickle down the widget-tree while others don't?

I am fairly new to flutter and just stumbled across something that seems odd to me with regards to how style is affecting widgets further down the tree.
Consider the following example:
ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: const TextStyle(
fontSize: 17.0,
fontWeight: FontWeight.bold,
color: Colors.red,
)
),
onPressed: () { print("testados"); },
child: const Text(
"some testadorian text",
style: TextStyle(color: Colors.red),
),
);
I could verify that changing fontSize and fontWeight in lines 4 and 5 did produce the
expected effect. But setting the color inside the textStyle of ElevatedButton.styleFrom didn't have any visible effect at all.
Setting the color inside style of Text did produce the expected result.
What I understood so far was that Text-widgets take what is available as default-theming further up the widget tree and override those defaults when a specific property is directly set on themselves.
What am I missing out to understand this behaviour?

Text underline display line above text instead of below

As showing the given image After applying underline decoration text style to the text it shows line above text instead of below in flutter 2.2.
TextButton(
onPressed: () {},
child: Text(
getLocalValue(context, txtTermsNConditions),
style: TextStyle(
fontSize: 12.sp,
fontWeight: fwMedium,
color: Color(clrPrimary),
decoration: TextDecoration.underline),
),
)
style: TextStyle(decoration: TextDecoration.overline) will do the trick see this link for more information.
You can do with a shortcut just use a Stack and place both Text and a Divider Widget in it and gave then position according to your Requirements that's all.
That was a problem with fonts I have used, using another font it has been resolved.

how to add icon into text flutter?

i have a simple code
RaisedButton(
onPressed: () {
model.resetmodem();
},
child: Text(
'Size (also 24 pixels, not coincidentally, since both FlutterLogo and Icon honor the ambient IconTheme). This leaves some room left over, and now the row tells the text exactly how wide to be: the exact width of the remaining space. The text, now happy to comply to a reasonable request, wraps the text ',
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
color: Colors.blue,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
),
I want to add an icon in front of the text but I don't want to overflow the text
Use Row and put this text and icon inside it if it overflows you got to lower font sized or icon size or make your button bigger
You could you RichText along with InkWell like:
InkWell(
onTap: () {
//Your code here
},
child: RichText(
text: TextSpan(
text: 'Size (also 24 pixels, not coincidentally, since both FlutterLogo and Icon honor the ambient IconTheme). This leaves some room left over, and now the row tells the text exactly how wide to be: the exact width of the remaining space. The text, now happy to comply to a reasonable request, wraps the text ',
children: [
WidgetSpan(child: Icon(Icons.done)),
]),
),
)

Set spacing between two lines of text

I am trying to set spacing between two lines of text, but am not able to. Right now, the two lines are rendering after each other, but i want a bit of spacing between that i can adjust. I have tried using the Spacer widget but this makes the spacing too large. Is there a better way to do this?
Expanded(
child: Column(
children: <Widget>[
Text("We're finding your pizza.",
style: theme.textTheme.body1.copyWith(fontSize: 18)),
Text(
"We'll send you a notification.",
textAlign: TextAlign.center,
style: theme.textTheme.body1.copyWith(fontSize: 18)),
],
),
),
You can also set a specific padding between text lines by setting the height property in the TextStyle. With this you set the height for each line.
Text(
"Let's make\nsome pancakes",
style: TextStyle(
height: 1.2, //SETTING THIS CAN SOLVE YOUR PROBLEM
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w300,
),
textAlign: TextAlign.center,
),
In fact, we can confirm from the docs that:
For most fonts, setting height to 1.0 is not the same as omitting or setting height to null because the fontSize sets the height of the EM-square, which is different than the font provided metrics for line height.
For more info: https://api.flutter.dev/flutter/painting/TextStyle/height.html
I posted this same answer at Flutter how do I remove unwanted padding from Text widget? to get the opposite result but it works the same way.
Spacer will take up all the available spaces left, and you may not need this. So you can simply use SizedBox widget.
Text("One"),
SizedBox(height: 20), // use this
Text("Two"),
you can simply use the SizedBox widget or Container widget with padding.
SizedBox(height: 15.0)
or
Container(
padding: const EdgeInsets.all(15.0))