2024-01-08 19:34:48 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
import '../../utils/circle_painter.dart';
|
|
|
|
import '../../utils/definitions/color_pair.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import '../../utils/definitions/style_guide.dart';
|
2024-01-09 12:34:44 +01:00
|
|
|
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';
|
2024-01-08 19:34:48 +01:00
|
|
|
|
|
|
|
class EntryPage extends StatefulWidget {
|
2023-12-17 23:00:31 +01:00
|
|
|
final DateTime date;
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
const EntryPage({Key? key, required this.date}) : super(key: key);
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
@override
|
2024-01-09 12:34:44 +01:00
|
|
|
State<EntryPage> createState() => _EntryPage();
|
2023-12-17 23:00:31 +01:00
|
|
|
}
|
2023-12-25 14:10:31 +01:00
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
class _EntryPage extends State<EntryPage> {
|
2024-01-08 19:34:48 +01:00
|
|
|
SliderChangeData sliderData = SliderChangeData(0, 0);
|
|
|
|
String _moodText = "";
|
|
|
|
final PreferencesService _prefsService = PreferencesService();
|
|
|
|
Color backgroundColor = Colors.lightGreenAccent;
|
|
|
|
Color textColor = Colors.black;
|
2023-12-25 14:10:31 +01:00
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
// Add these new class member variables
|
2024-01-10 00:06:58 +01:00
|
|
|
final bool _isEditing = false;
|
2024-01-08 19:34:48 +01:00
|
|
|
final TextEditingController _textController = TextEditingController();
|
2023-12-25 14:10:31 +01:00
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadCurrentDiaryEntry();
|
|
|
|
_loadColor();
|
|
|
|
}
|
2023-12-25 14:10:31 +01:00
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
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;
|
2024-01-09 12:34:44 +01:00
|
|
|
_textController.text = (currentEntry != null ? currentEntry.texts.join(" ") : _moodText);
|
2024-01-08 19:34:48 +01:00
|
|
|
}
|
|
|
|
|
2024-01-10 00:06:58 +01:00
|
|
|
/* void _toggleEdit() {
|
2024-01-08 19:34:48 +01:00
|
|
|
setState(() {
|
|
|
|
_isEditing = !_isEditing;
|
|
|
|
});
|
|
|
|
if (!_isEditing) {
|
|
|
|
_saveEntry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _saveEntry() async {
|
2024-01-09 12:34:44 +01:00
|
|
|
//print("saveEntry...."); Todo for future versions
|
2024-01-08 19:34:48 +01:00
|
|
|
}
|
2024-01-10 00:06:58 +01:00
|
|
|
*/
|
2023-12-25 14:10:31 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2024-01-08 19:34:48 +01:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
]),
|
2023-12-25 14:10:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 30),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
2024-01-09 12:34:44 +01:00
|
|
|
"${sliderData.value}%",
|
|
|
|
style: const TextStyle(color: Colors.black),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
Text(DateFormat('dd MM yyyy').format(widget.date).toString(),
|
2024-01-09 12:34:44 +01:00
|
|
|
style: const TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold)),
|
2024-01-08 19:34:48 +01:00
|
|
|
],
|
2023-12-25 14:10:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 30.0),
|
|
|
|
child: MoodTextAreaWidget(
|
|
|
|
initialText: _moodText,
|
|
|
|
isDisabled: !_isEditing,
|
|
|
|
hasPrefix: false,
|
|
|
|
autoFocus: _isEditing,
|
|
|
|
forceBlinkingCursor: _isEditing,
|
|
|
|
)),
|
2024-01-09 12:36:26 +01:00
|
|
|
/*TextButton( //Todo: For Future Versions
|
2024-01-08 19:34:48 +01:00
|
|
|
onPressed: _toggleEdit,
|
|
|
|
child: Text(
|
|
|
|
_isEditing ? "Save" : "Edit",
|
|
|
|
style: TextStyle(fontSize: 18, color: textColor), // Use appropriate styling
|
2023-12-25 14:10:31 +01:00
|
|
|
),
|
2024-01-09 12:36:26 +01:00
|
|
|
),*/
|
2024-01-09 12:34:44 +01:00
|
|
|
const SizedBox(height: 400), // Space for floating bottom navigation bar
|
2024-01-08 19:34:48 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-12-25 14:10:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
2024-01-09 12:34:44 +01:00
|
|
|
floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0),
|
2023-12-25 14:10:31 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|