2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import 'package:moody/utils/widgets/WhyWidget.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
|
2023-12-25 14:10:31 +01:00
|
|
|
import '../../utils/CirclePainter.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import '../../utils/definitions/ColorPairs.dart';
|
|
|
|
import '../../utils/definitions/style_guide.dart';
|
2023-12-25 14:10:31 +01:00
|
|
|
import '../../utils/logic/PreferencesService.dart';
|
|
|
|
import '../../utils/widgets/QuestionSliderWidget.dart';
|
|
|
|
|
2023-12-17 23:00:31 +01:00
|
|
|
class WritePage extends StatefulWidget {
|
2024-01-01 19:52:42 +01:00
|
|
|
final SliderChangeData sliderData;
|
2023-12-17 23:00:31 +01:00
|
|
|
|
2024-01-01 19:52:42 +01:00
|
|
|
const WritePage({Key? key, required this.sliderData}) : super(key: key);
|
2023-12-17 23:00:31 +01:00
|
|
|
@override
|
|
|
|
_WritePageState createState() => _WritePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WritePageState extends State<WritePage> {
|
2024-01-01 19:52:42 +01:00
|
|
|
SliderChangeData _sliderData = SliderChangeData(0, 0);
|
2024-01-08 19:34:48 +01:00
|
|
|
final bool _sliderChanged = true;
|
2023-12-25 14:10:31 +01:00
|
|
|
final PreferencesService _prefsService = PreferencesService();
|
2024-01-08 19:34:48 +01:00
|
|
|
final TextEditingController _textController = TextEditingController(text: "warum? ");
|
|
|
|
Color backgroundColor = Colors.lightGreenAccent;
|
|
|
|
Color textColor = Colors.black;
|
2023-12-25 14:10:31 +01:00
|
|
|
|
2023-12-17 23:00:31 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-01-01 19:52:42 +01:00
|
|
|
_sliderData = widget.sliderData; // Set the value here
|
2024-01-08 19:34:48 +01:00
|
|
|
_loadColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _loadColor() async {
|
|
|
|
ColorPair colorPair = await PreferencesService().loadColorPair();
|
|
|
|
setState(() {
|
|
|
|
backgroundColor = colorPair.backgroundColor;
|
|
|
|
textColor = colorPair.textColor;
|
|
|
|
});
|
2023-12-17 23:00:31 +01:00
|
|
|
}
|
|
|
|
|
2023-12-25 14:10:31 +01:00
|
|
|
void _saveEntry() async {
|
|
|
|
// Create a DiaryEntry object from the input
|
|
|
|
try {
|
2024-01-08 19:34:48 +01:00
|
|
|
List<String> texts = _textController.text.isEmpty ? [] : [_textController.text];
|
|
|
|
print("DerText:${_textController.text}");
|
2023-12-25 14:10:31 +01:00
|
|
|
DiaryEntry entry = DiaryEntry(
|
|
|
|
date: DateTime.now(), // or some date picker value
|
2024-01-01 19:52:42 +01:00
|
|
|
percentValue: _sliderData.value.toInt(),
|
2023-12-25 14:10:31 +01:00
|
|
|
texts: texts,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Save the entry using PreferencesService
|
|
|
|
await _prefsService.saveDiaryEntry(entry);
|
|
|
|
// Handle successful save here, maybe show a snackbar or navigate away
|
|
|
|
} catch (e) {
|
|
|
|
// Handle any errors here, such as invalid percent value or failed save
|
2024-01-08 19:34:48 +01:00
|
|
|
print("Error saving entry: $e"); // Consider showing an error dialog or toast instead
|
2023-12-25 14:10:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-17 23:00:31 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
2024-01-08 19:34:48 +01:00
|
|
|
backgroundColor: AppStyle.backgroundColor,
|
2023-12-17 23:00:31 +01:00
|
|
|
body: SafeArea(
|
2024-01-08 19:34:48 +01:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
// Background circle
|
|
|
|
Positioned.fill(
|
|
|
|
top: 15,
|
|
|
|
left: _sliderData.position - 40,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter: CirclePainter(_sliderData.value, backgroundColor),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
// Main content
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
|
2023-12-17 23:00:31 +01:00
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
// padding: const EdgeInsets.all(25.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
QuestionSliderWidget(
|
|
|
|
onSliderPositionChanged: (value) {},
|
|
|
|
sliderColor: textColor,
|
|
|
|
date: DateTime.now(),
|
|
|
|
questionText: "",
|
|
|
|
initialSliderValue: _sliderData.value,
|
|
|
|
isSliderEnabled: true,
|
|
|
|
onSliderChanged: (value) {
|
|
|
|
_sliderData = value;
|
|
|
|
setState(() {
|
|
|
|
// _sliderValue = value;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
context.go('/write', extra: _sliderData);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(25, 0, 25, 25),
|
|
|
|
child: WhyWidget(controller: _textController),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
],
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
// Skip/Save button
|
|
|
|
Positioned(
|
|
|
|
bottom: 20,
|
|
|
|
right: 20,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
_saveEntry();
|
|
|
|
context.go("/home");
|
|
|
|
},
|
|
|
|
child: Text(_sliderChanged ? "Save" : "Skip", style: TextStyle(color: textColor, fontSize: 16)),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
],
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|