lesnitsky / flutter_localstorage

📦 LocalStorage for Flutter
MIT License
299 stars 65 forks source link

Simple string saving throws error that toJson() not found in String. #99

Closed zulkarnainshah closed 1 year ago

lesnitsky commented 1 year ago

Can't reproduce, the code below works as expected

import 'package:localstorage/localstorage.dart';

Future<void> main() async {
  final storage = LocalStorage('strings');
  await storage.ready;

  final firstLaunch = storage.getItem('firstLaunch') ?? true;

  if (firstLaunch) {
    await storage.setItem('firstLaunch', false);
    await storage.setItem('key', 'value');
  } else {
    print(storage.getItem('key'));
  }
}
zulkarnainshah commented 1 year ago

@lesnitsky If you keep the All Exceptions breakpoint checked in debugger, you will see the error. Attaching screenshot of the error when caught at runtime. The passed value selectedDateFilter.value is a string in the screenshot. Screenshot 2023-04-07 at 7 12 34 AM

lesnitsky commented 1 year ago

All exceptions shows even properly handled ones, this is the case, see here

zulkarnainshah commented 1 year ago

So are we doing anything wrong? Is there a way to fix?

lesnitsky commented 1 year ago

There's nothing wrong in throwing an exception and handling it in catch. The string you're trying to save is actually there and you should be able to read it back with getItem