I'm trying to display a dialogue box when user select Other
from dropdown
, dialogue is displaying but this error also comes up.
Error:
type 'Future<bool?>' is not a subtype of type 'Widget'
Code:
here is my dialogue code
showAlertWithSingleTextField(
context, desc, title, labelText, controller, btnText, onPressButton) {
return Alert(
context: context,
title: title,
desc: desc,
content: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: labelText,
),
controller: controller,
),
],
),
buttons: [
DialogButton(
onPressed: onPressButton,
child: Text(btnText,
style: TextStyle(
fontFamily: 'montserrat', color: Colors.white, fontSize: 18)),
),
]).show();
}
and here is dropdown code
bool _newCatgoryFlag = false;
//here i'm calling dialogue box on the basis of condtion
addcatgerorytextfield(context) {
if (_newCatgoryFlag == true) {
SizedBox10();
print("run if");
return showAlertWithSingleTextField(
context,
"Please write your business category here",
"Add Category",
"Add Category",
newCategory,
"Add Category",
() {});
}
else {
return Padding(
padding: const EdgeInsets.only(left: 70),
child:
Row(crossAxisAlignment: CrossAxisAlignment.center, children: []));
}}
Widget build(BuildContext context) {
final color = HexColor("#7367f0");
return SafeArea(
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(children: [
dropdownCustom(
context,
"Category",
_selectedCategory,
(newValue) {
setState(() {
this._selectedCategory = newValue.toString();
if (this._selectedCategory == "Other") {
_newCatgoryFlag = true;
} else {
_newCatgoryFlag = false;
}
});
},
categorylist.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value,
style: GoogleFonts.montserrat(
color: HexColor("#6e6b7b"),
)));
}).toList(),
MediaQuery.of(context).size.width * 0.9,
MediaQuery.of(context).size.width * 0.9,
),
SizedBox10(),
addcatgerorytextfield(context),
}
please help how to fix it.
CodePudding user response:
You added Alert widget return Future<bool?> value to Column widget's children.
So you need to move 'showAlertWithSingleTextField' method calling where user select Other from dropdown place.
Column(
children: [
...
addcatgerorytextfield(context),
...
addcatgerorytextfield(context) {
...
return showAlertWithSingleTextField(
...
showAlertWithSingleTextField(
context, desc, title, labelText, controller, btnText, onPressButton) {
return Alert(
...