[flutter] Exception: type 'List<>' is not a subtype of type 'List<>'

💜Dabo (개발자 다보)·2020년 4월 16일
1

Exception Message

Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<bool>'


E/flutter ( 5907): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<bool>'
  
E/flutter ( 5907): #0      Customers.getfirestore.<anonymous closure> 
package: ///.dart:35
E/flutter ( 5907): #1      _rootRunUnary  (dart:async/zone.dart:1134:38)
E/flutter ( 5907): #2      _CustomZone.runUnary  (dart:async/zone.dart:1031:19)
E/flutter ( 5907): #3      _CustomZone.runUnaryGuarded  (dart:async/zone.dart:933:7)


Solution

Before

List<bool> _checkboxSeleted;

  
  void initState() {
    super.initState();
    ...

    setState(() {
      _checkboxSeleted = [false, false, false];
	  _checkboxSeleted.addAll((widget._dataObj['key']));
	});
  }

After

add .cast<bool>()

List<bool> _checkboxSeleted;

  
  void initState() {
    super.initState();
    ...

    setState(() {
      _checkboxSeleted = [false, false, false];
	  _checkboxSeleted.addAll((widget._dataObj['key'].cast<bool>()));
	});
  }
profile
𝙸 𝚊𝚖 𝚊 𝚌𝚞𝚛𝚒𝚘𝚞𝚜 𝚍𝚎𝚟𝚎𝚕𝚘𝚙𝚎𝚛 𝚠𝚑𝚘 𝚎𝚗𝚓𝚘𝚢𝚜 𝚍𝚎𝚏𝚒𝚗𝚒𝚗𝚐 𝚊 𝚙𝚛𝚘𝚋𝚕𝚎𝚖. 🇰🇷👩🏻‍💻

2개의 댓글

comment-user-thumbnail
2020년 9월 28일

E/flutter ( 4425): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'List' is not a subtype of type 'FutureOr?' of 'value'

답글 달기
comment-user-thumbnail
2020년 12월 16일
답글 달기