Merge branch '34-taskprovider-hinzufugen' of https://gitlab.com/Crondung/hsma_cpd into 34-taskprovider-hinzufugen
commit
24c1f8e21d
|
@ -1,4 +1,4 @@
|
||||||
image: cirrusci/flutter:latest
|
image: cirrusci/flutter:3.3.5
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- analyze
|
- analyze
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.smoke_cess_app">
|
package="com.example.smoke_cess_app">
|
||||||
|
<!-- Required to fetch data from the internet. -->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<application
|
<application
|
||||||
android:label="smoke_cess_app"
|
android:label="smoke_cess_app"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
|
|
|
@ -11,8 +11,14 @@ class Workout implements DatabaseRecord {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
factory Workout.fromDatabase(Map<String, dynamic> map) {
|
factory Workout.fromDatabase(Map<String, dynamic> map) {
|
||||||
return Workout(map['_workoutDuration'], map['_motivationBefore'],
|
return Workout(map['motivationBefore'], map['motivationAfter'],
|
||||||
map['_motivationAfter']);
|
DateTime.parse(map['workoutDate']));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
factory Workout.fromMap(Map<String, dynamic> map) {
|
||||||
|
return Workout(
|
||||||
|
map['motivationBefore'], map['motivationAfter'], map['workoutDate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -24,7 +30,7 @@ class Workout implements DatabaseRecord {
|
||||||
return {
|
return {
|
||||||
'motivationBefore': _motivationBefore,
|
'motivationBefore': _motivationBefore,
|
||||||
'motivationAfter': _motivationAfter,
|
'motivationAfter': _motivationAfter,
|
||||||
'workoutDate': _workoutDate,
|
'workoutDate': _workoutDate.toIso8601String(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
import 'package:awesome_dialog/awesome_dialog.dart';
|
import 'package:awesome_dialog/awesome_dialog.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:smoke_cess_app/models/mood.dart';
|
import 'package:smoke_cess_app/services/export_service.dart';
|
||||||
import 'package:smoke_cess_app/models/relapse.dart';
|
|
||||||
import 'package:smoke_cess_app/services/settings_service.dart';
|
import 'package:smoke_cess_app/services/settings_service.dart';
|
||||||
import 'package:smoke_cess_app/services/notification_service.dart';
|
import 'package:smoke_cess_app/services/notification_service.dart';
|
||||||
import 'package:smoke_cess_app/widgets/scanner.dart';
|
import 'package:smoke_cess_app/widgets/scanner.dart';
|
||||||
import '../models/sleep.dart';
|
|
||||||
import '../providers/settings_provider.dart';
|
import '../providers/settings_provider.dart';
|
||||||
import '../globals.dart' as globals;
|
|
||||||
|
|
||||||
class ScannerPage extends StatelessWidget {
|
class ScannerPage extends StatelessWidget {
|
||||||
const ScannerPage({super.key});
|
const ScannerPage({super.key});
|
||||||
|
|
||||||
void export() async {
|
void export() async {
|
||||||
List<Mood> moods = await globals.databaseService.getMoodRecords();
|
ExportService exportService = ExportService();
|
||||||
List<Sleep> sleeps = await globals.databaseService.getSleepRecords();
|
exportService.exportData();
|
||||||
List<Relapse> relapses = await globals.databaseService.getRelapseRecords();
|
|
||||||
moods;
|
|
||||||
sleeps;
|
|
||||||
relapses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadJSON(BuildContext context) async {
|
void loadJSON(BuildContext context) async {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:smoke_cess_app/models/mood.dart';
|
||||||
|
import 'package:smoke_cess_app/models/relapse.dart';
|
||||||
|
import 'package:smoke_cess_app/models/sleep.dart';
|
||||||
|
import 'package:smoke_cess_app/models/workout.dart';
|
||||||
|
import 'package:smoke_cess_app/services/database_service.dart';
|
||||||
|
import '../globals.dart' as globals;
|
||||||
|
|
||||||
|
class ExportService {
|
||||||
|
Uri url = Uri.parse('http://localhost:3000/data');
|
||||||
|
final DatabaseService _databaseService = globals.databaseService;
|
||||||
|
|
||||||
|
Future<Map<String, List<String>>> _loadRecords() async {
|
||||||
|
List<Mood> moodRecords = await _databaseService.getMoodRecords();
|
||||||
|
List<Sleep> sleepRecords = await _databaseService.getSleepRecords();
|
||||||
|
List<Relapse> relapseRecords = await _databaseService.getRelapseRecords();
|
||||||
|
List<Workout> workoutRecords = await _databaseService.getWorkoutRecords();
|
||||||
|
return {
|
||||||
|
'Stimmung':
|
||||||
|
moodRecords.map((Mood mood) => jsonEncode(mood.toMap())).toList(),
|
||||||
|
'Schlaf':
|
||||||
|
sleepRecords.map((Sleep sleep) => jsonEncode(sleep.toMap())).toList(),
|
||||||
|
'Rückfall': relapseRecords
|
||||||
|
.map((Relapse relapse) => jsonEncode(relapse.toMap()))
|
||||||
|
.toList(),
|
||||||
|
'Workout': workoutRecords
|
||||||
|
.map((Workout workout) => jsonEncode(workout.toMap()))
|
||||||
|
.toList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -192,7 +192,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.0"
|
version: "2.2.0"
|
||||||
http:
|
http:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: http
|
name: http
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
|
|
@ -36,15 +36,16 @@ dependencies:
|
||||||
path_provider: ^2.0.12
|
path_provider: ^2.0.12
|
||||||
provider: ^6.0.5
|
provider: ^6.0.5
|
||||||
awesome_dialog: ^3.0.2
|
awesome_dialog: ^3.0.2
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
|
||||||
cupertino_icons: ^1.0.2
|
|
||||||
timezone: ^0.9.0
|
timezone: ^0.9.0
|
||||||
shared_preferences: ^2.0.17
|
shared_preferences: ^2.0.17
|
||||||
audioplayers: ^3.0.1
|
audioplayers: ^3.0.1
|
||||||
mobile_scanner: ^3.0.0
|
mobile_scanner: ^3.0.0
|
||||||
flutter_local_notifications: ^13.0.0
|
flutter_local_notifications: ^13.0.0
|
||||||
|
http: ^0.13.5
|
||||||
|
|
||||||
|
# The following adds the Cupertino Icons font to your application.
|
||||||
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
cupertino_icons: ^1.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in New Issue