Creating a desktop app and the width of the text field is too log how to reduce the width of the textfield
body: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 20),
child: TextField(
controller: _firstNumberController,
keyboardType: TextInputType.number,
decoration:
const InputDecoration(labelText: 'First Number'),
),
),
const SizedBox(height: 20),
Padding(
padding: const EdgeInsets.only(left: 20),
child: TextField(
controller: _secondNumberController,
keyboardType: TextInputType.number,
decoration:
const InputDecoration(labelText: 'Second Number'),
),
),
],
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _calculateSum,
child: const Text('Calculate Sum'),
),
const SizedBox(height: 20),
Text(
'Sum: $_sum',
style: const TextStyle(fontSize: 24),
),
],
),
),
],
),
),
2
Answers
To adjust the width, you could use the width field in a SizedBox with the text field as a child.
Wrap the TextField widget in a
Container
orSizedBox
widget and set the width property of the container or the width property of the SizedBox.Example –