This is my code, I want to store JSON API into SharedPreferences and validate if SharedPreferences doesn't have my JSON API data or has different data from request API and that SharedPreferences data then my app will store new data from API to SharedPreference. Can anyone help me resolve my problem code or have some different logic code that works?
var localDataYoutube;class _TabYoutubeState extends State<TabYoutube> { var dataYoutube; late SharedPreferences pref; _dataCheck() async { var response = await http.get(Uri.parse(YOUTUBE_API_URL_2)); dataYoutube = json.decode(response.body)['items']; if (localDataYoutube == null || localDataYoutube != dataYoutube) { pref.setString("prefDataYoutube", jsonEncode(dataYoutube)); localDataYoutube = pref.getString('prefDataYoutube'); } } @override void initState() { super.initState(); _dataCheck(); } Future<List> getDataYoutube() async { pref = await SharedPreferences.getInstance(); localDataYoutube = pref.getString('prefDataYoutube'); return jsonDecode(localDataYoutube); }I successes in printing the JSON API data but I got this error log and blank on the Future Builder snapshot
Error: Assertion failed:org-dartlang-sdk:///lib/_engine/engine/canvaskit/surface_factory.dart:149:12_cache.contains(surface) is not true dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart294:49 throwdart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart35:3 assertFailedlib/_engine/engine/canvaskit/surface_factory.dart 149:35
isLive lib/_engine/engine/canvaskit/surface.dart 277:16
[_contextLostListener]dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart574:37 _checkAndCalldart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart579:39 dcall
I know this code will not effectively on dynamic data like YouTube data in my case because needs more validation from differences between local and updated online data, just take it as an example because for now I just want to know how to resolve this for another case. Thanks