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';
|
|
|
|
|
|
|
|
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> {
|
|
|
|
double _sliderValue = 0.0;
|
|
|
|
bool _sliderChanged = false;
|
2023-12-25 14:10:31 +01:00
|
|
|
PreferencesService _prefsService = PreferencesService();
|
|
|
|
|
|
|
|
void _saveEntry() async {
|
|
|
|
try {
|
|
|
|
List<String> texts = [];
|
|
|
|
DiaryEntry entry = DiaryEntry(
|
|
|
|
date: DateTime.now(), // or some date picker value
|
|
|
|
percentValue: _sliderValue.toInt(),
|
|
|
|
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) {
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: SafeArea(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
// Background circle
|
2023-12-25 14:10:31 +01:00
|
|
|
/*Positioned.fill(
|
2023-12-17 23:00:31 +01:00
|
|
|
child: CustomPaint(
|
|
|
|
painter: CirclePainter(_sliderValue),
|
|
|
|
),
|
2023-12-25 14:10:31 +01:00
|
|
|
),*/
|
2023-12-17 23:00:31 +01:00
|
|
|
// Main content
|
2023-12-25 14:10:31 +01:00
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
// Date
|
|
|
|
QuestionSliderWidget(
|
|
|
|
date: DateTime.now(),
|
|
|
|
questionText: "How are you today",
|
|
|
|
initialSliderValue: 0,
|
|
|
|
isSliderEnabled: true,
|
|
|
|
onSliderChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_sliderValue = value;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
// Why? button
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
context.go('/write', extra: _sliderValue);
|
2023-12-17 23:00:31 +01:00
|
|
|
|
2023-12-25 14:10:31 +01:00
|
|
|
// Implement your why? functionality here
|
|
|
|
},
|
|
|
|
child: Text("Why?"),
|
|
|
|
),
|
|
|
|
],
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
// Skip/Save button
|
|
|
|
Positioned(
|
|
|
|
bottom: 20,
|
|
|
|
right: 20,
|
|
|
|
child: TextButton(
|
2023-12-25 14:10:31 +01:00
|
|
|
onPressed: () {
|
|
|
|
print(_sliderChanged);
|
|
|
|
if (_sliderChanged) {
|
|
|
|
_saveEntry();
|
|
|
|
context.go('/home', extra: _sliderValue);
|
|
|
|
} else {
|
|
|
|
context.go('/home', extra: 0);
|
|
|
|
}
|
|
|
|
},
|
2023-12-17 23:00:31 +01:00
|
|
|
child: Text(_sliderChanged ? "Save" : "Skip"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|