0

I am currently building an app where the user is able to store List items as favorites on their device. Debugging my app I am running in the following error:

Exception has occurred.
_CastError (type 'Null' is not a subtype of type 'Widget' in type cast)

This is my code:

LogEntry _$LogEntryFromJson(Map<String, dynamic> json) {
  return LogEntry(
      mechanismId: json['mechanismId'] as int?,
      timestamp: DateTime.parse(json['timestamp'] as String),
      navigation: json['navigation'] as Widget);
}

Map<String, dynamic> _$LogEntryToJson(LogEntry instance) => <String, dynamic>{
      'mechanismId': instance.mechanismId,
      'timestamp': instance.timestamp.toIso8601String(),
      'navigation:': instance.navigation,
    };

The mechanismID is the respective ID of a List item and the navigation stands for the route of the detail page.

1
  • 1
    'json['navigation'] ' is returning null, change cast to 'as Widget?' or make sure 'json['navigation'] ' cannot be null. Commented May 2, 2022 at 19:37

1 Answer 1

0
LogEntry _$LogEntryFromJson(Map<String, dynamic> json) {
  return LogEntry(
      mechanismId: json['mechanismId'] as int?,
      timestamp: DateTime.parse(json['timestamp'] as String),
      navigation: json['navigation'] as Widget?);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.