fix scanner, try catch export

main
Julian Gegner 2023-03-06 18:39:36 +01:00
parent f04ddb40e1
commit d18231966c
4 changed files with 19 additions and 11 deletions

View File

@ -19,7 +19,7 @@ class Settings {
chessTime = json['chess_time'] != null
? TimeConfig.fromJson(json['chess_time'])
: null,
startedAt = DateTime.parse(json['startedAt']);
startedAt = DateTime.now();
}
class QueryConfig {

View File

@ -33,11 +33,17 @@ class ExportService {
Future<int> exportData() async {
Map<String, List<String>> body = await _loadRecords();
final response = await http.post(url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(body));
return response.statusCode >= 400 ? 0 : 1;
try {
final response = await http.post(url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(body));
return response.statusCode >= 400 ? 0 : 1;
} catch (e) {
// ignore: avoid_print
print(jsonEncode(body));
return 0;
}
}
}

View File

@ -49,7 +49,6 @@ Future<List<String>?> _getStringListSetting(String settingKey) =>
Future<void> loadSettingsFromLocalJSON() async {
Map<String, dynamic> configJSON = await loadLocalConfigJSON();
configJSON['startedAt'] = DateTime.now().toIso8601String();
Settings settings = Settings.fromJson(configJSON);
saveSettings(settings);
}
@ -63,7 +62,7 @@ void saveSettings(Settings settings) {
_setStringListSetting('sleep_query_days', settings.sleepQuery!.days!);
_setIntSetting('sleep_query_hours', settings.sleepQuery!.hours!);
_setIntSetting('sleep_query_minutes', settings.sleepQuery!.minutes!);
_setStringSetting('startedAt', DateTime.now().toIso8601String());
_setStringSetting('startedAt', settings.startedAt.toIso8601String());
if (settings.chessTime != null) {
_setIntSetting('chess_hours', settings.chessTime!.hours!);
_setIntSetting('chess_minutes', settings.chessTime!.minutes!);

View File

@ -16,7 +16,8 @@ class MyScanner extends StatelessWidget {
Widget build(BuildContext context) {
SettingsProvider settingsProvider = context.watch<SettingsProvider>();
void handleSucces(String? rawValue) {
void handleSuccess(String? rawValue) {
print('in Success: $rawValue');
String qrText = rawValue!;
Map<String, dynamic> json = stringToJSON(qrText);
Settings settings = Settings.fromJson(json);
@ -49,10 +50,12 @@ class MyScanner extends StatelessWidget {
final List<Barcode> barcodes = capture.barcodes;
for (final barcode in barcodes) {
if (barcode.rawValue != null) {
return handleSucces(barcode.rawValue);
print(barcode.rawValue);
return handleSuccess(barcode.rawValue);
}
}
} catch (e) {
print(e);
handleError();
}
}