Basically all Material Design Widget have a default minimum padding, as per their documentation.
Is there a way to remove this padding ? For example, a TextFormField while have its label very close to its content, but I haven't found a way to do the same for a DropDownButton, which is annoying since it break the pattern in a form having TextFormFields and DropDownButtons in it.
Many thanks.
Edit :
This question provides the widget I need, which doesn't seem to be well known : DropdownButtonFormField. It adds components like a label, which answers my immediate need.
Are you looking for this ?
TextField(
decoration:InputDecoration(
contentPadding: const EdgeInsets.all(0.0),
isDense:true,
),
EdgeInsetsGeometry contentPadding : The padding for the input decoration's container. [...]
bool isDense : Whether the InputDecorator.child is part of a dense form (i.e., uses less vertical space). default is false
Related
I am using CheckboxListTile. I just want to increase the size of the Checkbox, without affecting the size of overall CheckboxListTile. If it were Checkbox only widget, I would have used Transform.scale to increase the widget size.
Is it possible to achieve what I want? Or i would have to use Checkbox?
Thanks
As mentioned here (https://api.flutter.dev/flutter/material/CheckboxListTile-class.html#instance-properties) there is no any property or method provided by CheckboxListTile to control size of Checkbox. So, having a custom tile with checkbox makes more sense here.
Something like in code below:
Row(
children: [
Transform.scale(
scale: 1.5,
child: Checkbox(value: mail, onChanged: (value) {}),
),
Text(
"Check Me",
)
],
),
Also wrapping the row in Inkwell with onTap changing state similar to that of onChanged in Checkbox will have almost same experience as CheckboxListTile where tapping on any part of tile checks or unchecks the box.
You can even use a ListTile with a CheckBox. The source code for CheckboxListTile (https://github.com/flutter/flutter/blob/52b3dc25f6/packages/flutter/lib/src/material/checkbox_list_tile.dart#L124) exactly does that. Be sure to use on tap with handlechange as done in the source to get the effect of value change on tapping anywhere in the tile.
I am creating a Flutter app and I want to add horizontal padding to ONLY the labelText, not the hintText and the input text, in the TextFormField. I was using contentPadding but it adds padding to everything in the TextFormField. I tried looking for a solution but could not find anything.
I want something like this in the picture, so that the labelText has extra padding on the left as compared to the input text.
contentPadding: const EdgeInsets.left(40.0),
I'm using Semantics to adapt my app for accessibility and want to read a phone number (like: Text("950874123")) one to one instead "million, thousand...". Is there any way to do it?
I see this was asked a while back, but I ran into the same problem. I'm adding my solution here to help out the next guy.
I got the solution with the help of this page:
https://medium.com/theotherdev-s/mastering-flutter-semantics-672440bc8bc8
Basically, my solution is to use the Semantics label (that I can control) and use ExcludeSemantics to exclude the text that I'm reading. In the label, I divide everything up into an array that I convert into a string. This makes the screen reader see everything as individual numbers.
Here's an example
Semantics(
label: numberString.split("").toString(),
child: ExcludeSemantics(
excluding: true,
child: Text(numberString),
)
)
*Edit:
After playing around more with the code, I realized that the Text field has a property called "semanticsLabel" where you can do the same thing. I left the above example since it can be used for other widget types, not just Text()
This is what the code would look like:
Semantics(
child: Text(
viewModel.confirmationId,
semanticsLabel:numberString.split("").toString(),
)
)
(additionally, the parent 'Semantics' widget probably isn't needed. The label will work directly with the Text widget)
How can I shrink a TextFormField to fit only the text inside it and its associated prefix/suffix icons?
I'm trying to display a prefix (dollar) icon next to my number input. I want the field to align the the right of the screen. My TextFormField is inside a row:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('TITLE'),
Expanded(
TextFormField(
textAlign: TextAlign.end,
decoration: InputDecoration(
prefixText: '\$',
),
...
),
),
],
),
While this displays the numbers to the right, the TextFormField is expanding to fill all available space, and putting the prefix text on the left:
TITLE$_____________1000
I would like to add a spacer between the title and the form field, and let the form field occupy only the space needed to show its numbers:
TITLE<----spacer---->$1000
My attempts so far have only resulted in the spacer sharing spacing with the form field:
TITLE<--spacer-->$____1000
I want to style the prefix text differently than the field text, so I can't use an inputFormatter to add my prefix. There doesn't seem to be any way to tell the form field to draw the prefix text next to the field text. I suspect my issue with the prefix text is related to this bug: https://github.com/flutter/flutter/issues/18788
If there's a way to tell the form field to occupy the minimum amount of space needed, I can work around the prefix text bug.
I don't think you can shrink a TextFormField to fit only the text inside. Not easily anyway. I don't have the answer but maybe some pointers could also help ya.
First: you'd have to know what font you are using and calculate how long the text would be if you rendered it on the screen with the exact same font style as the input's. Once you have that, in theory, it should be possible to programmatically calculate the width of the input field.
Flutter uses RenderObject's to keep track of sizes. In fact, RenderBox is a child class of RenderObject. You can retrieve them by via GlobalKey.
If I remember correctly the API:
final gk = GlobalKey();
RenderBox box = gk.currentContext.findRenderObject();
Curious what solution you'll find. If you figure this out, please drop a response :)
The InputDecoration comes with a predetermined contentPadding and if I want to just move the contents of the InputDecoration a little bit to the left, I will have to override internal contentPadding.
Is it there a way for me to find out what's the value of an InputDecoration contentPadding? I tried the Flutter Inspector, but I can't see anything there at all.
You can always Check file source for values - input_decorator.dart