112 lines
3.2 KiB
Dart
112 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../utils/CirclePainter.dart';
|
|
import '../../utils/logic/PreferencesService.dart';
|
|
import '../../utils/widgets/BottomNavigationWidget.dart';
|
|
import '../../utils/widgets/MoodTextArea.dart';
|
|
import '../../utils/widgets/QuestionSliderWidget.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
home: HomePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
double _sliderValue = 0.0;
|
|
String _moodText = "No text given";
|
|
bool _isTextAreaEditable = false;
|
|
final PreferencesService _prefsService = PreferencesService();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadCurrentDiaryEntry();
|
|
}
|
|
|
|
void _loadCurrentDiaryEntry() async {
|
|
DiaryEntry? currentEntry = await _prefsService.getDiaryEntryByCurrentDate();
|
|
if (currentEntry != null) {
|
|
setState(() {
|
|
_sliderValue = currentEntry.percentValue.toDouble();
|
|
_moodText = currentEntry.texts
|
|
.join(" "); // Assuming you want to concatenate all texts
|
|
});
|
|
} else {
|
|
setState(() {
|
|
_sliderValue = 0.0;
|
|
_moodText = "No text given";
|
|
});
|
|
}
|
|
}
|
|
|
|
void _toggleTextAreaEditability() {
|
|
setState(() {
|
|
_isTextAreaEditable = !_isTextAreaEditable;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Stack(
|
|
children: [
|
|
// Background circle
|
|
Positioned.fill(
|
|
child: CustomPaint(
|
|
painter: CirclePainter(_sliderValue),
|
|
),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
QuestionSliderWidget(
|
|
date: DateTime.now(),
|
|
questionText: 'this is how it is:',
|
|
initialSliderValue: _sliderValue,
|
|
isSliderEnabled: true,
|
|
onSliderChanged: (value) {
|
|
setState(() {
|
|
_sliderValue = value;
|
|
});
|
|
},
|
|
),
|
|
MoodTextAreaWidget(
|
|
initialText: _moodText,
|
|
isDisabled: !_isTextAreaEditable,
|
|
hasPrefix: false,
|
|
autoFocus: false,
|
|
forceBlinkingCursor: false,
|
|
),
|
|
ElevatedButton(
|
|
onPressed: _toggleTextAreaEditability,
|
|
child: Text(_isTextAreaEditable ? "- Save" : "+ Edit"),
|
|
),
|
|
SizedBox(
|
|
height: 100), // Space for floating bottom navigation bar
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 1),
|
|
);
|
|
}
|
|
}
|