类型 'Future<bool?>' 不是类型 'Widget' 的子类型

type 'Future<bool?>' is not a subtype of type 'Widget'

当来自 dropdown 的用户 select Other 时,我正在尝试显示一个对话框,对话正在显示,但也会出现此错误。

错误:

type 'Future<bool?>' is not a subtype of type 'Widget'

代码:

这是我的对话代码

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();
}

这里是下拉代码

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),  
}

请帮忙解决一下。

您已将警报小部件 return Future 值添加到列小部件的子项。

因此您需要将 'showAlertWithSingleTextField' 方法调用从下拉列表位置移到用户 select 其他位置。

Column(
   children: [
       ...
       addcatgerorytextfield(context), 
...
addcatgerorytextfield(context) {
   ...
   return showAlertWithSingleTextField(
   ...

showAlertWithSingleTextField(
    context, desc, title, labelText, controller, btnText, onPressButton) {
  return Alert(
      ...