mirror of
https://github.com/DefinedNet/mobile_nebula.git
synced 2025-02-12 15:05:29 +00:00
32 lines
851 B
Dart
32 lines
851 B
Dart
|
import 'dart:io';
|
||
|
|
||
|
import 'package:flutter/widgets.dart';
|
||
|
import 'package:mobile_nebula/services/result.dart';
|
||
|
|
||
|
class LogsNotFoundException implements Exception {
|
||
|
String error() => 'No logs found. Logs will be available after starting the site for the first time.';
|
||
|
}
|
||
|
|
||
|
class LogsNotifier extends ChangeNotifier {
|
||
|
Result<String>? logsResult;
|
||
|
|
||
|
LogsNotifier();
|
||
|
|
||
|
loadLogs({required String logFile}) async {
|
||
|
final file = File(logFile);
|
||
|
try {
|
||
|
logsResult = Result.ok(await file.readAsString());
|
||
|
notifyListeners();
|
||
|
} on FileSystemException {
|
||
|
logsResult = Result.error(LogsNotFoundException());
|
||
|
notifyListeners();
|
||
|
} on Exception catch (err) {
|
||
|
logsResult = Result.error(err);
|
||
|
notifyListeners();
|
||
|
} catch (err) {
|
||
|
logsResult = Result.error(Exception(err));
|
||
|
notifyListeners();
|
||
|
}
|
||
|
}
|
||
|
}
|