Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
884 views
in Technique[技术] by (71.8m points)

firebase - Unhandled Exception: type 'bool' is not a subtype of type 'String'

I want to revise this title error.

Could you have any ideas for solving.

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

workout.dart

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

  String reportList;
  bool isDone = false;

enter image description here

I want to separate these components but now this List is collected

question from:https://stackoverflow.com/questions/65871261/unhandled-exception-type-bool-is-not-a-subtype-of-type-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

reportList is not a String, it is a List. If you pass a value to Text widget, a value must be String.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...