首页 > 解决方案 > 未处理的异常:类型“布尔”不是“字符串”类型的子类型

问题描述

我想修改这个标题错误。

你有什么解决办法吗。

主要.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;

在此处输入图像描述

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

标签: firebasefluttergoogle-cloud-firestoreflutter-layout

解决方案


reportList不是一个String,是一个List。如果将值传递给Text小部件,则值必须是String.


推荐阅读