import 'dart:io'; import 'package:manager_app/Models/session.dart'; import 'package:path_provider/path_provider.dart'; class SessionHelper { // TODO instance LOAD FILE.. Future get _localPath async { final directory = await getApplicationDocumentsDirectory(); return directory.path; } Future get _localFile async { final path = await _localPath; return File('$path/session.json'); } Future writeSession(Session session) async { final file = await _localFile; // Write the file return file.writeAsString(session.toString()); } Future readSession() async { try { final file = await _localFile; // Read the file final contents = await file.readAsString(); return int.parse(contents); } catch (e) { // If encountering an error, return 0 return 0; } } }