2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2023-12-25 14:10:31 +01:00
|
|
|
import 'package:moody/utils/widgets/QuestionSliderWidget.dart';
|
|
|
|
|
2024-01-01 18:31:10 +01:00
|
|
|
import '../../utils/CirclePainter.dart';
|
|
|
|
import '../../utils/definitions/ColorPairs.dart';
|
2023-12-25 14:10:31 +01:00
|
|
|
import '../../utils/logic/PreferencesService.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
class FirstPage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_FirstPageState createState() => _FirstPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FirstPageState extends State<FirstPage> {
|
2024-01-01 18:31:10 +01:00
|
|
|
SliderChangeData sliderData = SliderChangeData(0, 0);
|
2023-12-17 23:00:31 +01:00
|
|
|
bool _sliderChanged = false;
|
2023-12-25 14:10:31 +01:00
|
|
|
PreferencesService _prefsService = PreferencesService();
|
|
|
|
|
2024-01-01 18:31:10 +01:00
|
|
|
Color backgroundColor = Colors.lightGreenAccent;
|
|
|
|
Color textColor = Colors.black;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _loadColor() async {
|
|
|
|
ColorPair colorPair = await PreferencesService().loadColorPair();
|
|
|
|
setState(() {
|
|
|
|
backgroundColor = colorPair.backgroundColor;
|
|
|
|
textColor = colorPair.textColor;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-25 14:10:31 +01:00
|
|
|
void _saveEntry() async {
|
|
|
|
try {
|
|
|
|
List<String> texts = [];
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
|
|
|
await _prefsService.saveDiaryEntry(entry);
|
|
|
|
} catch (e) {
|
|
|
|
print(
|
|
|
|
"Error saving entry: $e"); // Consider showing an error dialog or toast instead
|
|
|
|
}
|
|
|
|
}
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-01-01 18:31:10 +01:00
|
|
|
return backgroundColor == Colors.lightGreenAccent
|
|
|
|
? CircularProgressIndicator() // Show loading indicator while color is null
|
|
|
|
: MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: SafeArea(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
// Background circle
|
|
|
|
Positioned.fill(
|
|
|
|
top: 15,
|
|
|
|
left: sliderData.position - 70,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter:
|
|
|
|
CirclePainter(sliderData.value, backgroundColor),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Main content
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
// Date
|
|
|
|
Stack(
|
|
|
|
children: [
|
|
|
|
QuestionSliderWidget(
|
|
|
|
onSliderPositionChanged: (value) {
|
|
|
|
print("sliderposchanged");
|
|
|
|
},
|
2024-01-01 19:52:42 +01:00
|
|
|
sliderColor: textColor,
|
2024-01-01 18:31:10 +01:00
|
|
|
date: DateTime.now(),
|
|
|
|
questionText: "",
|
|
|
|
initialSliderValue: 0,
|
|
|
|
isSliderEnabled: true,
|
|
|
|
onSliderChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
sliderData = value;
|
|
|
|
if (!_sliderChanged) _sliderChanged = true;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// Why? button
|
|
|
|
_sliderChanged
|
|
|
|
? TextButton(
|
|
|
|
onPressed: () {
|
2024-01-01 19:52:42 +01:00
|
|
|
context.go('/write', extra: sliderData);
|
2024-01-01 18:31:10 +01:00
|
|
|
},
|
2024-01-01 19:52:42 +01:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 25),
|
|
|
|
child: Text(
|
|
|
|
"warum?",
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black, fontSize: 18),
|
|
|
|
),
|
|
|
|
),
|
2024-01-01 18:31:10 +01:00
|
|
|
)
|
|
|
|
: SizedBox.shrink(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// Skip/Save button
|
|
|
|
Positioned(
|
|
|
|
bottom: 20,
|
|
|
|
right: 20,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
print(_sliderChanged);
|
|
|
|
if (_sliderChanged) {
|
|
|
|
_saveEntry();
|
|
|
|
context.go('/home', extra: sliderData.value);
|
|
|
|
} else {
|
|
|
|
context.go('/home', extra: 0);
|
|
|
|
}
|
|
|
|
},
|
2024-01-01 19:52:42 +01:00
|
|
|
child: _sliderChanged
|
|
|
|
? Text("save.",
|
|
|
|
style:
|
|
|
|
TextStyle(fontSize: 18, color: textColor))
|
|
|
|
: Text("skip",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18, color: Colors.grey)),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
),
|
2024-01-01 18:31:10 +01:00
|
|
|
),
|
|
|
|
);
|
2023-12-17 23:00:31 +01:00
|
|
|
}
|
|
|
|
}
|