how I can change the distance between text and tile - flutter

So I have two SwitchListTiles on my modal Page, and the problem is that the text doesn't fit into it. (it takes 3 lines, but should 1)
How can I make it to be in one single line, without decreasing it's font size
child: SwitchListTile(
value: state.filter.flagId == null ? false : true,
onChanged: (newValue) =>
context.read<FilterBloc>().add(HotPressed(newValue)),
title: Text(
AppLocalizations.of(context)!.hotAdds.capitalize(),
style: FlutterFlowTheme.dark50016.copyWith(),
),
tileColor: FlutterFlowTheme.white,
activeColor: FlutterFlowTheme.primaryColor,
dense: true,
controlAffinity: ListTileControlAffinity.trailing,
),
I was thinking that the possible answer could be to decrease the distance between tile, but don't know how to do it

Just add "maxLines: 1" to Text widget
title: Text(
AppLocalizations.of(context)!.hotAdds.capitalize(),
style: FlutterFlowTheme.dark50016.copyWith(),
maxLines: 1,
),

There is default padding on the outer edges and also between the text and the switch. From what I can see the outer padding (the padding to the right of the switch and to the left of the text) defaults to 16. You can change this by adding contentPadding as an input to SwitchListTile and set the value to something smaller than 16:
contentPadding: EdgeInsets.symmetric(horizontal: 5),
But I'm not sure if you can change the padding between the text and the switch.

wrap your text widget to Flexible and trim() your text to avoid enter(\n) as string. maxLines =1.
title: Flexible(
child: Text(
AppLocalizations.of(context)!.hotAdds.capitalize().trim(),
style: FlutterFlowTheme.dark50016.copyWith(),
maxLines: 1,
),
),

Related

Flutter RadioListTile Radio(icon) Size

After searching and several attempts, I did not find a way to increase the RadioListTile Radio(icon) Size in width, height and thickness
Is there a way to do that?
you could use the dense property like this:
RadioListTile(
dense: false, // Set to true for a smaller widget
contentPadding: EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0), // Increase or decrease the padding as needed
title: Text('RadioListTile'),
value: 1,
groupValue: 1,
onChanged: (value) {},
);
You can use ListTile instead of RadioListTile for increase size of Radio button as below code
ListTile(
leading: Transform.scale(
scale: 1.5,
child: Radio(
value: false,
groupValue: 0,
onChanged: (value) {},
),
),
title: Text('RadioListTile'),
),
Otherwise you have to make custom Radio button as per your requirement

Flutter – CheckboxListTile - Override title style

In a CheckboxListTile, when we check the tile, the check box and the title change their color. What I need to achieve is to split the behavior and keep my title widget with the default color.
In this example, I'm trying to replace the title color but the default behavior is still in place and change the title color the same way as the checked icon:
https://dartpad.dev/?id=7f55df6ce3ba094cfe1db680ccc4b400
The only way I found to achieve the goal is to set directly in the widget the color.
Text(
'Select Example',
style: TextStyle(color: Colors.red),
)
I know I can do a custom item do reach this objective but my question is if possible to override the title widget color when the tile is selected in the CheckboxListTile Flutter widget?
Thanks for reading!
Its also weird for me that there are no separate properties for checkbox and text theme, but this is how you can achieve it.
return CheckboxListTile(
title: DefaultTextStyle(
style: const TextStyle(color: Colors.white),
child: widget.child,
),
tileColor: Colors.black,
selectedTileColor: Colors.black,
selected: isSelected,
dense: true,
value: isSelected,
onChanged: (v) => setState(() => isSelected = !isSelected),
controlAffinity: ListTileControlAffinity.leading,
);

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)),
]),
),
)

Reduce space between checkbox and title in flutter

I need to remove the space between checkbox and title but i cant able to reduce the space
here is my code
Expanded(
//width: 30,
child: CheckboxListTile(
checkColor: Colors.white,
activeColor: PRIMARY_COLOR,
title: Text('Select All',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.black)),
value: _selectAll,
dense: true,
contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool value) {
}
}
setState(() {});
}),
),
here is the image how it is coming
How to reduce the space
You need to create a custom widget in order to resolve your problem, because if you're using the CheckboxListTile the way it is, you're gonna have to add more contentPadding to your widget in order to make the gap smaller and by default, I see that it has a default padding between the actual checkbox and the text widget ... I personally, don't know why you're trying to squeeze more space from this thing, because in documentation it says clearly that CheckboxListTile acts just like a ListTile, which in my knowledge it takes all the space available in a row and the padding between items in your widget will be a little bit bigger. Also your widget is wrapped in an Expanded widget which also take the whole space available. So in conclusion you either use it as the way it is intended, or you can create a custom widget that will bennefit your problems.

How to set Flutter text max length value?

I am using Flutter programming. I need to display a title and a button next to the title. If the text length is less button also should display next to the text. If text length is more i want to fix the text length as maximum 200px and need to show the button next to the title.
I am using the below code. And working fine with the less text length.
Problem is: If text length is more, then my button is moving out of screen. You can see the behaviour in the below attached image.
Row(
children: <Widget>[
Container(
child: RichText(
overflow: TextOverflow.ellipsis,
strutStyle: StrutStyle(fontSize: 12.0),
text: TextSpan(
style: TextStyle(color: Colors.white), text: model.title),
),
),
Text("My Button"),
],
)
You can put maximum characters
text.substring(0,150)
I think there's no maxLength property for RichText and Text widget. If you are using RichText class, you'll have maxLines property that can be used. I tried to recreated your case and wrapped RichText widget with Flexible widget that lets the child widget to use only the minimum available space. But I wasn't able to replicate the error you mentioned. The long text I used gets ellipsis and the button doesn't go out of the screen. Note that I also used maxLines property which if you set to 2, will wrap the long text in new line without moving away the button and the long text will be shown as ellipsis. Sample working code below:
body: Center(
child: Row(
children: <Widget>[
Container(
child: Flexible(
child: RichText(
maxLines: 2,
overflow: TextOverflow.ellipsis,
strutStyle: StrutStyle(fontSize: 12.0),
text: TextSpan(
style: TextStyle(color: Colors.white), text: 'I am using Flutter programming. I need to display a title and a button next to the title. If the text length is less button also should display next to the text. If text length is more i want to fix the text length as maximum 200px and need to show the button next to the title.'),
),
)
),
Text("My Button"),
],
)
)
If you set maxLines to 1, the long text will wrap in ellipsis.
Hope this helps.
String addressText = userAddress.address.toString();
if(addressText.length > 22)
addressText = addressText.substring(0,22);
You can check length and split string if exceeds max length.
you can use Expanded or give fixed width to container of rich text, like this with Expanded widget:-
Row(
children: <Widget>[
Expanded(
child: RichText(
overflow: TextOverflow.ellipsis,
strutStyle: StrutStyle(fontSize: 12.0),
text: TextSpan(
style: TextStyle(color: Colors.white), text: model.title),
),
),
Text("My Button"),
],
)