import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; import '../../utils/circle_painter.dart'; import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; import '../../utils/logic/preferences_service.dart'; import '../../utils/widgets/custom_bottom_navigation_bar.dart'; import '../../utils/widgets/mood_text_area_widget.dart'; import '../../utils/widgets/question_slider_widget.dart'; class EntryPage extends StatefulWidget { final DateTime date; const EntryPage({Key? key, required this.date}) : super(key: key); @override State createState() => _EntryPage(); } class _EntryPage extends State { SliderChangeData sliderData = SliderChangeData(0, 0); String _moodText = ""; final PreferencesService _prefsService = PreferencesService(); Color backgroundColor = Colors.lightGreenAccent; Color textColor = Colors.black; // Add these new class member variables bool _isEditing = false; final TextEditingController _textController = TextEditingController(); @override void initState() { super.initState(); _loadCurrentDiaryEntry(); _loadColor(); } void _loadColor() async { ColorPair colorPair = await _prefsService.loadColorPair(); setState(() { backgroundColor = colorPair.backgroundColor; textColor = colorPair.textColor; }); } void _loadCurrentDiaryEntry() async { DiaryEntry? currentEntry = await _prefsService.getDiaryEntryByDate(widget.date); if (currentEntry != null) { setState(() { sliderData.value = currentEntry.percentValue.toDouble(); _moodText = currentEntry.texts.join(" "); // Concatenate all texts }); } else { setState(() { sliderData.value = 0.0; _moodText = "No text found for this date."; }); } // _textController.text = _moodText; _textController.text = (currentEntry != null ? currentEntry.texts.join(" ") : _moodText); } void _toggleEdit() { setState(() { _isEditing = !_isEditing; }); if (!_isEditing) { _saveEntry(); } } void _saveEntry() async { //print("saveEntry...."); Todo for future versions } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppStyle.backgroundColor, body: SafeArea( child: SingleChildScrollView( child: Stack( children: [ // Background circle Padding( padding: const EdgeInsets.only(top: 250), child: Positioned.fill( child: CustomPaint( painter: CirclePainter(sliderData.value, backgroundColor), ), ), ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( onTap: () { context.go("/statistic"); }, child: const Padding( padding: EdgeInsets.only(left: 25, top: 80), child: Row(children: [ Icon(size: 25, Icons.chevron_left, color: Colors.black), // "<" icon SizedBox( height: 140, ) ]), ), ), Padding( padding: const EdgeInsets.only(left: 30), child: Column( children: [ Text( "${sliderData.value}%", style: const TextStyle(color: Colors.black), ), Text(DateFormat('dd MM yyyy').format(widget.date).toString(), style: const TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold)), ], ), ), Padding( padding: const EdgeInsets.only(left: 30.0), child: MoodTextAreaWidget( initialText: _moodText, isDisabled: !_isEditing, hasPrefix: false, autoFocus: _isEditing, forceBlinkingCursor: _isEditing, )), TextButton( onPressed: _toggleEdit, child: Text( _isEditing ? "Save" : "Edit", style: TextStyle(fontSize: 18, color: textColor), // Use appropriate styling ), ), const SizedBox(height: 400), // Space for floating bottom navigation bar ], ), ], ), ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0), ); } }