wip
parent
aabdaafadc
commit
de5815c71c
|
@ -1,3 +1,5 @@
|
||||||
abstract class DatabaseRecord {
|
abstract class DatabaseRecord {
|
||||||
String toCSV();
|
String toCSV();
|
||||||
|
Map<String, dynamic> toMap();
|
||||||
|
DatabaseRecord.fromMap(Map<String, dynamic> map);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:smoke_cess_app/pages/main_page.dart';
|
import 'package:smoke_cess_app/pages/main_page.dart';
|
||||||
|
|
||||||
void main() => runApp(const MyApp());
|
void main() async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
runApp(const MyApp());
|
||||||
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
const MyApp({super.key});
|
||||||
|
@ -10,6 +13,6 @@ class MyApp extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(title: _title, home: MyHomePage());
|
return const MaterialApp(title: _title, home: MyHomePage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,33 @@
|
||||||
import 'package:smoke_cess_app/interface/db_record.dart';
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
|
||||||
class HIITWorkout implements DatabaseRecord {
|
class HIITWorkout implements DatabaseRecord {
|
||||||
final Duration _workoutDuration;
|
Duration _workoutDuration;
|
||||||
final String _commentBefore;
|
String _commentBefore;
|
||||||
final String _commentAfter;
|
String _commentAfter;
|
||||||
final DateTime _workoutDate;
|
DateTime _workoutDate;
|
||||||
|
|
||||||
HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
|
HIITWorkout(this._workoutDuration, this._commentBefore, this._commentAfter,
|
||||||
this._workoutDate);
|
this._workoutDate);
|
||||||
|
|
||||||
|
/* @override
|
||||||
|
HIITWorkout.fromMap(Map<String, dynamic> map) {
|
||||||
|
_workoutDuration = map['_workoutDuration'];
|
||||||
|
_commentBefore = map['_commentBefore'];
|
||||||
|
_commentAfter = map['_commentAfter'];
|
||||||
|
_workoutDate = map['_workoutDate'];
|
||||||
|
} */
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toCSV() =>
|
String toCSV() =>
|
||||||
"${_workoutDate.toIso8601String()}, $_workoutDuration, $_commentBefore, $_commentAfter";
|
"${_workoutDate.toIso8601String()}, $_workoutDuration, $_commentBefore, $_commentAfter";
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'workoutDuration': _workoutDuration,
|
||||||
|
'commentBefore': _commentBefore,
|
||||||
|
'commentAfter': _commentAfter,
|
||||||
|
'workoutDate': _workoutDate,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,13 @@ class Mood implements DatabaseRecord {
|
||||||
String toCSV() {
|
String toCSV() {
|
||||||
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment";
|
return "${_date.toIso8601String()}, ${_moodValue.round().toString()}, $_comment";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'moodValue': _moodValue,
|
||||||
|
'comment': _comment,
|
||||||
|
'date': _date,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,15 @@ class Sleep implements DatabaseRecord {
|
||||||
String toCSV() {
|
String toCSV() {
|
||||||
return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment";
|
return "${_date.toIso8601String()}, ${_sleepQualityValue.round().toString()}, $_sleepedAt, $_wokeUpAt, $_comment";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'sleepQualityValue': _sleepQualityValue,
|
||||||
|
'comment': _comment,
|
||||||
|
'date': _date,
|
||||||
|
'sleepedAt': _sleepedAt,
|
||||||
|
'wokeUpAt': _wokeUpAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:path/path.dart';
|
||||||
|
import 'package:smoke_cess_app/models/mood.dart';
|
||||||
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
// ignore: depend_on_referenced_packages
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class DatabaseService {
|
||||||
|
DatabaseService._privateConstructor();
|
||||||
|
static final DatabaseService instance = DatabaseService._privateConstructor();
|
||||||
|
|
||||||
|
static Database? _database;
|
||||||
|
Future<Database> get database async => _database ??= await _initDatabase();
|
||||||
|
|
||||||
|
Future<Database> _initDatabase() async {
|
||||||
|
Directory documentsDirectory = await getApplicationDocumentsDirectory();
|
||||||
|
String path = join(documentsDirectory.path, 'database.db');
|
||||||
|
return await openDatabase(
|
||||||
|
path,
|
||||||
|
version: 1,
|
||||||
|
onCreate: _onCreate,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future _onCreate(Database db, int version) async {
|
||||||
|
await db.execute('''
|
||||||
|
CREATE TABLE mood(
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
value INTEGER,
|
||||||
|
date TEXT,
|
||||||
|
comment TEXT
|
||||||
|
)
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Mood>> getMoodRecords() async {
|
||||||
|
Database db = await instance.database;
|
||||||
|
var moodRecords = await db.query('mood');
|
||||||
|
List<Mood> moodList = moodRecords.isNotEmpty
|
||||||
|
? moodRecords.map((e) => Mood(1, 'comment', DateTime.now())).toList()
|
||||||
|
: [];
|
||||||
|
return moodList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> addMood(Mood mood) async {
|
||||||
|
Database db = await instance.database;
|
||||||
|
return await db.insert('mood', mood.toMap());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:smoke_cess_app/models/mood.dart';
|
||||||
|
import 'package:smoke_cess_app/service/database_service.dart';
|
||||||
import 'package:smoke_cess_app/widgets/slider.dart';
|
import 'package:smoke_cess_app/widgets/slider.dart';
|
||||||
import 'package:smoke_cess_app/widgets/submit_form_button.dart';
|
import 'package:smoke_cess_app/widgets/submit_form_button.dart';
|
||||||
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
||||||
|
@ -20,9 +22,9 @@ class _MoodFormState extends State<MoodForm> {
|
||||||
void submitForm() {
|
void submitForm() {
|
||||||
if (_moodFormKey.currentState!.validate()) {
|
if (_moodFormKey.currentState!.validate()) {
|
||||||
_moodFormKey.currentState?.save(); //call every onSave Method
|
_moodFormKey.currentState?.save(); //call every onSave Method
|
||||||
//TODO Businesslogik aufrufen!
|
Mood mood = Mood(slider.getSliderValue(), _textInput, DateTime.now());
|
||||||
print(_textInput);
|
print(mood.toCSV());
|
||||||
print(slider.getSliderValue());
|
DatabaseService.instance.addMood(mood);
|
||||||
_moodFormKey.currentState?.reset();
|
_moodFormKey.currentState?.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
pubspec.lock
27
pubspec.lock
|
@ -199,14 +199,14 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0"
|
version: "3.0.0"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.2"
|
version: "1.8.2"
|
||||||
path_provider:
|
path_provider:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: path_provider
|
name: path_provider
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
|
@ -329,6 +329,20 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.0"
|
version: "1.9.0"
|
||||||
|
sqflite:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sqflite
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.4+1"
|
||||||
|
sqflite_common:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: sqflite_common
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.4.2+2"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -350,6 +364,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.1"
|
version: "1.1.1"
|
||||||
|
synchronized:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: synchronized
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.1"
|
||||||
term_glyph:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -401,4 +422,4 @@ packages:
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.18.2 <3.0.0"
|
dart: ">=2.18.2 <3.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.3.0"
|
||||||
|
|
|
@ -3,7 +3,7 @@ description: A new Flutter project.
|
||||||
|
|
||||||
# The following line prevents the package from being accidentally published to
|
# The following line prevents the package from being accidentally published to
|
||||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
# The following defines the version and build number for your application.
|
# The following defines the version and build number for your application.
|
||||||
# A version number is three numbers separated by dots, like 1.2.43
|
# A version number is three numbers separated by dots, like 1.2.43
|
||||||
|
@ -20,7 +20,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
version: 1.0.0+1
|
version: 1.0.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.18.2 <3.0.0"
|
sdk: '>=2.18.2 <3.0.0'
|
||||||
|
|
||||||
# Dependencies specify other packages that your package needs in order to work.
|
# Dependencies specify other packages that your package needs in order to work.
|
||||||
# To automatically upgrade your package dependencies to the latest versions
|
# To automatically upgrade your package dependencies to the latest versions
|
||||||
|
@ -31,6 +31,9 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
sqflite:
|
||||||
|
path:
|
||||||
|
path_provider: ^2.0.12
|
||||||
|
|
||||||
# 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.
|
||||||
|
|
Loading…
Reference in New Issue