readStringLocally method
Reads the saved JSON string from local storage.
Returns:
- JSON string if file exists
- null if file does not exist
Implementation
Future<String?> readStringLocally() async {
final file = File('local_data.txt');
// If no saved state exists, return null (first-time run)
if (!await file.exists()) {
debugPrint('No saved data found.');
return null;
}
// Read entire file contents
final contents = await file.readAsString();
return contents;
}