Skip to content

Nullable fields in AccessToken cause runtime crash#144

Open
PhuCG wants to merge 1 commit intoline:masterfrom
PhuCG:fix/nullable-access-token-fields
Open

Nullable fields in AccessToken cause runtime crash#144
PhuCG wants to merge 1 commit intoline:masterfrom
PhuCG:fix/nullable-access-token-fields

Conversation

@PhuCG
Copy link
Copy Markdown

@PhuCG PhuCG commented Apr 3, 2026

Problem

AccessToken getters declared non-nullable return types (String, num, List<String>), but values come from a raw Map<String, dynamic>. If any key is missing or null in the server response, Dart throws a runtime exception when casting null to a non-nullable type.

Crash stack trace:

Null check operator used on a null value
#0  AccessToken.tokenType (package:flutter_line_sdk/src/model/access_token.dart:99:32)

Root Cause

// Before — crashes if 'token_type' key is absent
String get tokenType => _data['token_type'];

_data['token_type'] returns dynamic. At runtime, Dart implicitly casts it to String. If the value is null, it throws immediately.

Fix

Changed affected getters to return nullable types:

Getter Before After
value String String?
expiresIn num num?
scopes List<String> List<String>?
tokenType String String?
// After — safe
String? get tokenType => _data['token_type'];
List<String>? get scopes => (_data['scope'] as String?)?.split(' ');

Changes

  • lib/src/model/access_token.dart — updated getter return types
  • test/flutter_line_sdk_test.dart — updated assertions to use null-aware operators

…n, scopes, and tokenType; adjust tests accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant