플러터 오류 – type ‘Null’ is not a subtype of type ‘String’ of ‘function result’

The following _TypeError was thrown while dispatching a pointer event:
type 'Null' is not a subtype of type 'String' of 'function result'

When the exception was thrown, this was the stack: 
#0      _Location.file (package:flutter/src/widgets/widget_inspector.dart)
#1      _Location.toJsonMap (package:flutter/src/widgets/widget_inspector.dart:2844:15)
#2      _Location.toJsonMap.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:2853:42)
#3      MappedListIterable.elementAt (dart:_internal/iterable.dart:412:31)
#4      ListIterator.moveNext (dart:_internal/iterable.dart:341:26)
...
Event: PointerUpEvent#d8ec4(position: Offset(329.1, 367.7))
  position: Offset(329.1, 367.7)
Target: <WidgetsFlutterBinding>

원인

final LocalStorage storage = new LocalStorage('dev_link_app');
var list = storage.getItem(WISH_KEY);

LocalStorage 객체의 getItem을 호출해서 받아온 값은 null인데 List<String> 형으로 강제 형번환하려다가 발생.

해결

final LocalStorage storage = new LocalStorage('dev_link_app');
var list = storage.getItem(WISH_KEY);

먼저 유동적인 var형으로 값을 받아오고 그것이 null일 경우 분기처리해줌.

평점

Leave a Comment