Merge branch 'main' into '34-taskprovider-hinzufugen'

# Conflicts:
#   lib/models/workout.dart
main
Kai Mannweiler 2023-03-02 19:02:32 +00:00
commit c3a74e50af
7 changed files with 64 additions and 19 deletions

View File

@ -1,4 +1,4 @@
image: cirrusci/flutter:latest
image: cirrusci/flutter:3.3.5
stages:
- analyze

View File

@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smoke_cess_app">
<!-- Required to fetch data from the internet. -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="smoke_cess_app"
android:name="${applicationName}"

View File

@ -11,8 +11,14 @@ class Workout implements DatabaseRecord {
@override
factory Workout.fromDatabase(Map<String, dynamic> map) {
return Workout(map['_workoutDuration'], map['_motivationBefore'],
map['_motivationAfter']);
return Workout(map['motivationBefore'], map['motivationAfter'],
DateTime.parse(map['workoutDate']));
}
@override
factory Workout.fromMap(Map<String, dynamic> map) {
return Workout(
map['motivationBefore'], map['motivationAfter'], map['workoutDate']);
}
@override
@ -24,7 +30,7 @@ class Workout implements DatabaseRecord {
return {
'motivationBefore': _motivationBefore,
'motivationAfter': _motivationAfter,
'workoutDate': _workoutDate,
'workoutDate': _workoutDate.toIso8601String(),
};
}
}

View File

@ -1,25 +1,18 @@
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/export_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/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();
moods;
sleeps;
relapses;
ExportService exportService = ExportService();
exportService.exportData();
}
void loadJSON(BuildContext context) async {

View File

@ -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;
}
}

View File

@ -192,7 +192,7 @@ packages:
source: hosted
version: "2.2.0"
http:
dependency: transitive
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"

View File

@ -36,15 +36,16 @@ dependencies:
path_provider: ^2.0.12
provider: ^6.0.5
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
shared_preferences: ^2.0.17
audioplayers: ^3.0.1
mobile_scanner: ^3.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:
flutter_test: