未处理的异常:“bool”类型不是“String”类型的子类型

时间:2021-01-24 13:42:27

标签: firebase flutter google-cloud-firestore flutter-layout

我想修改这个标题错误。

你有什么解决办法吗。

main.dart

Padding(
                        padding: const EdgeInsets.only(top: 20),
                        child: Text(workout.reportList,
                            style: TextStyle(fontSize: 12)),
                      ),

main_model.dart

List<String> reportList = [
    "Not relevant",
    "Illegal",
    "Spam",
    "Offensive",
    "Uncivil"
  ];

Future add(model) async {
    final collection = FirebaseFirestore.instance.collection('workoutlist');
    await collection.add({
      'title': newWorkoutText,
      'count': int.parse(newWorkoutDigit),
      "category": reportList,
      'createdAt': Timestamp.now(),
    });

add_page.dart

List<String> reportList;
List<String> selectedChoices = List();

Container(
                  padding: const EdgeInsets.all(8.0),
                  child: ChoiceChip(
                    label: Text(model.reportList.toString()),
                    selected: isSelected,
                    selectedColor: Colors.teal,
                    onSelected: (selected) {
                      setState (() {
                        isSelected = selected;
                      });
                    },
                  ),

锻炼.dart

  Workout(DocumentSnapshot doc) {
    this.documentReference = doc.reference;
    this.reportList = doc.data()['category'].toString();
  }

  String reportList;
  bool isDone = false;

enter image description here

我想分离这些组件,但现在这个列表被收集了

1 个答案:

答案 0 :(得分:0)

reportList 不是 String,而是 List。如果您将值传递给 Text 小部件,则值必须为 String