Skip to content

storing value at SharedPreference throwing "'_Map<Object?, Object?>' is not a subtype of type 'List<Object?>?' in type cast" exception #128560

@abdullah432

Description

@abdullah432

Is there an existing issue for this?

Steps to reproduce

I updated old app to latest flutter version, everything working fine but only setInt method is throwing exception and the error does not make any sense here.

Weird part is I commented out shared_preferences: ^2.1.2 and still able to use the SharedPreference without any error.

Note: Exception is getting thrown with all set methods but value is actually getting stored.

Expected results

Store value at SharePreference

Actual results

Not storing value at SharePreference

Code sample

Code sample
  void updateSelection(int id) async {
    try {
      final prefs = await SharedPreferences.getInstance();
      await prefs.setInt('selectedTextPos', id);
    } catch (e) {
      debugPrint('updateSelection ex: ${e.toString()}');
    }
  }

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
updateSelection ex: type '_Map<Object?, Object?>' is not a subtype of type 'List<Object?>?' in type cast

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.1, on macOS 13.0 22A8380 darwin-arm64, locale
    en-PK)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.78.2)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions