69 lines
2.2 KiB
Dart
69 lines
2.2 KiB
Dart
import 'package:awesome_dialog/awesome_dialog.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:smoke_cess_app/models/mood.dart';
|
|
import 'package:smoke_cess_app/models/relapse.dart';
|
|
import 'package:smoke_cess_app/services/settings_service.dart';
|
|
import 'package:smoke_cess_app/services/notification_service.dart';
|
|
import 'package:smoke_cess_app/widgets/scanner.dart';
|
|
import '../models/sleep.dart';
|
|
import '../providers/settings_provider.dart';
|
|
import '../globals.dart' as globals;
|
|
|
|
class ScannerPage extends StatelessWidget {
|
|
const ScannerPage({super.key});
|
|
|
|
void export() async {
|
|
List<Mood> moods = await globals.databaseService.getMoodRecords();
|
|
List<Sleep> sleeps = await globals.databaseService.getSleepRecords();
|
|
List<Relapse> relapses = await globals.databaseService.getRelapseRecords();
|
|
for (Mood mood in moods) {
|
|
print(mood.toCSV());
|
|
}
|
|
for (Sleep sleep in sleeps) {
|
|
print(sleep.toCSV());
|
|
}
|
|
for (Relapse relapse in relapses) {
|
|
print(relapse.toCSV());
|
|
}
|
|
}
|
|
|
|
void loadJSON(BuildContext context) async {
|
|
var settingsModel = context.read<SettingsProvider>();
|
|
await loadSettingsFromLocalJSON();
|
|
settingsModel.initSettings();
|
|
NotificationService().setAllNotifications();
|
|
AwesomeDialog(
|
|
context: context,
|
|
dialogType: DialogType.success,
|
|
title: 'Geschafft',
|
|
desc: 'Die Einstellung wurden erfolgreich gespeichert',
|
|
).show();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const MyScanner(),
|
|
const SizedBox(height: 30),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
textStyle: const TextStyle(fontSize: 20)),
|
|
onPressed: () => loadJSON(context),
|
|
child: const Text('Read JSON'),
|
|
),
|
|
const SizedBox(height: 30),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
textStyle: const TextStyle(fontSize: 20)),
|
|
onPressed: export,
|
|
child: const Text('Export'),
|
|
)
|
|
],
|
|
));
|
|
}
|
|
}
|