2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import 'package:moody/utils/definitions/style_guide.dart';
|
|
|
|
import 'package:moody/views/first_page/first_page.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
|
2023-12-25 14:10:31 +01:00
|
|
|
import '../../utils/CirclePainter.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import '../../utils/definitions/ColorPairs.dart';
|
2023-12-25 14:10:31 +01:00
|
|
|
import '../../utils/logic/PreferencesService.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
import '../../utils/widgets/BottomNavigationWidget.dart';
|
|
|
|
import '../../utils/widgets/QuestionSliderWidget.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import '../../utils/widgets/WhyWidget.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
const HomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<HomePage> createState() => _HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage> {
|
2024-01-08 19:34:48 +01:00
|
|
|
SliderChangeData sliderData = SliderChangeData(0, 0);
|
|
|
|
String _moodText = "";
|
2023-12-17 23:00:31 +01:00
|
|
|
bool _isTextAreaEditable = false;
|
2023-12-25 14:10:31 +01:00
|
|
|
final PreferencesService _prefsService = PreferencesService();
|
2024-01-08 19:34:48 +01:00
|
|
|
Color backgroundColor = Colors.lightGreenAccent;
|
|
|
|
Color textColor = Colors.black;
|
|
|
|
bool noData = false;
|
|
|
|
|
|
|
|
final TextEditingController _textController = TextEditingController(text: "");
|
2023-12-25 14:10:31 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadCurrentDiaryEntry();
|
2024-01-08 19:34:48 +01:00
|
|
|
_loadColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _loadColor() async {
|
|
|
|
ColorPair colorPair = await PreferencesService().loadColorPair();
|
|
|
|
setState(() {
|
|
|
|
backgroundColor = colorPair.backgroundColor;
|
|
|
|
textColor = colorPair.textColor;
|
|
|
|
});
|
2023-12-25 14:10:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _loadCurrentDiaryEntry() async {
|
|
|
|
DiaryEntry? currentEntry = await _prefsService.getDiaryEntryByCurrentDate();
|
|
|
|
if (currentEntry != null) {
|
2024-01-08 19:34:48 +01:00
|
|
|
print(currentEntry.texts.join(" "));
|
2023-12-25 14:10:31 +01:00
|
|
|
setState(() {
|
2024-01-08 19:34:48 +01:00
|
|
|
sliderData.value = currentEntry.percentValue.toDouble();
|
|
|
|
print(currentEntry.percentValue);
|
|
|
|
_moodText = currentEntry.texts.join(" "); // Assuming you want to concatenate all texts
|
|
|
|
_textController.text = currentEntry.texts.join(" ");
|
2023-12-25 14:10:31 +01:00
|
|
|
});
|
2024-01-08 19:34:48 +01:00
|
|
|
setState(() {});
|
|
|
|
print(sliderData.value);
|
2023-12-25 14:10:31 +01:00
|
|
|
} else {
|
|
|
|
setState(() {
|
2024-01-08 19:34:48 +01:00
|
|
|
noData = true;
|
2023-12-25 14:10:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
void _toggleTextAreaEditability() {
|
|
|
|
setState(() {
|
2024-01-08 19:34:48 +01:00
|
|
|
if (_isTextAreaEditable) {
|
|
|
|
_saveEntry();
|
|
|
|
}
|
2023-12-17 23:00:31 +01:00
|
|
|
_isTextAreaEditable = !_isTextAreaEditable;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
void _saveEntry() async {
|
|
|
|
try {
|
|
|
|
List<String> texts = _textController.text.isEmpty ? [] : [_textController.text];
|
|
|
|
print("DerText:${_textController.text}");
|
|
|
|
DiaryEntry entry = DiaryEntry(
|
|
|
|
date: DateTime.now(),
|
|
|
|
percentValue: sliderData.value.toInt(),
|
|
|
|
texts: texts,
|
|
|
|
);
|
|
|
|
|
|
|
|
await _prefsService.saveDiaryEntry(entry);
|
|
|
|
} catch (e) {
|
|
|
|
print("Error saving entry: $e");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-17 23:00:31 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-01-08 19:34:48 +01:00
|
|
|
return noData
|
|
|
|
? Scaffold(
|
|
|
|
body: const FirstPage(showSkipText: false),
|
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
|
|
floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 1),
|
|
|
|
)
|
|
|
|
: Scaffold(
|
|
|
|
backgroundColor: AppStyle.backgroundColor,
|
|
|
|
body: SafeArea(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
// Background circle
|
|
|
|
Positioned.fill(
|
|
|
|
top: 25,
|
|
|
|
left: sliderData.position,
|
|
|
|
child: CustomPaint(
|
|
|
|
painter: CirclePainter(sliderData.value, backgroundColor),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
QuestionSliderWidget(
|
|
|
|
onSliderPositionChanged: (value) {
|
|
|
|
print("sliderposchanged");
|
|
|
|
},
|
|
|
|
sliderColor: textColor,
|
|
|
|
date: DateTime.now(),
|
|
|
|
questionText: 'today',
|
|
|
|
initialSliderValue: sliderData.value.toDouble(),
|
|
|
|
isSliderEnabled: _isTextAreaEditable,
|
|
|
|
onSliderChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
sliderData.value = value.value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 30.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
/*MoodTextAreaWidget(
|
|
|
|
controller: _textController,
|
|
|
|
initialText: _moodText,
|
|
|
|
isDisabled: !_isTextAreaEditable,
|
|
|
|
hasPrefix: false,
|
|
|
|
autoFocus: _isTextAreaEditable,
|
|
|
|
forceBlinkingCursor: _isTextAreaEditable,
|
|
|
|
),*/
|
|
|
|
_isTextAreaEditable
|
|
|
|
? WhyWidget(
|
|
|
|
controller: _textController,
|
|
|
|
prependWhy: false,
|
|
|
|
)
|
|
|
|
: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Text(_textController.text, style: TextStyle(color: textColor, fontSize: 18)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: _toggleTextAreaEditability,
|
|
|
|
child: Text(
|
|
|
|
_isTextAreaEditable ? "- Save" : "+ Edit",
|
|
|
|
style: TextStyle(color: textColor, fontSize: 18),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 600),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2023-12-25 14:10:31 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
|
|
floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 1),
|
|
|
|
);
|
2023-12-17 23:00:31 +01:00
|
|
|
}
|
|
|
|
}
|