Added DropDown for Relapse
parent
a2ed17fd5c
commit
63fdda8195
|
@ -1,20 +1,21 @@
|
||||||
import 'package:smoke_cess_app/interface/db_record.dart';
|
import 'package:smoke_cess_app/interface/db_record.dart';
|
||||||
|
|
||||||
class Relapse implements DatabaseRecord {
|
class Relapse implements DatabaseRecord {
|
||||||
|
final String _category;
|
||||||
final String _comment;
|
final String _comment;
|
||||||
final DateTime _date;
|
final DateTime _date;
|
||||||
|
|
||||||
Relapse(this._comment, this._date);
|
Relapse(this._category, this._comment, this._date);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
factory Relapse.fromDatabase(Map<String, dynamic> map) {
|
factory Relapse.fromDatabase(Map<String, dynamic> map) {
|
||||||
DateTime date = DateTime.parse(map['date']);
|
DateTime date = DateTime.parse(map['date']);
|
||||||
return Relapse(map['comment'], date);
|
return Relapse(map['_category'], map['comment'], date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toCSV() {
|
String toCSV() {
|
||||||
return "${_date.toIso8601String()}, {_wokeUpAt.minute}, $_comment";
|
return "${_date.toIso8601String()}, $_category, $_comment";
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -1,5 +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/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/sleep.dart';
|
||||||
import '../globals.dart' as globals;
|
import '../globals.dart' as globals;
|
||||||
|
|
||||||
|
@ -10,15 +11,22 @@ class InputProvider extends ChangeNotifier {
|
||||||
'wokeUpAt': const TimeOfDay(hour: 8, minute: 0),
|
'wokeUpAt': const TimeOfDay(hour: 8, minute: 0),
|
||||||
'sleptAt': const TimeOfDay(hour: 22, minute: 0),
|
'sleptAt': const TimeOfDay(hour: 22, minute: 0),
|
||||||
};
|
};
|
||||||
|
String _relapseCategory = '';
|
||||||
|
|
||||||
double get sliderValue => _sliderValue;
|
double get sliderValue => _sliderValue;
|
||||||
TextEditingController get textController => _textController;
|
TextEditingController get textController => _textController;
|
||||||
|
String get relapseCategory => _relapseCategory;
|
||||||
|
|
||||||
set sliderValue(double newValue) {
|
set sliderValue(double newValue) {
|
||||||
_sliderValue = newValue;
|
_sliderValue = newValue;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set relapseCategory(String newValue) {
|
||||||
|
_relapseCategory = newValue;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
TimeOfDay getTimeEntry(String key) {
|
TimeOfDay getTimeEntry(String key) {
|
||||||
return _times[key] ?? const TimeOfDay(hour: 12, minute: 0);
|
return _times[key] ?? const TimeOfDay(hour: 12, minute: 0);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +51,13 @@ class InputProvider extends ChangeNotifier {
|
||||||
_resetFields();
|
_resetFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveRelapse() {
|
||||||
|
Relapse relapse =
|
||||||
|
Relapse(_relapseCategory, _textController.text, DateTime.now());
|
||||||
|
globals.databaseService.addRelapse(relapse);
|
||||||
|
_resetFields();
|
||||||
|
}
|
||||||
|
|
||||||
void saveSleep(String wokeUpKey, String sleptKey) {
|
void saveSleep(String wokeUpKey, String sleptKey) {
|
||||||
Sleep sleep = Sleep(_sliderValue.toInt(), _textController.text,
|
Sleep sleep = Sleep(_sliderValue.toInt(), _textController.text,
|
||||||
DateTime.now(), getTimeEntry(sleptKey), getTimeEntry(wokeUpKey));
|
DateTime.now(), getTimeEntry(sleptKey), getTimeEntry(wokeUpKey));
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../providers/input_provider.dart';
|
||||||
|
import '../providers/settings_provider.dart';
|
||||||
|
|
||||||
|
class DropDown extends StatelessWidget {
|
||||||
|
const DropDown({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var inputModel = context.watch<InputProvider>();
|
||||||
|
var settings = context.watch<SettingsProvider>();
|
||||||
|
return DropdownButtonFormField<String>(
|
||||||
|
value: settings.settings?.relapseCategories?[0] ?? '',
|
||||||
|
icon: const Icon(Icons.arrow_downward),
|
||||||
|
elevation: 16,
|
||||||
|
style: const TextStyle(color: Colors.deepPurple),
|
||||||
|
onChanged: (String? value) {
|
||||||
|
inputModel.relapseCategory = value ?? '';
|
||||||
|
},
|
||||||
|
items: settings.settings?.relapseCategories
|
||||||
|
?.map<DropdownMenuItem<String>>((String value) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: value,
|
||||||
|
child: Text(value),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
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/widgets/drop_down.dart';
|
||||||
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
import 'package:smoke_cess_app/widgets/text_formfield.dart';
|
||||||
|
|
||||||
import '../providers/input_provider.dart';
|
import '../providers/input_provider.dart';
|
||||||
|
@ -14,6 +15,10 @@ class RelapseForm extends StatelessWidget {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
const ElevatedCard(
|
||||||
|
title: 'Rückfallkategorie',
|
||||||
|
child: DropDown(),
|
||||||
|
),
|
||||||
const ElevatedCard(
|
const ElevatedCard(
|
||||||
title: 'Beschreibe deinen Rückfall',
|
title: 'Beschreibe deinen Rückfall',
|
||||||
child: MyTextFormField('Beschreibe deinen Rückfall'),
|
child: MyTextFormField('Beschreibe deinen Rückfall'),
|
||||||
|
@ -22,7 +27,7 @@ class RelapseForm extends StatelessWidget {
|
||||||
height: 80,
|
height: 80,
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {},
|
onPressed: () => inputModel.saveRelapse(),
|
||||||
child: const Text('Speichern'),
|
child: const Text('Speichern'),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue