96 lines
2.8 KiB
Dart
96 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:moody/utils/widgets/QuestionSliderWidget.dart';
|
|
|
|
import '../../utils/logic/PreferencesService.dart';
|
|
|
|
class FirstPage extends StatefulWidget {
|
|
@override
|
|
_FirstPageState createState() => _FirstPageState();
|
|
}
|
|
|
|
class _FirstPageState extends State<FirstPage> {
|
|
double _sliderValue = 0.0;
|
|
bool _sliderChanged = false;
|
|
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
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
// Background circle
|
|
/*Positioned.fill(
|
|
child: CustomPaint(
|
|
painter: CirclePainter(_sliderValue),
|
|
),
|
|
),*/
|
|
// Main content
|
|
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);
|
|
|
|
// Implement your why? functionality here
|
|
},
|
|
child: Text("Why?"),
|
|
),
|
|
],
|
|
),
|
|
// Skip/Save button
|
|
Positioned(
|
|
bottom: 20,
|
|
right: 20,
|
|
child: TextButton(
|
|
onPressed: () {
|
|
print(_sliderChanged);
|
|
if (_sliderChanged) {
|
|
_saveEntry();
|
|
context.go('/home', extra: _sliderValue);
|
|
} else {
|
|
context.go('/home', extra: 0);
|
|
}
|
|
},
|
|
child: Text(_sliderChanged ? "Save" : "Skip"),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|