i am having problem in removing space between the expanded widgets which are inside a column this is my code for upto 4 expanded widgets there are 3 more i have tried many things it still does’nt work .
class XylophoneApp extends StatelessWidget {
const XylophoneApp({super.key});
void playsound(int num) {
final player = AudioPlayer();
player.play(AssetSource('note$num.wav'));
}
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: TextButton(
onPressed: () {
playsound(1);
},
child: Container(
color: Colors.red,
),
),
),
Expanded(
child: TextButton(
onPressed: () {
playsound(2);
},
child: Container(
color: Colors.orange,
),
),
),
Expanded(
child: TextButton(
onPressed: () {
playsound(3);
},
child: Container(
color: Colors.yellow,
),
),
],
),
),
));
}
}
I am gettingthis is my output
i want this is the output i want
2
Answers
The space in between appearing in your output is the padding/margin for
TextButton
widget.I am not sure why you are using
TextButton
,however to make aContainer
tappable you could user eitherGestureDetector
orInkWell
as below:Output:
The
TextButton
reason for the margin of the between on your elements. You could useInkwell
instead ofTextButton
to remove the gap between theColumn
widgets of your design. Thus you can get rid of problems in this way.