【问题标题】:type 'Future<bool?>' is not a subtype of type 'Widget'type 'Future<bool?>' 不是 type 'Widget' 的子类型
【发布时间】:2021-11-19 06:17:12
【问题描述】:

当用户从dropdown 中选择Other 时,我正在尝试显示一个对话框,正在显示对话框但也会出现此错误。

错误:

type 'Future&lt;bool?&gt;' 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),  
}

请帮忙解决一下。

【问题讨论】:

    标签: flutter dialog future


    【解决方案1】:

    您向 Column 小部件的子级添加了 Alert 小部件 return Future 值。

    因此,您需要将“showAlertWithSingleTextField”方法调用移动到用户从下拉位置选择“其他”的位置。

    Column(
       children: [
           ...
           addcatgerorytextfield(context), 
    ...
    
    addcatgerorytextfield(context) {
       ...
       return showAlertWithSingleTextField(
       ...
    
    
    showAlertWithSingleTextField(
        context, desc, title, labelText, controller, btnText, onPressButton) {
      return Alert(
          ...
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2020-09-11
      • 2021-08-25
      • 2020-04-07
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多