Merge branch 'feature/ZI-1/backend-mock' into 'main'
Feature/zi 1/backend mock See merge request Crondung/hsma_cpd!3main
commit
4b2e900bda
|
@ -0,0 +1,3 @@
|
||||||
|
abstract class DatabaseRecord {
|
||||||
|
String toCSV();
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
import 'package:smoke_cess_app/models/mood.dart';
|
||||||
|
import 'package:smoke_cess_app/models/sleep.dart';
|
||||||
|
|
||||||
|
class DatabaseMock {
|
||||||
|
final List<DatabaseRecord> _moodRecords = [];
|
||||||
|
final List<DatabaseRecord> _sleepRecords = [];
|
||||||
|
final List<DatabaseRecord> _workoutRecords = [];
|
||||||
|
|
||||||
|
void saveRecord(DatabaseRecord record) {
|
||||||
|
if (record is Mood) {
|
||||||
|
_moodRecords.add(record);
|
||||||
|
} else if (record is Sleep) {
|
||||||
|
_sleepRecords.add(record);
|
||||||
|
} else {
|
||||||
|
_workoutRecords.add(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DatabaseRecord> getMoodRecords() => _moodRecords;
|
||||||
|
List<DatabaseRecord> getSleepRecords() => _sleepRecords;
|
||||||
|
List<DatabaseRecord> getWorkoutRecords() => _workoutRecords;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
|
||||||
|
class HIITWorkout implements DatabaseRecord {
|
||||||
|
final Duration _workoutDuration;
|
||||||
|
final String _commentBefore;
|
||||||
|
final String _commentAfter;
|
||||||
|
final DateTime _workoutDate;
|
||||||
|
|
||||||
|
HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
|
||||||
|
this._workoutDate);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toCSV() =>
|
||||||
|
"${_workoutDate.toIso8601String()}, $_workoutDuration, $_commentBefore, $_commentAfter";
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
|
||||||
|
class Mood implements DatabaseRecord {
|
||||||
|
final double _moodValue;
|
||||||
|
final String _comment;
|
||||||
|
final DateTime _date;
|
||||||
|
|
||||||
|
Mood(this._moodValue, this._comment, this._date);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toCSV() {
|
||||||
|
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
|
||||||
|
class Sleep implements DatabaseRecord {
|
||||||
|
final double _sleepQualityValue;
|
||||||
|
final String _comment;
|
||||||
|
final DateTime _date;
|
||||||
|
final TimeOfDay _sleepedAt;
|
||||||
|
final TimeOfDay _wokeUpAt;
|
||||||
|
|
||||||
|
Sleep(this._sleepQualityValue, this._comment, this._date, this._sleepedAt,
|
||||||
|
this._wokeUpAt);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toCSV() {
|
||||||
|
return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment";
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:smoke_cess_app/service/settings_service.dart';
|
||||||
import 'package:smoke_cess_app/widgets/timer_button.dart';
|
import 'package:smoke_cess_app/widgets/timer_button.dart';
|
||||||
|
|
||||||
class StopWatchTimerPage extends StatefulWidget {
|
class StopWatchTimerPage extends StatefulWidget {
|
||||||
|
@ -10,15 +11,26 @@ class StopWatchTimerPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StopWatchTimerPageState extends State<StopWatchTimerPage> {
|
class StopWatchTimerPageState extends State<StopWatchTimerPage> {
|
||||||
static const countdownDuration = Duration(minutes: 1);
|
SettingsService settings = SettingsService();
|
||||||
Duration duration = countdownDuration;
|
Duration duration = const Duration(minutes: 1);
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
|
|
||||||
bool countDown = true;
|
bool countDown = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
setDurationWithSetting();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDurationWithSetting() {
|
||||||
|
settings.getIntSetting('workout_duration_minutes').then((workoutMinutes) =>
|
||||||
|
{setState(() => duration = Duration(minutes: workoutMinutes ?? 10))});
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
if (countDown) {
|
if (countDown) {
|
||||||
setState(() => duration = countdownDuration);
|
setDurationWithSetting();
|
||||||
} else {
|
} else {
|
||||||
setState(() => duration = const Duration());
|
setState(() => duration = const Duration());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
import 'package:smoke_cess_app/mock/db_mock.dart';
|
||||||
|
|
||||||
|
class QueryService {
|
||||||
|
final DatabaseMock _database;
|
||||||
|
|
||||||
|
QueryService(this._database);
|
||||||
|
|
||||||
|
void addRecord(DatabaseRecord record) => _database.saveRecord(record);
|
||||||
|
List<DatabaseRecord> getWorkoutRecords() => _database.getWorkoutRecords();
|
||||||
|
List<DatabaseRecord> getMoodRecords() => _database.getMoodRecords();
|
||||||
|
List<DatabaseRecord> getSleepRecords() => _database.getSleepRecords();
|
||||||
|
|
||||||
|
String recordsToCSV(List<DatabaseRecord> records) {
|
||||||
|
String csv = "";
|
||||||
|
for (DatabaseRecord record in records) {
|
||||||
|
csv += '${record.toCSV()}\n';
|
||||||
|
}
|
||||||
|
return csv;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class SettingsService {
|
||||||
|
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
SettingsService() {
|
||||||
|
setIntSetting('workout_duration_minutes', 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStringSetting(String settingKey, String settingValue) =>
|
||||||
|
_prefs.then((pref) => pref.setString(settingKey, settingValue));
|
||||||
|
|
||||||
|
Future<String?> getStringSetting(String settingKey) =>
|
||||||
|
_prefs.then((pref) => pref.getString(settingKey));
|
||||||
|
|
||||||
|
void setIntSetting(String settingKey, int settingValue) =>
|
||||||
|
_prefs.then((pref) => pref.setInt(settingKey, settingValue));
|
||||||
|
|
||||||
|
Future<int?> getIntSetting(String settingKey) =>
|
||||||
|
_prefs.then((pref) => pref.getInt(settingKey));
|
||||||
|
|
||||||
|
//Add other setters and getters if needed
|
||||||
|
//other possible SharedPreferences Types: Int, Bool, Double, StringList
|
||||||
|
//see https://pub.dev/packages/shared_preferences
|
||||||
|
}
|
132
pubspec.lock
132
pubspec.lock
|
@ -50,6 +50,20 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
|
ffi:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ffi
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
|
file:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: file
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.4"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -67,6 +81,18 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.4"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -102,6 +128,97 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.8.2"
|
||||||
|
path_provider_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_linux
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.8"
|
||||||
|
path_provider_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.5"
|
||||||
|
path_provider_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_windows
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
|
platform:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: platform
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.0"
|
||||||
|
plugin_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: plugin_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
|
process:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: process
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.2.4"
|
||||||
|
shared_preferences:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: shared_preferences
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.17"
|
||||||
|
shared_preferences_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_android
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.15"
|
||||||
|
shared_preferences_foundation:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_foundation
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
|
shared_preferences_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_linux
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
|
shared_preferences_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_platform_interface
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
|
shared_preferences_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_web
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.4"
|
||||||
|
shared_preferences_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_windows
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.3"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -156,5 +273,20 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.2"
|
version: "2.1.2"
|
||||||
|
win32:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.3"
|
||||||
|
xdg_directories:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xdg_directories
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.18.2 <3.0.0"
|
dart: ">=2.18.2 <3.0.0"
|
||||||
|
flutter: ">=3.0.0"
|
||||||
|
|
|
@ -32,10 +32,10 @@ dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
|
shared_preferences: ^2.0.17
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
@ -53,7 +53,6 @@ dev_dependencies:
|
||||||
|
|
||||||
# The following section is specific to Flutter packages.
|
# The following section is specific to Flutter packages.
|
||||||
flutter:
|
flutter:
|
||||||
|
|
||||||
# The following line ensures that the Material Icons font is
|
# The following line ensures that the Material Icons font is
|
||||||
# included with your application, so that you can use the icons in
|
# included with your application, so that you can use the icons in
|
||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
|
|
Loading…
Reference in New Issue