My flutter app is not showing a Dropdown field and a text field in release mode, but in debug everything seems fine, I have no idea why this is happening.
I'm using a dropdown_search package to show the dropdown field, and a CustomTextField package to show the text field.
here is my full code. (DropdownSearch) and (CustomTextField)
body: ListView(
shrinkWrap: true,
padding: const EdgeInsets.all(15.0),
children: <Widget>[
Expanded(
child: DropdownSearch<String>(
popupProps: const PopupProps.menu(
showSelectedItems: true,
),
items: [
'Option 1',
'Option 2',
'Option 3'
],
dropdownDecoratorProps: const DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
labelText: 'Choose',
hintText: 'Choose',
),
),
onChanged: print,
selectedItem: 'Option 1',
)),
SizedBox(
height: 20,
),
Expanded(
child: CustomTextField(
controller: num1controller,
showCancelIcon: true,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter Number',
hintText: 'Enter Number',
),
),
),
SizedBox(
height: 30,
),
ElevatedButton(
child: const Text('Calculate'),
onPressed: () {
setState(() {
double sum = double.tryParse(num1controller.text) ?? 1;
final sum1 = sum / calculation;
result = sum1.toStringAsFixed(3);
});
},
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
'Result',
style: TextStyle(fontSize: 20),
),
Container(
color: Colors.black12,
child: Text(
'$result',
style: Theme.of(context).textTheme.headline1!.copyWith(
fontSize: 25,
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.w600,
),
),
)
],
),
])
I have no idea why its happening
CodePudding user response:
It's because you are using Expanded
as child of a listview. Expanded
can only be used inside flex widgets like Column
and Row
. Your console should also be showing errors because of that, even in debug mode.
CodePudding user response:
As a solution, you can remove the expanded
from the parent of DropdownSearch
and Customtextfield
or wrap both expanded
in the row
widget.