import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:moody/utils/widgets/QuestionSliderWidget.dart'; import '../../utils/CirclePainter.dart'; import '../../utils/definitions/ColorPairs.dart'; import '../../utils/logic/PreferencesService.dart'; class FirstPage extends StatefulWidget { @override _FirstPageState createState() => _FirstPageState(); } class _FirstPageState extends State { SliderChangeData sliderData = SliderChangeData(0, 0); double _sliderValue = 0.0; bool _sliderChanged = false; PreferencesService _prefsService = PreferencesService(); 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; }); } void _saveEntry() async { try { List 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 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: [ // Date Stack( children: [ QuestionSliderWidget( onSliderPositionChanged: (value) { print("sliderposchanged"); }, date: DateTime.now(), questionText: "", initialSliderValue: 0, isSliderEnabled: true, onSliderChanged: (value) { setState(() { sliderData = value; if (!_sliderChanged) _sliderChanged = true; }); }), ], ), // Why? button _sliderChanged ? TextButton( onPressed: () { context.go('/write', extra: sliderData.value); }, child: Text("warum?"), ) : 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); } }, child: Text(_sliderChanged ? "Save" : "Skip"), ), ), ], ), ), ), ); } }