From dbba93411a85917cd3f488f266b1435eff3f9acb Mon Sep 17 00:00:00 2001 From: Chri$ <2023467@stud.hs-mannheim.de> Date: Mon, 1 Jan 2024 19:52:42 +0100 Subject: [PATCH] fixxed pin switch + other stuff --- lib/main.dart | 5 +- lib/utils/widgets/QuestionSliderWidget.dart | 10 ++-- lib/views/first_page/first_page.dart | 23 +++++++-- lib/views/home_page/home_page.dart | 1 + lib/views/settings_page/settings_page.dart | 51 ++++++++++++++++--- .../widgets/TextSwitchContainer.dart | 10 +++- .../statistic/widget/calendar_widget.dart | 7 +++ lib/views/write_page/write_page.dart | 17 ++++--- 8 files changed, 99 insertions(+), 25 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ae3f277..dd38f55 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:moody/utils/SlideDirection.dart'; +import 'package:moody/utils/widgets/QuestionSliderWidget.dart'; import 'package:moody/views/color_page/color_page.dart'; import 'package:moody/views/entry_view/entry_page.dart'; import 'package:moody/views/first_page/first_page.dart'; @@ -52,8 +53,8 @@ final GoRouter _router = GoRouter( GoRoute( path: '/write', builder: (context, state) { - final moodPercentage = state.extra as double; - return WritePage(moodPercentage: moodPercentage); + final sliderdata = state.extra as SliderChangeData; + return WritePage(sliderData: sliderdata); }, ), GoRoute( diff --git a/lib/utils/widgets/QuestionSliderWidget.dart b/lib/utils/widgets/QuestionSliderWidget.dart index 88febb9..3846e0a 100644 --- a/lib/utils/widgets/QuestionSliderWidget.dart +++ b/lib/utils/widgets/QuestionSliderWidget.dart @@ -9,6 +9,7 @@ class QuestionSliderWidget extends StatefulWidget { final bool isSliderEnabled; final ValueChanged onSliderChanged; final ValueChanged onSliderPositionChanged; + final Color sliderColor; // parameter for the color QuestionSliderWidget({ Key? key, @@ -18,6 +19,7 @@ class QuestionSliderWidget extends StatefulWidget { required this.isSliderEnabled, required this.onSliderChanged, required this.onSliderPositionChanged, + required this.sliderColor, // Initialize the color }) : super(key: key); @override @@ -69,7 +71,7 @@ class _QuestionSliderWidgetState extends State { child: SliderTheme( data: SliderTheme.of(context).copyWith( disabledThumbColor: Colors.transparent, - activeTrackColor: Colors.black, + activeTrackColor: widget.sliderColor, trackShape: RectangularSliderTrackShape(), inactiveTickMarkColor: Colors.red, inactiveTrackColor: Colors.transparent, @@ -114,11 +116,13 @@ class _QuestionSliderWidgetState extends State { child: _showDragText ? Text( "Drag Me -->", - style: TextStyle(fontSize: 16), + style: TextStyle( + fontSize: 16, color: widget.sliderColor), ) : Text( "${_sliderData.value.toStringAsFixed(0)}%", - style: TextStyle(fontSize: 20), + style: TextStyle( + fontSize: 20, color: widget.sliderColor), ), ), ), diff --git a/lib/views/first_page/first_page.dart b/lib/views/first_page/first_page.dart index f988abc..456a6db 100644 --- a/lib/views/first_page/first_page.dart +++ b/lib/views/first_page/first_page.dart @@ -13,7 +13,6 @@ class FirstPage extends StatefulWidget { class _FirstPageState extends State { SliderChangeData sliderData = SliderChangeData(0, 0); - double _sliderValue = 0.0; bool _sliderChanged = false; PreferencesService _prefsService = PreferencesService(); @@ -39,7 +38,7 @@ class _FirstPageState extends State { List texts = []; DiaryEntry entry = DiaryEntry( date: DateTime.now(), // or some date picker value - percentValue: _sliderValue.toInt(), + percentValue: sliderData.value.toInt(), texts: texts, ); @@ -79,6 +78,7 @@ class _FirstPageState extends State { onSliderPositionChanged: (value) { print("sliderposchanged"); }, + sliderColor: textColor, date: DateTime.now(), questionText: "", initialSliderValue: 0, @@ -95,9 +95,16 @@ class _FirstPageState extends State { _sliderChanged ? TextButton( onPressed: () { - context.go('/write', extra: sliderData.value); + context.go('/write', extra: sliderData); }, - child: Text("warum?"), + child: Padding( + padding: const EdgeInsets.only(left: 25), + child: Text( + "warum?", + style: TextStyle( + color: Colors.black, fontSize: 18), + ), + ), ) : SizedBox.shrink(), ], @@ -116,7 +123,13 @@ class _FirstPageState extends State { context.go('/home', extra: 0); } }, - child: Text(_sliderChanged ? "Save" : "Skip"), + child: _sliderChanged + ? Text("save.", + style: + TextStyle(fontSize: 18, color: textColor)) + : Text("skip", + style: TextStyle( + fontSize: 18, color: Colors.grey)), ), ), ], diff --git a/lib/views/home_page/home_page.dart b/lib/views/home_page/home_page.dart index b82ccc0..b13f27a 100644 --- a/lib/views/home_page/home_page.dart +++ b/lib/views/home_page/home_page.dart @@ -78,6 +78,7 @@ class _HomePageState extends State { onSliderPositionChanged: (value) { print("sliderposchanged"); }, + sliderColor: Colors.purple, date: DateTime.now(), questionText: 'this is how it is:', initialSliderValue: _sliderValue, diff --git a/lib/views/settings_page/settings_page.dart b/lib/views/settings_page/settings_page.dart index b9676c6..2804ac1 100644 --- a/lib/views/settings_page/settings_page.dart +++ b/lib/views/settings_page/settings_page.dart @@ -1,12 +1,33 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import '../../utils/logic/PreferencesService.dart'; import '../../utils/widgets/BottomNavigationWidget.dart'; import 'widgets/CustomDivider.dart'; import 'widgets/SetPinPopup.dart'; import 'widgets/TextSwitchContainer.dart'; -class SettingsPage extends StatelessWidget { +class SettingsPage extends StatefulWidget { + @override + _SettingsPageState createState() => _SettingsPageState(); +} + +class _SettingsPageState extends State { + bool isPinEnabled = false; // Default to false + + @override + void initState() { + super.initState(); + _loadPinEnabledState(); + } + + void _loadPinEnabledState() async { + isPinEnabled = await PreferencesService().isPinEnabled(); + print("isPinenabled2"); + print(isPinEnabled); + setState(() {}); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -34,11 +55,29 @@ class SettingsPage extends StatelessWidget { onTap: () => context.go("/color"), ), CustomDivider(), - TextSwitchContainer( - leftText: "pin", - hasSwitch: true, - onTap: () => {showSetPinPopup(context)}, - onSwitchToggle: (value) => print('Switch toggled: $value'), + FutureBuilder( + future: PreferencesService().isPinEnabled(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return CircularProgressIndicator(); // or some other placeholder + } + bool pinEnabled = + snapshot.data ?? false; // Default to false if null + return TextSwitchContainer( + leftText: "pin", + hasSwitch: true, + onTap: () => {showSetPinPopup(context)}, + onSwitchToggle: (value) { + if (value) { + PreferencesService().enablePin(); + } else { + PreferencesService().disablePin(); + } + // Consider updating the state here or using other state management + }, + switchDefaultValue: pinEnabled, + ); + }, ), CustomDivider(), TextSwitchContainer( diff --git a/lib/views/settings_page/widgets/TextSwitchContainer.dart b/lib/views/settings_page/widgets/TextSwitchContainer.dart index f435bf5..b798f34 100644 --- a/lib/views/settings_page/widgets/TextSwitchContainer.dart +++ b/lib/views/settings_page/widgets/TextSwitchContainer.dart @@ -7,6 +7,7 @@ class TextSwitchContainer extends StatefulWidget { final bool hasSwitch; final Function onTap; final Function(bool)? onSwitchToggle; + final bool switchDefaultValue; // Added parameter for the default switch value TextSwitchContainer({ required this.leftText, @@ -14,14 +15,19 @@ class TextSwitchContainer extends StatefulWidget { this.hasSwitch = false, required this.onTap, this.onSwitchToggle, + this.switchDefaultValue = false, }); @override - _TextSwitchContainerState createState() => _TextSwitchContainerState(); + _TextSwitchContainerState createState() => + _TextSwitchContainerState(switchValue: this.switchDefaultValue); } class _TextSwitchContainerState extends State { - bool switchValue = false; + bool switchValue; // No longer explicitly initialized here + + _TextSwitchContainerState( + {required this.switchValue}); // Constructor takes the initial switch value @override Widget build(BuildContext context) { diff --git a/lib/views/statistic/widget/calendar_widget.dart b/lib/views/statistic/widget/calendar_widget.dart index c2095c2..50a44e0 100644 --- a/lib/views/statistic/widget/calendar_widget.dart +++ b/lib/views/statistic/widget/calendar_widget.dart @@ -113,6 +113,13 @@ class _CalendarWidgetState extends State { // Fetching diary entry percentage value DiaryEntry? entry = diaryEntries[DateFormat('yyyy-MM-dd').format(date)]; + if (entry != null) { + print(entry); + print(entry!.date.toString()); + print(entry!.percentValue); + print(entry!.texts); + } + double fillPercentage = entry != null ? entry.percentValue / 100.0 : 0.0; diff --git a/lib/views/write_page/write_page.dart b/lib/views/write_page/write_page.dart index 162d75c..15bf1b5 100644 --- a/lib/views/write_page/write_page.dart +++ b/lib/views/write_page/write_page.dart @@ -7,15 +7,15 @@ import '../../utils/logic/PreferencesService.dart'; import '../../utils/widgets/QuestionSliderWidget.dart'; class WritePage extends StatefulWidget { - final double moodPercentage; + final SliderChangeData sliderData; - const WritePage({Key? key, required this.moodPercentage}) : super(key: key); + const WritePage({Key? key, required this.sliderData}) : super(key: key); @override _WritePageState createState() => _WritePageState(); } class _WritePageState extends State { - double _sliderValue = 0.0; + SliderChangeData _sliderData = SliderChangeData(0, 0); bool _sliderChanged = true; final PreferencesService _prefsService = PreferencesService(); TextEditingController _textController = TextEditingController(text: "why? "); @@ -23,7 +23,7 @@ class _WritePageState extends State { @override void initState() { super.initState(); - _sliderValue = widget.moodPercentage; // Set the value here + _sliderData = widget.sliderData; // Set the value here } void _saveEntry() async { @@ -33,7 +33,7 @@ class _WritePageState extends State { _textController.text.isEmpty ? [] : [_textController.text]; DiaryEntry entry = DiaryEntry( date: DateTime.now(), // or some date picker value - percentValue: _sliderValue.toInt(), + percentValue: _sliderData.value.toInt(), texts: texts, ); @@ -58,7 +58,8 @@ class _WritePageState extends State { // Background circle Positioned.fill( child: CustomPaint( - painter: CirclePainter(_sliderValue, Colors.yellowAccent), + painter: + CirclePainter(_sliderData.value, Colors.yellowAccent), ), ), // Main content @@ -73,6 +74,7 @@ class _WritePageState extends State { onSliderPositionChanged: (value) { print("sliderposchanged"); }, + sliderColor: Colors.lightBlue, date: DateTime.now(), questionText: "How are you today", initialSliderValue: 0, @@ -84,7 +86,7 @@ class _WritePageState extends State { }), TextButton( onPressed: () { - context.go('/write', extra: _sliderValue); + context.go('/write', extra: _sliderData); }, child: Padding( padding: const EdgeInsets.fromLTRB(25, 0, 25, 25), @@ -100,6 +102,7 @@ class _WritePageState extends State { right: 20, child: TextButton( onPressed: () { + _saveEntry(); context.go("/home"); }, child: Text(_sliderChanged ? "Save" : "Skip"),