I have a somewhat long label in a DropdownButtonFormField
and I need to show the entire text which overflows outside it's parent container.
How can I achieve that?
Container(
width: MediaQuery.of(context).size.width * 0.30,
child: new DropdownButtonFormField<String>(
decoration: InputDecoration(
labelText: ("Long Text here, which should overflow it's parent"),
// labelStyle: new TextStyle(
// overflow: TextOverflow.visible,
// ),
// label: TextField(
// //maxLines: 1,
// style: TextStyle(overflow: TextOverflow.visible,),
// decoration: InputDecoration.collapsed(
// hintText: ("Long Text here, which should overflow it's parent"),
// ),
// ),
// label: Text(
// ("Long Text here, which should overflow it's parent"),
// overflow: TextOverflow.visible,
// ),
),
isExpanded:true,
hint: Text("Select"),
items: _list.map((value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (value) {},
)
),
Solution 1: Increase the width of the Container to occupy a larger portion of the screen. You can do this by setting its width to a percentage of the screen width:
width: MediaQuery.of(context).size.width * 0.9,
Solution 2:
If you need multiple containers or elements within a Column, you can assign each element a specific width. Here's an example:
Container(
width: MediaQuery.of(context).size.width * 0.9,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Long Text here, which should overflow it\'s parent',
),
// SizedBox(height: 8),
Container(
width: MediaQuery.of(context).size.width *
0.30,
child:
new DropdownButtonFormField<String>(
decoration: InputDecoration(
// labelStyle: new TextStyle(
// overflow: TextOverflow.visible,
// ),
// label: TextField(
// //maxLines: 1,
// style: TextStyle(overflow: TextOverflow.visible,),
// decoration: InputDecoration.collapsed(
// hintText: ("[![Long Text here, which should overflow it's parent][1]][1]"),
// ),
// ),
// label: Text(
// ("Long Text here, which should overflow it's parent"),
// overflow: TextOverflow.visible,
// ),
),
isExpanded: true,
hint: Text("Select"),
items: _list.map((value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (value) {},
)),