From cf53061e3a2a07a39f01d1514209dc26022e5149 Mon Sep 17 00:00:00 2001 From: Chri$ <2023467@stud.hs-mannheim.de> Date: Tue, 9 Jan 2024 12:34:44 +0100 Subject: [PATCH] fixed important things --- lib/main.dart | 53 ++++------ ...CirclePainter.dart => circle_painter.dart} | 8 +- lib/utils/definitions/ColorPairs.dart | 44 -------- lib/utils/definitions/color_pair.dart | 19 ++++ ...sService.dart => preferences_service.dart} | 4 +- ...Generator.dart => question_generator.dart} | 0 ...ideDirection.dart => slide_direction.dart} | 0 ...dart => custom_bottom_navigation_bar.dart} | 49 ++++----- ...xtArea.dart => mood_text_area_widget.dart} | 7 +- ...idget.dart => question_slider_widget.dart} | 19 ++-- .../{WhyWidget.dart => why_widget.dart} | 6 +- lib/views/color_page/color_page.dart | 35 +++--- lib/views/entry_view/entry_page.dart | 32 +++--- lib/views/first_page/first_page.dart | 26 ++--- lib/views/first_page/widgets/drag_widget.dart | 19 ++-- lib/views/home_page/home_page.dart | 31 +++--- lib/views/home_page/kalendartryhome_page.dart | 100 ------------------ lib/views/settings_page/settings_page.dart | 64 +++++------ ...ivider.dart => custom_divider_widget.dart} | 0 ...inPopup.dart => set_pin_popup_widget.dart} | 40 +++---- ...et.dart => settings_selection_widget.dart} | 23 ++-- ...dart => text_switch_container_widget.dart} | 41 ++++--- lib/views/start_page/start_page.dart | 46 ++++---- lib/views/statistic/statistic_page.dart | 30 +++--- .../statistic/widget/calendar_widget.dart | 78 +++++--------- lib/views/statistic/widget/streak_widget.dart | 2 +- lib/views/write_page/writeOld_page.dart | 81 -------------- lib/views/write_page/write_page.dart | 20 ++-- test/my_app_test.dart | 27 +++++ 29 files changed, 344 insertions(+), 560 deletions(-) rename lib/utils/{CirclePainter.dart => circle_painter.dart} (72%) delete mode 100644 lib/utils/definitions/ColorPairs.dart create mode 100644 lib/utils/definitions/color_pair.dart rename lib/utils/logic/{PreferencesService.dart => preferences_service.dart} (98%) rename lib/utils/logic/{QuestionGenerator.dart => question_generator.dart} (100%) rename lib/utils/{SlideDirection.dart => slide_direction.dart} (100%) rename lib/utils/widgets/{BottomNavigationWidget.dart => custom_bottom_navigation_bar.dart} (65%) rename lib/utils/widgets/{MoodTextArea.dart => mood_text_area_widget.dart} (92%) rename lib/utils/widgets/{QuestionSliderWidget.dart => question_slider_widget.dart} (91%) rename lib/utils/widgets/{WhyWidget.dart => why_widget.dart} (93%) delete mode 100644 lib/views/home_page/kalendartryhome_page.dart rename lib/views/settings_page/widgets/{CustomDivider.dart => custom_divider_widget.dart} (100%) rename lib/views/settings_page/widgets/{SetPinPopup.dart => set_pin_popup_widget.dart} (73%) rename lib/views/settings_page/widgets/{SettingsSelectionWdiget.dart => settings_selection_widget.dart} (67%) rename lib/views/settings_page/widgets/{TextSwitchContainer.dart => text_switch_container_widget.dart} (57%) delete mode 100644 lib/views/write_page/writeOld_page.dart create mode 100644 test/my_app_test.dart diff --git a/lib/main.dart b/lib/main.dart index dd38f55..47c7387 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,12 +1,11 @@ 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/utils/slide_direction.dart'; +import 'package:moody/utils/widgets/question_slider_widget.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'; import 'package:moody/views/home_page/home_page.dart'; -import 'package:moody/views/home_page/kalendartryhome_page.dart'; import 'package:moody/views/settings_page/settings_page.dart'; import 'package:moody/views/start_page/start_page.dart'; import 'package:moody/views/statistic/statistic_page.dart'; @@ -18,37 +17,32 @@ final GoRouter _router = GoRouter( routes: [ GoRoute( path: '/', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, StartPage()), + pageBuilder: (context, state) => _noAnimationTransition(context, state, const StartPage()), ), GoRoute( path: '/moods', - builder: (context, state) => CalendarPage(), + builder: (context, state) => const StatisticPage(), ), GoRoute( path: '/settings', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, SettingsPage()), + pageBuilder: (context, state) => _noAnimationTransition(context, state, const SettingsPage()), ), GoRoute( path: '/statistic', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, StatisticPage()), + // ignore: prefer_const_constructors + pageBuilder: (context, state) => _noAnimationTransition(context, state, StatisticPage()), ), GoRoute( path: '/home', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, HomePage()), + pageBuilder: (context, state) => _noAnimationTransition(context, state, const HomePage()), ), GoRoute( path: '/first', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, FirstPage()), + pageBuilder: (context, state) => _noAnimationTransition(context, state, const FirstPage()), ), GoRoute( path: '/color', - pageBuilder: (context, state) => - _noAnimationTransition(context, state, ColorPage()), + pageBuilder: (context, state) => _noAnimationTransition(context, state, const ColorPage()), ), GoRoute( path: '/write', @@ -81,10 +75,9 @@ class MyApp extends StatelessWidget { } } -CustomTransitionPage _createSlideTransition(BuildContext context, - GoRouterState state, Widget child, SlideDirection direction) { - var beginOffset = - direction == SlideDirection.left ? Offset(1.0, 0.0) : Offset(-1.0, 0.0); +/* A Slide Transition that will may be used in future versions +CustomTransitionPage _createSlideTransition(BuildContext context, GoRouterState state, Widget child, SlideDirection direction) { + var beginOffset = direction == SlideDirection.left ? Offset(1.0, 0.0) : Offset(-1.0, 0.0); return CustomTransitionPage( key: state.pageKey, @@ -93,8 +86,7 @@ CustomTransitionPage _createSlideTransition(BuildContext context, var end = Offset.zero; var curve = Curves.easeInOut; - var tween = - Tween(begin: beginOffset, end: end).chain(CurveTween(curve: curve)); + var tween = Tween(begin: beginOffset, end: end).chain(CurveTween(curve: curve)); var offsetAnimation = animation.drive(tween); return SlideTransition( @@ -103,15 +95,9 @@ CustomTransitionPage _createSlideTransition(BuildContext context, ); }, ); -} +}*/ -SlideDirection determineSlideDirection( - String currentRoute, String targetRoute) { - print(currentRoute); - print(targetRoute); - if (currentRoute == targetRoute) { - print("Sameroute pls fix!!"); - } +SlideDirection determineSlideDirection(String currentRoute, String targetRoute) { if (targetRoute == "/statistic") { return SlideDirection.right; } else if (targetRoute == "/settings") { @@ -123,13 +109,10 @@ SlideDirection determineSlideDirection( return SlideDirection.right; } } - return currentRoute.compareTo(targetRoute) < 0 - ? SlideDirection.left - : SlideDirection.right; + return currentRoute.compareTo(targetRoute) < 0 ? SlideDirection.left : SlideDirection.right; } -CustomTransitionPage _noAnimationTransition( - BuildContext context, GoRouterState state, Widget child) { +CustomTransitionPage _noAnimationTransition(BuildContext context, GoRouterState state, Widget child) { return CustomTransitionPage( key: state.pageKey, child: child, diff --git a/lib/utils/CirclePainter.dart b/lib/utils/circle_painter.dart similarity index 72% rename from lib/utils/CirclePainter.dart rename to lib/utils/circle_painter.dart index 409653b..c8598b9 100644 --- a/lib/utils/CirclePainter.dart +++ b/lib/utils/circle_painter.dart @@ -1,4 +1,4 @@ -import 'dart:math' as Math; +import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -6,9 +6,7 @@ class CirclePainter extends CustomPainter { final double value; final Color color; // New field for color - CirclePainter(this.value, this.color) { - print("CirclePainter " + value.toString()); - } + CirclePainter(this.value, this.color); @override void paint(Canvas canvas, Size size) { @@ -16,7 +14,7 @@ class CirclePainter extends CustomPainter { ..color = color.withOpacity(0.5) // Use the passed color ..style = PaintingStyle.fill; - double radius = Math.pow(((value + 5) * 500 / 100) / 1.5, 1.14).toDouble(); + double radius = math.pow(((value + 5) * 500 / 100) / 1.5, 1.14).toDouble(); canvas.drawCircle(Offset(55, size.height / 4), radius, paint); } diff --git a/lib/utils/definitions/ColorPairs.dart b/lib/utils/definitions/ColorPairs.dart deleted file mode 100644 index 1690ca1..0000000 --- a/lib/utils/definitions/ColorPairs.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'package:flutter/material.dart'; - -class ColorPair { - final Color textColor; - final Color backgroundColor; - final String name; - - ColorPair( - {required this.name, - required this.textColor, - required this.backgroundColor}); -} - -List colorPairs = [ - ColorPair( - name: "origin", - textColor: Color(0xff446F2F), - backgroundColor: Color(0xffC9E7BB)), - ColorPair( - name: "lavender", - textColor: Color(0xff765EAB), - backgroundColor: Color(0xffD3CAE7)), - ColorPair( - name: "orange", - textColor: Color(0xffC78233), - backgroundColor: Color(0xffF0CFA9)), - ColorPair( - name: "rose", - textColor: Color(0xffB15555), - backgroundColor: Color(0xffEBD6D6)), - ColorPair( - name: "mountain", - textColor: Color(0xff1D6289), - backgroundColor: Color(0xffB4D0E0)), - ColorPair( - name: "moon", - textColor: Color(0xff7A83C7), - backgroundColor: Color(0xff393C55)), - ColorPair( - name: "forest", - textColor: Color(0xffC9E7BB), - backgroundColor: Color(0xff4C5847)), - // ...add other color pairs with names... -]; diff --git a/lib/utils/definitions/color_pair.dart b/lib/utils/definitions/color_pair.dart new file mode 100644 index 0000000..c509a56 --- /dev/null +++ b/lib/utils/definitions/color_pair.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; + +class ColorPair { + final Color textColor; + final Color backgroundColor; + final String name; + + ColorPair({required this.name, required this.textColor, required this.backgroundColor}); +} + +List colorPairs = [ + ColorPair(name: "origin", textColor: const Color(0xff446F2F), backgroundColor: const Color(0xffC9E7BB)), + ColorPair(name: "lavender", textColor: const Color(0xff765EAB), backgroundColor: const Color(0xffD3CAE7)), + ColorPair(name: "orange", textColor: const Color(0xffC78233), backgroundColor: const Color(0xffF0CFA9)), + ColorPair(name: "rose", textColor: const Color(0xffB15555), backgroundColor: const Color(0xffEBD6D6)), + ColorPair(name: "mountain", textColor: const Color(0xff1D6289), backgroundColor: const Color(0xffB4D0E0)), + ColorPair(name: "moon", textColor: const Color(0xff7A83C7), backgroundColor: const Color(0xff393C55)), + ColorPair(name: "forest", textColor: const Color(0xffC9E7BB), backgroundColor: const Color(0xff4C5847)), +]; diff --git a/lib/utils/logic/PreferencesService.dart b/lib/utils/logic/preferences_service.dart similarity index 98% rename from lib/utils/logic/PreferencesService.dart rename to lib/utils/logic/preferences_service.dart index 199226b..cb70172 100644 --- a/lib/utils/logic/PreferencesService.dart +++ b/lib/utils/logic/preferences_service.dart @@ -4,7 +4,7 @@ import 'dart:ui'; import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import '../definitions/ColorPairs.dart'; +import '../definitions/color_pair.dart'; class PreferencesService { static const _keyColor1 = 'color1'; @@ -138,7 +138,7 @@ class PreferencesService { while (entryDates.contains(DateFormat('yyyy-MM-dd').format(currentDate))) { streakCount++; - currentDate = currentDate.subtract(Duration(days: 1)); // Move to the previous day + currentDate = currentDate.subtract(const Duration(days: 1)); // Move to the previous day } return streakCount; diff --git a/lib/utils/logic/QuestionGenerator.dart b/lib/utils/logic/question_generator.dart similarity index 100% rename from lib/utils/logic/QuestionGenerator.dart rename to lib/utils/logic/question_generator.dart diff --git a/lib/utils/SlideDirection.dart b/lib/utils/slide_direction.dart similarity index 100% rename from lib/utils/SlideDirection.dart rename to lib/utils/slide_direction.dart diff --git a/lib/utils/widgets/BottomNavigationWidget.dart b/lib/utils/widgets/custom_bottom_navigation_bar.dart similarity index 65% rename from lib/utils/widgets/BottomNavigationWidget.dart rename to lib/utils/widgets/custom_bottom_navigation_bar.dart index f343d1b..6ee0ab8 100644 --- a/lib/utils/widgets/BottomNavigationWidget.dart +++ b/lib/utils/widgets/custom_bottom_navigation_bar.dart @@ -1,20 +1,18 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:moody/utils/definitions/ColorPairs.dart'; -import 'package:moody/utils/logic/PreferencesService.dart'; +import 'package:moody/utils/definitions/color_pair.dart'; +import 'package:moody/utils/logic/preferences_service.dart'; class CustomBottomNavigationBar extends StatefulWidget { final int initialSelectedIndex; - CustomBottomNavigationBar({Key? key, this.initialSelectedIndex = 0}) - : super(key: key); + const CustomBottomNavigationBar({Key? key, this.initialSelectedIndex = 0}) : super(key: key); @override - _CustomBottomNavigationBarState createState() => - _CustomBottomNavigationBarState(); + State createState() => _CustomBottomNavigationBar(); } -class _CustomBottomNavigationBarState extends State { +class _CustomBottomNavigationBar extends State { late int _selectedIndex; @override @@ -27,9 +25,7 @@ class _CustomBottomNavigationBarState extends State { setState(() { _selectedIndex = index; }); - print('Item $index clicked'); - var currentRoute = - GoRouter.of(context).routeInformationProvider.value.location; + var currentRoute = GoRouter.of(context).routeInformationProvider.value.uri.toString(); var goToRoute = "/"; switch (index) { case 0: @@ -50,47 +46,41 @@ class _CustomBottomNavigationBarState extends State { @override Widget build(BuildContext context) { return FutureBuilder( - future: - PreferencesService().loadColorPair(), // Async loading of the color + future: PreferencesService().loadColorPair(), // Async loading of the color builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { + if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) { // When data is loaded - Color backgroundColor = - snapshot.data!.backgroundColor; // Use loaded background color + Color backgroundColor = snapshot.data!.backgroundColor; // Use loaded background color return buildNavigationBar(backgroundColor); } else { // While loading or if no data, show default or loading indicator - return buildNavigationBar( - Colors.white); // Default color or loading indicator + return buildNavigationBar(Colors.white); // Default color or loading indicator } }, ); } - @override Widget buildNavigationBar(Color backgroundColor) { return Container( width: 175, - margin: EdgeInsets.only(bottom: 30), - padding: EdgeInsets.all(5), + margin: const EdgeInsets.only(bottom: 30), + padding: const EdgeInsets.all(5), decoration: BoxDecoration( color: Colors.white, border: Border.all(color: Colors.transparent), - borderRadius: - BorderRadius.circular(35), // Adjust radius to fit your design + borderRadius: BorderRadius.circular(35), // Adjust radius to fit your design boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.5), spreadRadius: 1, blurRadius: 7, - offset: Offset(3, 3), // changes position of shadow + offset: const Offset(3, 3), // changes position of shadow ), BoxShadow( color: Colors.grey.withOpacity(0.3), spreadRadius: 1, blurRadius: 5, - offset: Offset(-1, -1), // changes position of shadow + offset: const Offset(-1, -1), // changes position of shadow ), // You can add more BoxShadow layers to create more complex shadows ], @@ -100,12 +90,9 @@ class _CustomBottomNavigationBarState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - _buildNavItem(Image.asset('assets/icons/icon-analyze.png'), 0, - backgroundColor), - _buildNavItem( - Image.asset('assets/icons/icon-logo.png'), 1, backgroundColor), - _buildNavItem(Image.asset('assets/icons/icon-settings.png'), 2, - backgroundColor), + _buildNavItem(Image.asset('assets/icons/icon-analyze.png'), 0, backgroundColor), + _buildNavItem(Image.asset('assets/icons/icon-logo.png'), 1, backgroundColor), + _buildNavItem(Image.asset('assets/icons/icon-settings.png'), 2, backgroundColor), ], ), ), diff --git a/lib/utils/widgets/MoodTextArea.dart b/lib/utils/widgets/mood_text_area_widget.dart similarity index 92% rename from lib/utils/widgets/MoodTextArea.dart rename to lib/utils/widgets/mood_text_area_widget.dart index a9f8442..c65315f 100644 --- a/lib/utils/widgets/MoodTextArea.dart +++ b/lib/utils/widgets/mood_text_area_widget.dart @@ -8,7 +8,7 @@ class MoodTextAreaWidget extends StatefulWidget { final bool forceBlinkingCursor; final TextEditingController? controller; - MoodTextAreaWidget({ + const MoodTextAreaWidget({ Key? key, this.initialText = '', this.isDisabled = false, @@ -19,10 +19,10 @@ class MoodTextAreaWidget extends StatefulWidget { }) : super(key: key); @override - _MoodTextAreaWidgetState createState() => _MoodTextAreaWidgetState(); + State createState() => _MoodTextAreaWidget(); } -class _MoodTextAreaWidgetState extends State { +class _MoodTextAreaWidget extends State { late TextEditingController _controller; final FocusNode _focusNode = FocusNode(); late bool _isEditingEnabled; @@ -70,7 +70,6 @@ class _MoodTextAreaWidgetState extends State { @override Widget build(BuildContext context) { - print("initialtext######${widget.initialText}"); if (!_isEditingEnabled) _controller.text = widget.initialText; return TextField( controller: _controller, diff --git a/lib/utils/widgets/QuestionSliderWidget.dart b/lib/utils/widgets/question_slider_widget.dart similarity index 91% rename from lib/utils/widgets/QuestionSliderWidget.dart rename to lib/utils/widgets/question_slider_widget.dart index 05fd392..2689e16 100644 --- a/lib/utils/widgets/QuestionSliderWidget.dart +++ b/lib/utils/widgets/question_slider_widget.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; -import 'package:moody/utils/logic/QuestionGenerator.dart'; +import 'package:moody/utils/logic/question_generator.dart'; class QuestionSliderWidget extends StatefulWidget { final DateTime date; @@ -11,7 +11,7 @@ class QuestionSliderWidget extends StatefulWidget { final ValueChanged onSliderPositionChanged; final Color sliderColor; // parameter for the color - QuestionSliderWidget({ + const QuestionSliderWidget({ Key? key, required this.date, required this.questionText, @@ -23,10 +23,10 @@ class QuestionSliderWidget extends StatefulWidget { }) : super(key: key); @override - _QuestionSliderWidgetState createState() => _QuestionSliderWidgetState(); + State createState() => _QuestionSliderWidget(); } -class _QuestionSliderWidgetState extends State { +class _QuestionSliderWidget extends State { bool _showDragText = true; SliderChangeData? _sliderData; QuestionGenerator generator = QuestionGenerator(); @@ -38,7 +38,6 @@ class _QuestionSliderWidgetState extends State { super.initState(); //_sliderData?.value = widget.initialSliderValue; _sliderData = SliderChangeData(widget.initialSliderValue, 0); - print("innit"); if (!widget.isSliderEnabled) { _showDragText = false; } @@ -51,13 +50,11 @@ class _QuestionSliderWidgetState extends State { } else { if (!initValSet && changedInitValue != widget.initialSliderValue) { initValSet = true; - print("here"); changedInitValue != widget.initialSliderValue; _sliderData?.value = widget.initialSliderValue; } } - print(_sliderData?.value); return Padding( padding: const EdgeInsets.fromLTRB(0, 150, 20, 0), child: Column( @@ -72,12 +69,12 @@ class _QuestionSliderWidgetState extends State { children: [ Text( DateFormat('dd MM yyyy').format(widget.date), - style: TextStyle(fontSize: 18), + style: const TextStyle(fontSize: 18), ), - SizedBox(height: 10), + const SizedBox(height: 10), Text( widget.questionText == "" ? generator.getQuestionByDate(widget.date) : widget.questionText, - style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold), + style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold), ), ], ), @@ -91,7 +88,7 @@ class _QuestionSliderWidgetState extends State { data: SliderTheme.of(context).copyWith( disabledThumbColor: Colors.transparent, activeTrackColor: widget.sliderColor, - trackShape: RectangularSliderTrackShape(), + trackShape: const RectangularSliderTrackShape(), inactiveTickMarkColor: Colors.transparent, inactiveTrackColor: Colors.transparent, valueIndicatorColor: Colors.transparent, diff --git a/lib/utils/widgets/WhyWidget.dart b/lib/utils/widgets/why_widget.dart similarity index 93% rename from lib/utils/widgets/WhyWidget.dart rename to lib/utils/widgets/why_widget.dart index a2078fb..e4a630e 100644 --- a/lib/utils/widgets/WhyWidget.dart +++ b/lib/utils/widgets/why_widget.dart @@ -4,17 +4,17 @@ class WhyWidget extends StatefulWidget { final TextEditingController controller; final bool prependWhy; - WhyWidget({ + const WhyWidget({ Key? key, required this.controller, this.prependWhy = true, }) : super(key: key); @override - _WhyWidgetState createState() => _WhyWidgetState(); + State createState() => _WhyWidget(); } -class _WhyWidgetState extends State { +class _WhyWidget extends State { //final TextEditingController _controller = TextEditingController(text: "warum? "); final FocusNode _focusNode = FocusNode(); diff --git a/lib/views/color_page/color_page.dart b/lib/views/color_page/color_page.dart index 1e6ece5..3843071 100644 --- a/lib/views/color_page/color_page.dart +++ b/lib/views/color_page/color_page.dart @@ -1,19 +1,21 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import '../../utils/definitions/ColorPairs.dart'; +import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/BottomNavigationWidget.dart'; +import '../../utils/logic/preferences_service.dart'; +import '../../utils/widgets/custom_bottom_navigation_bar.dart'; // ...Include PreferencesService and other necessary imports class ColorPage extends StatefulWidget { + const ColorPage({super.key}); + @override - _ColorPageState createState() => _ColorPageState(); + State createState() => _ColorPage(); } -class _ColorPageState extends State { +class _ColorPage extends State { int? selectedColorIndex; // Index of the selected color @override @@ -25,20 +27,13 @@ class _ColorPageState extends State { // Load selected color from preferences void _loadSelectedColor() async { ColorPair? savedColorPair = await PreferencesService().loadColorPair(); - if (savedColorPair != null) { - // Find the index of the saved color in the colorPairs list - int index = colorPairs.indexWhere( - (pair) => pair.backgroundColor.value == savedColorPair.backgroundColor.value && pair.textColor.value == savedColorPair.textColor.value, - ); - if (index != -1) { - setState(() { - selectedColorIndex = index; - }); - } - } else { - // If no color is selected, default to the first one + // Find the index of the saved color in the colorPairs list + int index = colorPairs.indexWhere( + (pair) => pair.backgroundColor.value == savedColorPair.backgroundColor.value && pair.textColor.value == savedColorPair.textColor.value, + ); + if (index != -1) { setState(() { - selectedColorIndex = 0; + selectedColorIndex = index; }); } } @@ -83,7 +78,7 @@ class _ColorPageState extends State { ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 2), + floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 2), ); } @@ -101,7 +96,7 @@ class _ColorPageState extends State { child: Container( width: bubbleWidth, height: bubbleWidth, - padding: EdgeInsets.all(10), // Padding for inner circle effect + padding: const EdgeInsets.all(10), // Padding for inner circle effect decoration: BoxDecoration( color: colorPairs[index].backgroundColor, shape: BoxShape.circle, diff --git a/lib/views/entry_view/entry_page.dart b/lib/views/entry_view/entry_page.dart index 9e722c0..7c4c63c 100644 --- a/lib/views/entry_view/entry_page.dart +++ b/lib/views/entry_view/entry_page.dart @@ -2,24 +2,24 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; -import '../../utils/CirclePainter.dart'; -import '../../utils/definitions/ColorPairs.dart'; +import '../../utils/circle_painter.dart'; +import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/BottomNavigationWidget.dart'; -import '../../utils/widgets/MoodTextArea.dart'; -import '../../utils/widgets/QuestionSliderWidget.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; - EntryPage({Key? key, required this.date}) : super(key: key); + const EntryPage({Key? key, required this.date}) : super(key: key); @override - _EntryPageState createState() => _EntryPageState(); + State createState() => _EntryPage(); } -class _EntryPageState extends State { +class _EntryPage extends State { SliderChangeData sliderData = SliderChangeData(0, 0); String _moodText = ""; final PreferencesService _prefsService = PreferencesService(); @@ -59,7 +59,7 @@ class _EntryPageState extends State { }); } // _textController.text = _moodText; - _textController.text = currentEntry != null ? currentEntry!.texts.join(" ") : _moodText; + _textController.text = (currentEntry != null ? currentEntry.texts.join(" ") : _moodText); } void _toggleEdit() { @@ -72,7 +72,7 @@ class _EntryPageState extends State { } void _saveEntry() async { - print("saveEntry...."); + //print("saveEntry...."); Todo for future versions } @override @@ -114,11 +114,11 @@ class _EntryPageState extends State { child: Column( children: [ Text( - sliderData.value.toString() + "%", - style: TextStyle(color: Colors.black), + "${sliderData.value}%", + style: const TextStyle(color: Colors.black), ), Text(DateFormat('dd MM yyyy').format(widget.date).toString(), - style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold)), + style: const TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold)), ], ), ), @@ -138,7 +138,7 @@ class _EntryPageState extends State { style: TextStyle(fontSize: 18, color: textColor), // Use appropriate styling ), ), - SizedBox(height: 400), // Space for floating bottom navigation bar + const SizedBox(height: 400), // Space for floating bottom navigation bar ], ), ], @@ -146,7 +146,7 @@ class _EntryPageState extends State { ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 0), + floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0), ); } } diff --git a/lib/views/first_page/first_page.dart b/lib/views/first_page/first_page.dart index e7217f4..ef2e8d8 100644 --- a/lib/views/first_page/first_page.dart +++ b/lib/views/first_page/first_page.dart @@ -1,11 +1,12 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:moody/utils/widgets/QuestionSliderWidget.dart'; +import 'package:moody/utils/widgets/question_slider_widget.dart'; -import '../../utils/CirclePainter.dart'; -import '../../utils/definitions/ColorPairs.dart'; +import '../../utils/circle_painter.dart'; +import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; +import '../../utils/logic/preferences_service.dart'; class FirstPage extends StatefulWidget { final bool showSkipText; // Add this line @@ -14,10 +15,10 @@ class FirstPage extends StatefulWidget { : super(key: key); @override - _FirstPageState createState() => _FirstPageState(); + State createState() => _FirstPage(); } -class _FirstPageState extends State { +class _FirstPage extends State { SliderChangeData sliderData = SliderChangeData(0, 50); bool _sliderChanged = false; final PreferencesService _prefsService = PreferencesService(); @@ -33,9 +34,9 @@ class _FirstPageState extends State { } void _checkExistingEntry() async { - WidgetsBinding.instance?.addPostFrameCallback((_) async { + WidgetsBinding.instance.addPostFrameCallback((_) async { DiaryEntry? entry = await _prefsService.getDiaryEntryByCurrentDate(); - if (entry != null) { + if (entry != null && mounted) { context.go('/home'); } }); @@ -60,7 +61,9 @@ class _FirstPageState extends State { await _prefsService.saveDiaryEntry(entry); } catch (e) { - print("Error saving entry: $e"); // Consider showing an error dialog or toast instead + if (kDebugMode) { + print("Error saving entry: $e"); + } // Consider showing an error dialog or toast instead } } @@ -91,7 +94,7 @@ class _FirstPageState extends State { children: [ QuestionSliderWidget( onSliderPositionChanged: (value) { - print("sliderposchanged"); + //print("slider Moved"); }, sliderColor: textColor, date: DateTime.now(), @@ -129,7 +132,6 @@ class _FirstPageState extends State { right: 20, child: TextButton( onPressed: () { - print(_sliderChanged); if (_sliderChanged) { _saveEntry(); context.go('/home', extra: sliderData.value); @@ -141,7 +143,7 @@ class _FirstPageState extends State { ? Text("save.", style: TextStyle(fontSize: 18, color: textColor)) : widget.showSkipText // Use the showSkipText parameter ? const Text("skip", style: TextStyle(fontSize: 18, color: Colors.grey)) - : SizedBox.shrink(), + : const SizedBox.shrink(), ), ), ], diff --git a/lib/views/first_page/widgets/drag_widget.dart b/lib/views/first_page/widgets/drag_widget.dart index ad42bc2..4c1ce17 100644 --- a/lib/views/first_page/widgets/drag_widget.dart +++ b/lib/views/first_page/widgets/drag_widget.dart @@ -1,13 +1,15 @@ import 'package:flutter/material.dart'; -import '../../../utils/CirclePainter.dart'; +import '../../../utils/circle_painter.dart'; class DragWidget extends StatefulWidget { + const DragWidget({super.key}); + @override - _DragWidgetState createState() => _DragWidgetState(); + State createState() => _DragWidget(); } -class _DragWidgetState extends State { +class _DragWidget extends State { double _sliderValue = 0.0; @override @@ -28,7 +30,7 @@ class _DragWidgetState extends State { padding: const EdgeInsets.only(top: 20.0, left: 20.0), child: Text( "${DateTime.now().toLocal()}", - style: TextStyle(fontSize: 18), + style: const TextStyle(fontSize: 18), ), ), const Padding( @@ -38,7 +40,7 @@ class _DragWidgetState extends State { style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold), ), ), - SizedBox(height: 32), // 2 line padding + const SizedBox(height: 32), // 2 line padding SliderTheme( data: SliderTheme.of(context).copyWith( trackShape: CustomTrackShape(), @@ -57,10 +59,10 @@ class _DragWidgetState extends State { ), if (_sliderValue > 0) Padding( - padding: EdgeInsets.only(left: 20.0), + padding: const EdgeInsets.only(left: 20.0), child: Text( "${_sliderValue.toStringAsFixed(0)}%", - style: TextStyle(fontSize: 18), + style: const TextStyle(fontSize: 18), ), ), ], @@ -82,8 +84,7 @@ class CustomTrackShape extends RoundedRectSliderTrackShape { }) { final double trackHeight = sliderTheme.trackHeight ?? 4; final double trackLeft = offset.dx; - final double trackTop = - offset.dy + (parentBox.size.height - trackHeight) / 2; + final double trackTop = offset.dy + (parentBox.size.height - trackHeight) / 2; final double trackWidth = parentBox.size.width; return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight); } diff --git a/lib/views/home_page/home_page.dart b/lib/views/home_page/home_page.dart index 89c5a17..b8f57a4 100644 --- a/lib/views/home_page/home_page.dart +++ b/lib/views/home_page/home_page.dart @@ -1,13 +1,14 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:moody/utils/definitions/style_guide.dart'; import 'package:moody/views/first_page/first_page.dart'; -import '../../utils/CirclePainter.dart'; -import '../../utils/definitions/ColorPairs.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/BottomNavigationWidget.dart'; -import '../../utils/widgets/QuestionSliderWidget.dart'; -import '../../utils/widgets/WhyWidget.dart'; +import '../../utils/circle_painter.dart'; +import '../../utils/definitions/color_pair.dart'; +import '../../utils/logic/preferences_service.dart'; +import '../../utils/widgets/custom_bottom_navigation_bar.dart'; +import '../../utils/widgets/question_slider_widget.dart'; +import '../../utils/widgets/why_widget.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -18,7 +19,6 @@ class HomePage extends StatefulWidget { class _HomePageState extends State { SliderChangeData sliderData = SliderChangeData(0, 0); - String _moodText = ""; bool _isTextAreaEditable = false; final PreferencesService _prefsService = PreferencesService(); Color backgroundColor = Colors.lightGreenAccent; @@ -45,15 +45,11 @@ class _HomePageState extends State { void _loadCurrentDiaryEntry() async { DiaryEntry? currentEntry = await _prefsService.getDiaryEntryByCurrentDate(); if (currentEntry != null) { - print(currentEntry.texts.join(" ")); setState(() { sliderData.value = currentEntry.percentValue.toDouble(); - print(currentEntry.percentValue); - _moodText = currentEntry.texts.join(" "); // Assuming you want to concatenate all texts _textController.text = currentEntry.texts.join(" "); }); setState(() {}); - print(sliderData.value); } else { setState(() { noData = true; @@ -73,7 +69,6 @@ class _HomePageState extends State { void _saveEntry() async { try { List texts = _textController.text.isEmpty ? [] : [_textController.text]; - print("DerText:${_textController.text}"); DiaryEntry entry = DiaryEntry( date: DateTime.now(), percentValue: sliderData.value.toInt(), @@ -82,15 +77,17 @@ class _HomePageState extends State { await _prefsService.saveDiaryEntry(entry); } catch (e) { - print("Error saving entry: $e"); + if (kDebugMode) { + print("Error saving entry: $e"); + } } } @override Widget build(BuildContext context) { return noData - ? Scaffold( - body: const FirstPage(showSkipText: false), + ? const Scaffold( + body: FirstPage(showSkipText: false), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 1), ) @@ -113,7 +110,7 @@ class _HomePageState extends State { children: [ QuestionSliderWidget( onSliderPositionChanged: (value) { - print("sliderposchanged"); + //print("Slider moved"); }, sliderColor: textColor, date: DateTime.now(), @@ -169,7 +166,7 @@ class _HomePageState extends State { ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 1), + floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 1), ); } } diff --git a/lib/views/home_page/kalendartryhome_page.dart b/lib/views/home_page/kalendartryhome_page.dart deleted file mode 100644 index dd08dca..0000000 --- a/lib/views/home_page/kalendartryhome_page.dart +++ /dev/null @@ -1,100 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; - -void main() => runApp(MyApp()); - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - home: CalendarPage(), - ); - } -} - -class CalendarPage extends StatefulWidget { - @override - _CalendarPageState createState() => _CalendarPageState(); -} - -class _CalendarPageState extends State { - DateTime currentDate = DateTime.now(); - late List dateList; - - @override - void initState() { - super.initState(); - dateList = _generateDateList(currentDate); - } - - List _generateDateList(DateTime date) { - List list = []; - DateTime firstOfMonth = DateTime(date.year, date.month, 1); - int dayOfWeek = firstOfMonth.weekday; - - // Adjust to Monday start - int startDay = dayOfWeek - 1; - if (startDay < 0) startDay = 6; - - // Dates from previous month - for (int i = startDay; i > 0; i--) { - list.add(firstOfMonth.subtract(Duration(days: i))); - } - - // Dates of current month - int daysInMonth = DateUtils.getDaysInMonth(date.year, date.month); - for (int i = 0; i < daysInMonth; i++) { - list.add(DateTime(date.year, date.month, i + 1)); - } - - return list; - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("Calendar"), - ), - body: GridView.builder( - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 7, - ), - itemBuilder: (context, index) { - double radius = - (Random().nextInt(50).toDouble() + 20) / 2; // Reduced by 50% - DateTime date = dateList[index]; - return Center( - child: Container( - width: radius * 2, - height: radius * 2, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: Border.all(color: Colors.black, width: 2), - ), - child: Center( - child: Container( - width: radius, - height: radius, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.lightGreen, - ), - child: Center( - child: Text( - DateFormat("d").format(date), - style: TextStyle(color: Colors.black), - ), - ), - ), - ), - ), - ); - }, - itemCount: dateList.length, - ), - ); - } -} diff --git a/lib/views/settings_page/settings_page.dart b/lib/views/settings_page/settings_page.dart index 93feca3..2ba5aa6 100644 --- a/lib/views/settings_page/settings_page.dart +++ b/lib/views/settings_page/settings_page.dart @@ -2,18 +2,20 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/BottomNavigationWidget.dart'; -import 'widgets/CustomDivider.dart'; -import 'widgets/SetPinPopup.dart'; -import 'widgets/TextSwitchContainer.dart'; +import '../../utils/logic/preferences_service.dart'; +import '../../utils/widgets/custom_bottom_navigation_bar.dart'; +import 'widgets/custom_divider_widget.dart'; +import 'widgets/set_pin_popup_widget.dart'; +import 'widgets/text_switch_container_widget.dart'; class SettingsPage extends StatefulWidget { + const SettingsPage({super.key}); + @override - _SettingsPageState createState() => _SettingsPageState(); + State createState() => _SettingsPage(); } -class _SettingsPageState extends State { +class _SettingsPage extends State { bool isPinEnabled = false; // Default to false @override @@ -32,7 +34,7 @@ class _SettingsPageState extends State { return Scaffold( backgroundColor: AppStyle.backgroundColor, body: Container( - padding: EdgeInsets.only(bottom: 0), + padding: const EdgeInsets.only(bottom: 0), margin: const EdgeInsets.fromLTRB(30, 30, 30, 0), child: SingleChildScrollView( child: Column( @@ -43,20 +45,20 @@ class _SettingsPageState extends State { // Settings section Container( - margin: EdgeInsets.only(bottom: 10), + margin: const EdgeInsets.only(bottom: 10), alignment: Alignment.topLeft, - child: Text('settings', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), + child: const Text('settings', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), ), TextSwitchContainer( leftText: "change color", onTap: () => context.go("/color"), ), - CustomDivider(), + const CustomDivider(), FutureBuilder( future: PreferencesService().isPinEnabled(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { - return CircularProgressIndicator(); // or some other placeholder + return const CircularProgressIndicator(); // or some other placeholder } bool pinEnabled = snapshot.data ?? false; // Default to false if null return TextSwitchContainer( @@ -75,63 +77,63 @@ class _SettingsPageState extends State { ); }, ), - CustomDivider(), + const CustomDivider(), TextSwitchContainer( leftText: "your data", - onTap: () => print('Container tapped'), + onTap: () => {}, ), // Community section Padding( padding: const EdgeInsets.fromLTRB(0, 50, 0, 10), child: Container( alignment: Alignment.topLeft, - margin: EdgeInsets.only(bottom: 10), - child: Text('community', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), + margin: const EdgeInsets.only(bottom: 10), + child: const Text('community', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), ), ), TextSwitchContainer( leftText: "join our discord", rightText: "fulfilled", - onTap: () => print('Container tapped'), + onTap: () => {}, ), - CustomDivider(), + const CustomDivider(), TextSwitchContainer( leftText: "our instagram", rightText: "@get.fulfilled", - onTap: () => print('Container tapped'), + onTap: () => {}, ), - CustomDivider(), + const CustomDivider(), TextSwitchContainer( leftText: "share fulfilled with your loved ones", - onTap: () => print('Container tapped'), + onTap: () => {}, ), Padding( padding: const EdgeInsets.fromLTRB(0, 50, 0, 10), child: Container( alignment: Alignment.topLeft, - child: Text('humans behind fulfilled', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), + child: const Text('humans behind fulfilled', style: TextStyle(fontWeight: FontWeight.w500, fontSize: 24)), ), ), TextSwitchContainer( leftText: "about us", - onTap: () => print('Container tapped'), + onTap: () => {}, ), - CustomDivider(), + const CustomDivider(), TextSwitchContainer( leftText: "support us", - onTap: () => print('Container tapped'), + onTap: () => {}, ), - CustomDivider(), + const CustomDivider(), TextSwitchContainer( leftText: "give feedback", - onTap: () => print('Container tapped'), + onTap: () => {}, ), // ListTile( - title: Text('imprint & privacy policy', style: TextStyle(color: Colors.grey, fontSize: 15)), + title: const Text('imprint & privacy policy', style: TextStyle(color: Colors.grey, fontSize: 15)), onTap: () => {}, // Implement your logic ), - SizedBox( + const SizedBox( height: 150, ) ], @@ -139,7 +141,7 @@ class _SettingsPageState extends State { ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 2), + floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 2), ); } @@ -147,7 +149,7 @@ class _SettingsPageState extends State { showDialog( context: context, builder: (BuildContext context) { - return SetPinPopup(); + return const SetPinPopup(); }, ); } diff --git a/lib/views/settings_page/widgets/CustomDivider.dart b/lib/views/settings_page/widgets/custom_divider_widget.dart similarity index 100% rename from lib/views/settings_page/widgets/CustomDivider.dart rename to lib/views/settings_page/widgets/custom_divider_widget.dart diff --git a/lib/views/settings_page/widgets/SetPinPopup.dart b/lib/views/settings_page/widgets/set_pin_popup_widget.dart similarity index 73% rename from lib/views/settings_page/widgets/SetPinPopup.dart rename to lib/views/settings_page/widgets/set_pin_popup_widget.dart index 000057a..925401d 100644 --- a/lib/views/settings_page/widgets/SetPinPopup.dart +++ b/lib/views/settings_page/widgets/set_pin_popup_widget.dart @@ -3,20 +3,21 @@ import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import '../../../utils/logic/PreferencesService.dart'; // For HapticFeedback +import '../../../utils/logic/preferences_service.dart'; // For HapticFeedback // ...Include PreferencesService and other necessary imports class SetPinPopup extends StatefulWidget { + const SetPinPopup({super.key}); + @override - _SetPinPopupState createState() => _SetPinPopupState(); + State createState() => _SetPinPopup(); } -class _SetPinPopupState extends State { +class _SetPinPopup extends State { String _pin = ''; String _confirmedPin = ''; - bool _isSettingPin = - true; // True if setting the PIN, false if confirming the PIN + bool _isSettingPin = true; // True if setting the PIN, false if confirming the PIN static const int pinLength = 4; @@ -55,12 +56,11 @@ class _SetPinPopupState extends State { Widget _buildNumberButton(int number) { return GestureDetector( onTap: () => _onNumberTap(number), - onTapDown: (_) => - HapticFeedback.lightImpact(), // Cool haptic feedback on tap + onTapDown: (_) => HapticFeedback.lightImpact(), // Cool haptic feedback on tap child: Container( width: 70, height: 70, - margin: EdgeInsets.all(10), + margin: const EdgeInsets.all(10), decoration: BoxDecoration( color: Colors.white, border: Border.all(color: Colors.black), @@ -69,7 +69,7 @@ class _SetPinPopupState extends State { child: Center( child: Text( number.toString(), - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold), ), ), ), @@ -85,8 +85,7 @@ class _SetPinPopupState extends State { } }); - if ((_isSettingPin && _pin.length == pinLength) || - (!_isSettingPin && _confirmedPin.length == pinLength)) { + if ((_isSettingPin && _pin.length == pinLength) || (!_isSettingPin && _confirmedPin.length == pinLength)) { if (!_isSettingPin && _pin == _confirmedPin) { // Call setPin and enablePin methods, assuming they are async PreferencesService().setPin(int.parse(_pin)); @@ -117,35 +116,28 @@ class _SetPinPopupState extends State { child: Container( height: 600, width: 400, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(50))), + decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(50))), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(_isSettingPin ? 'Set a PIN' : 'Repeat PIN', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), - SizedBox(height: 20), + Text(_isSettingPin ? 'Set a PIN' : 'Repeat PIN', style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), + const SizedBox(height: 20), Row( mainAxisSize: MainAxisSize.min, children: List.generate(pinLength, (index) { return Container( - margin: EdgeInsets.all(4), + margin: const EdgeInsets.all(4), width: 15, height: 15, decoration: BoxDecoration( - color: - (_isSettingPin ? _pin.length : _confirmedPin.length) > - index - ? Colors.black - : Colors.transparent, + color: (_isSettingPin ? _pin.length : _confirmedPin.length) > index ? Colors.black : Colors.transparent, border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(15), ), ); }), ), - SizedBox(height: 20), + const SizedBox(height: 20), ..._buildNumberPad(), ], ), diff --git a/lib/views/settings_page/widgets/SettingsSelectionWdiget.dart b/lib/views/settings_page/widgets/settings_selection_widget.dart similarity index 67% rename from lib/views/settings_page/widgets/SettingsSelectionWdiget.dart rename to lib/views/settings_page/widgets/settings_selection_widget.dart index c3db618..2a73d47 100644 --- a/lib/views/settings_page/widgets/SettingsSelectionWdiget.dart +++ b/lib/views/settings_page/widgets/settings_selection_widget.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -5,8 +6,7 @@ class SettingsSection extends StatelessWidget { final String title; final List items; - SettingsSection({Key? key, required this.title, required this.items}) - : super(key: key); + const SettingsSection({Key? key, required this.title, required this.items}) : super(key: key); @override Widget build(BuildContext context) { @@ -14,11 +14,10 @@ class SettingsSection extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( - padding: EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), child: Text( title, - style: TextStyle( - fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black), + style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black), ), ), ...items.map((item) => _buildItem(item)).toList(), @@ -36,9 +35,9 @@ class SettingsSection extends StatelessWidget { ? GestureDetector( child: Text( item.trailingText ?? "", - style: TextStyle(color: Colors.grey), + style: const TextStyle(color: Colors.grey), ), - onTap: () => _launchURL(item.url!), + onTap: () => _launchURL(Uri.parse(item.url!)), ) : null, onTap: item.onTap, @@ -47,11 +46,13 @@ class SettingsSection extends StatelessWidget { ); } - void _launchURL(String url) async { - if (await canLaunch(url)) { - await launch(url); + void _launchURL(Uri url) async { + if (await canLaunchUrl(url)) { + await launchUrl(url); } else { - print("Could not launch $url"); + if (kDebugMode) { + print("Could not launch $url"); + } } } } diff --git a/lib/views/settings_page/widgets/TextSwitchContainer.dart b/lib/views/settings_page/widgets/text_switch_container_widget.dart similarity index 57% rename from lib/views/settings_page/widgets/TextSwitchContainer.dart rename to lib/views/settings_page/widgets/text_switch_container_widget.dart index b798f34..e2b660a 100644 --- a/lib/views/settings_page/widgets/TextSwitchContainer.dart +++ b/lib/views/settings_page/widgets/text_switch_container_widget.dart @@ -1,15 +1,19 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import '../../../utils/definitions/color_pair.dart'; +import '../../../utils/logic/preferences_service.dart'; + class TextSwitchContainer extends StatefulWidget { final String leftText; final String? rightText; final bool hasSwitch; final Function onTap; final Function(bool)? onSwitchToggle; - final bool switchDefaultValue; // Added parameter for the default switch value + final bool switchDefaultValue; // Parameter for the default switch value - TextSwitchContainer({ + const TextSwitchContainer({ + super.key, required this.leftText, this.rightText, this.hasSwitch = false, @@ -19,33 +23,46 @@ class TextSwitchContainer extends StatefulWidget { }); @override - _TextSwitchContainerState createState() => - _TextSwitchContainerState(switchValue: this.switchDefaultValue); + State createState() => _TextSwitchContainer(); } -class _TextSwitchContainerState extends State { - bool switchValue; // No longer explicitly initialized here +class _TextSwitchContainer extends State { + late bool switchValue; + Color backgroundColor = Colors.white; // Default value + Color textColor = Colors.black; // Default value - _TextSwitchContainerState( - {required this.switchValue}); // Constructor takes the initial switch value + @override + void initState() { + super.initState(); + switchValue = widget.switchDefaultValue; // Initialize switchValue here + _loadColor(); + } + + void _loadColor() async { + ColorPair colorPair = await PreferencesService().loadColorPair(); + setState(() { + backgroundColor = colorPair.backgroundColor; + textColor = colorPair.textColor; + }); + } @override Widget build(BuildContext context) { return GestureDetector( onTap: () => widget.onTap(), child: Container( - padding: EdgeInsets.symmetric(horizontal: 0, vertical: 20), + padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 20), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( widget.leftText, - style: TextStyle(fontSize: 18), + style: const TextStyle(fontSize: 18), ), if (widget.hasSwitch) CupertinoSwitch( trackColor: Colors.white, - thumbColor: switchValue ? Colors.lightGreen : Colors.grey, + thumbColor: switchValue ? backgroundColor : Colors.grey, value: switchValue, onChanged: (newValue) { setState(() { @@ -60,7 +77,7 @@ class _TextSwitchContainerState extends State { else if (widget.rightText != null) Text( widget.rightText!, - style: TextStyle(fontSize: 16, color: Colors.grey), + style: const TextStyle(fontSize: 16, color: Colors.grey), ), ], ), diff --git a/lib/views/start_page/start_page.dart b/lib/views/start_page/start_page.dart index 681e5e6..eebb1b2 100644 --- a/lib/views/start_page/start_page.dart +++ b/lib/views/start_page/start_page.dart @@ -1,14 +1,17 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:go_router/go_router.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; // For Haptic Feedback +import '../../utils/logic/preferences_service.dart'; // For Haptic Feedback class StartPage extends StatelessWidget { + const StartPage({super.key}); + @override Widget build(BuildContext context) { - return MaterialApp( + return const MaterialApp( title: 'PIN Input', home: PinInputScreen(), ); @@ -16,11 +19,13 @@ class StartPage extends StatelessWidget { } class PinInputScreen extends StatefulWidget { + const PinInputScreen({super.key}); + @override - _PinInputScreenState createState() => _PinInputScreenState(); + State createState() => _PinInputScreen(); } -class _PinInputScreenState extends State { +class _PinInputScreen extends State { String _pin = ''; static const int pinLength = 4; @@ -31,11 +36,13 @@ class _PinInputScreenState extends State { } Future _checkPinStatus() async { - bool pinEnabled = await PreferencesService().isPinEnabled(); // Adjust with actual implementation + bool pinEnabled = await PreferencesService().isPinEnabled(); if (!pinEnabled) { - // If no PIN is enabled, navigate to the "/first" route. - // Navigator context will be available after the widget build. - Future.microtask(() => context.go("/first")); + Future.microtask(() { + if (mounted) { + context.go("/first"); + } + }); } } @@ -61,12 +68,15 @@ class _PinInputScreenState extends State { Future _validatePin() async { bool correct = await checkPin(int.parse(_pin)); if (correct) { - print("Right"); - context.go("/first"); + if (mounted) { + context.go("/first"); + } // Perform any actions you need on successful pin entry } else { // Handle wrong pin entry, e.g., reset pin, show error, etc. - print("Wrong PIN"); + if (kDebugMode) { + print("Wrong PIN"); + } } // Resetting the PIN for this example, you might want to do this differently @@ -91,17 +101,17 @@ class _PinInputScreenState extends State { child: Container( height: 600, width: 400, - decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(50))), + decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(50))), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text('Welcome Back!', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), - SizedBox(height: 20), + const Text('Welcome Back!', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), + const SizedBox(height: 20), Row( mainAxisSize: MainAxisSize.min, children: List.generate(pinLength, (index) { return Container( - margin: EdgeInsets.all(4), + margin: const EdgeInsets.all(4), width: 15, height: 15, decoration: BoxDecoration( @@ -112,7 +122,7 @@ class _PinInputScreenState extends State { ); }), ), - SizedBox(height: 20), + const SizedBox(height: 20), ..._buildNumberPad(), ], ), @@ -160,7 +170,7 @@ class _PinInputScreenState extends State { child: Container( width: 70, height: 70, - margin: EdgeInsets.all(10), + margin: const EdgeInsets.all(10), decoration: BoxDecoration( border: Border.all(color: Colors.black), borderRadius: BorderRadius.circular(35), @@ -168,7 +178,7 @@ class _PinInputScreenState extends State { child: Center( child: Text( number.toString(), - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold), ), ), ), diff --git a/lib/views/statistic/statistic_page.dart b/lib/views/statistic/statistic_page.dart index a646f3d..5b91e9c 100644 --- a/lib/views/statistic/statistic_page.dart +++ b/lib/views/statistic/statistic_page.dart @@ -2,17 +2,19 @@ import 'package:flutter/material.dart'; import 'package:moody/views/statistic/widget/calendar_widget.dart'; import 'package:moody/views/statistic/widget/streak_widget.dart'; -import '../../utils/definitions/ColorPairs.dart'; +import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/BottomNavigationWidget.dart'; +import '../../utils/logic/preferences_service.dart'; +import '../../utils/widgets/custom_bottom_navigation_bar.dart'; class StatisticPage extends StatefulWidget { + const StatisticPage({super.key}); + @override - _StatisticPageState createState() => _StatisticPageState(); + State createState() => _StatisticPage(); } -class _StatisticPageState extends State { +class _StatisticPage extends State { Color backgroundColor = Colors.white; // Default fallback color Color textColor = Colors.black; // Default fallback color final ScrollController _scrollController = ScrollController(); @@ -47,7 +49,7 @@ class _StatisticPageState extends State { child: Scaffold( backgroundColor: AppStyle.backgroundColor, body: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - SizedBox( + const SizedBox( height: 50, ), Column( @@ -61,11 +63,11 @@ class _StatisticPageState extends State { color: backgroundColor, ); } else { - return CircularProgressIndicator(); // or some placeholder + return const CircularProgressIndicator(); // or some placeholder } }, ), - Text( + const Text( "browse your memories!", style: TextStyle(fontSize: 24), ), @@ -76,11 +78,11 @@ class _StatisticPageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ - SizedBox(height: 50), - Container(child: CalendarWidget(currentDate: DateTime(DateTime.now().year, DateTime.now().month - 2, 1))), - Container(child: CalendarWidget(currentDate: DateTime(DateTime.now().year, DateTime.now().month - 1, 1))), - Container(child: CalendarWidget(currentDate: DateTime.now())), - SizedBox( + const SizedBox(height: 50), + CalendarWidget(currentDate: DateTime(DateTime.now().year, DateTime.now().month - 2, 1)), + CalendarWidget(currentDate: DateTime(DateTime.now().year, DateTime.now().month - 1, 1)), + CalendarWidget(currentDate: DateTime.now()), + const SizedBox( height: 50, ) ], @@ -89,7 +91,7 @@ class _StatisticPageState extends State { ), ]), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 0), + floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0), ), ), ); diff --git a/lib/views/statistic/widget/calendar_widget.dart b/lib/views/statistic/widget/calendar_widget.dart index 2b52fe6..c27e025 100644 --- a/lib/views/statistic/widget/calendar_widget.dart +++ b/lib/views/statistic/widget/calendar_widget.dart @@ -2,19 +2,19 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; -import '../../../utils/definitions/ColorPairs.dart'; -import '../../../utils/logic/PreferencesService.dart'; // Correct the path as necessary +import '../../../utils/definitions/color_pair.dart'; +import '../../../utils/logic/preferences_service.dart'; // Correct the path as necessary class CalendarWidget extends StatefulWidget { final DateTime currentDate; - CalendarWidget({Key? key, required this.currentDate}) : super(key: key); + const CalendarWidget({Key? key, required this.currentDate}) : super(key: key); @override - _CalendarWidgetState createState() => _CalendarWidgetState(); + State createState() => _CalendarWidget(); } -class _CalendarWidgetState extends State { +class _CalendarWidget extends State { List dateList = []; // Initialized immediately as an empty list Map diaryEntries = {}; // Holds diary entries by date late ColorPair currentColorPair; // Holds the current color pair @@ -28,7 +28,7 @@ class _CalendarWidgetState extends State { void _loadColorPairAndDiaryData() async { // Load color pair - currentColorPair = await PreferencesService().loadColorPair() ?? colorPairs[0]; + currentColorPair = await PreferencesService().loadColorPair(); // Generate date list //dateList = _generateDateList(widget.currentDate); @@ -67,7 +67,7 @@ class _CalendarWidgetState extends State { // Adjust list to end with a complete week while (list.length % 7 != 0) { - list.add(list.last.add(Duration(days: 1))); + list.add(list.last.add(const Duration(days: 1))); } return list; @@ -82,24 +82,24 @@ class _CalendarWidgetState extends State { future: PreferencesService().loadColorPair(), builder: (context, snapshot) { if (!snapshot.hasData) { - return Center(child: CircularProgressIndicator()); + return const Center(child: CircularProgressIndicator()); } ColorPair colorPair = snapshot.data!; - return Container( + return SizedBox( height: 360 + addon, child: Column( children: [ Padding( - padding: EdgeInsets.symmetric(vertical: 8.0), - child: Text(monthName, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), // Month Header + padding: const EdgeInsets.symmetric(vertical: 8.0), + child: Text(monthName, style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), // Month Header ), Expanded( child: Padding( padding: const EdgeInsets.fromLTRB(25, 0, 25, 0), child: GridView.builder( - physics: NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + physics: const NeverScrollableScrollPhysics(), + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 7, ), itemBuilder: (context, index) { @@ -109,18 +109,23 @@ 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; return Center( child: GestureDetector( - onTap: () => {context.go('/entry', extra: date)}, + onTap: () { + DiaryEntry? entry = diaryEntries[DateFormat('yyyy-MM-dd').format(date)]; + if (entry != null) { + context.go('/entry', extra: date); + } else { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text("no entry there :("), + duration: Duration(seconds: 2), + ), + ); + } + }, child: Container( width: 50, height: 50, @@ -142,7 +147,7 @@ class _CalendarWidgetState extends State { DateTime.now().day == date.day && DateTime.now().month == date.month && DateTime.now().year == date.year ? "today" : DateFormat("d").format(date), - style: TextStyle(color: Colors.black), + style: const TextStyle(color: Colors.black), ), ], ), @@ -159,40 +164,13 @@ class _CalendarWidgetState extends State { ); }); } - - Widget _buildDateCell(DateTime date, DiaryEntry? entry) { - bool isCurrentMonth = date.month == widget.currentDate.month; - double opacity = isCurrentMonth ? 1.0 : 0.5; - Color bgColor = entry != null ? currentColorPair.backgroundColor.withOpacity(opacity) : Colors.transparent; - double fillPercentage = entry != null ? entry.percentValue / 100 : 0; // Assuming percentValue is 0-100 - - return GestureDetector( - onTap: () { - context.go('/entry', extra: date); - }, - child: Container( - child: Stack( - alignment: Alignment.center, - children: [ - CircleWidget( - radius: 25 * fillPercentage, // Adjust radius based on value - color: fillPercentage > 0 ? currentColorPair.backgroundColor : Colors.grey.withOpacity(opacity)), - Text( - DateFormat("d").format(date), - style: TextStyle(color: Colors.black), - ), - ], - ), - ), - ); - } } class CircleWidget extends StatelessWidget { final double radius; final Color color; - CircleWidget({Key? key, required this.radius, required this.color}) : super(key: key); + const CircleWidget({Key? key, required this.radius, required this.color}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/views/statistic/widget/streak_widget.dart b/lib/views/statistic/widget/streak_widget.dart index 1a8d50b..f12069c 100644 --- a/lib/views/statistic/widget/streak_widget.dart +++ b/lib/views/statistic/widget/streak_widget.dart @@ -4,7 +4,7 @@ class StreakWidget extends StatelessWidget { final int dayCount; final Color color; // Optional color parameter - StreakWidget({ + const StreakWidget({ Key? key, required this.dayCount, this.color = Colors.white, // Default to white if not provided diff --git a/lib/views/write_page/writeOld_page.dart b/lib/views/write_page/writeOld_page.dart deleted file mode 100644 index 4fe3fe2..0000000 --- a/lib/views/write_page/writeOld_page.dart +++ /dev/null @@ -1,81 +0,0 @@ -import 'package:flutter/material.dart'; - -class WritePageOLD extends StatefulWidget { - final double moodPercentage; - - const WritePageOLD({Key? key, required this.moodPercentage}) - : super(key: key); - - @override - _WritePageState createState() => _WritePageState(); -} - -class _WritePageState extends State { - final TextEditingController _textController = TextEditingController(); - bool _hasText = false; - - @override - void initState() { - super.initState(); - _textController.addListener(() { - setState(() { - _hasText = _textController.text.isNotEmpty; - }); - }); - } - - @override - void dispose() { - _textController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - body: SafeArea( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Displaying the mood percentage - Text( - "${widget.moodPercentage.toStringAsFixed(0)}%", - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - SizedBox(height: 8), - Text("Today", style: TextStyle(fontSize: 20)), - SizedBox(height: 4), - Text( - "Why was today only ${widget.moodPercentage.toStringAsFixed(0)}% good?", - style: TextStyle(fontSize: 16), - ), - SizedBox(height: 20), - // Text area - Expanded( - child: TextField( - controller: _textController, - maxLines: null, // Allows for unlimited lines - expands: true, - decoration: InputDecoration( - hintText: "Enter your thoughts here...", - border: OutlineInputBorder(), - ), - ), - ), - ], - ), - ), - ), - // Dynamic Save or Skip button - floatingActionButton: FloatingActionButton.extended( - onPressed: () { - // Implement save or skip functionality - }, - label: Text(_hasText ? 'Save' : 'Skip'), - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, - ); - } -} diff --git a/lib/views/write_page/write_page.dart b/lib/views/write_page/write_page.dart index f77dc58..d1639a9 100644 --- a/lib/views/write_page/write_page.dart +++ b/lib/views/write_page/write_page.dart @@ -1,22 +1,23 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; -import 'package:moody/utils/widgets/WhyWidget.dart'; +import 'package:moody/utils/widgets/why_widget.dart'; -import '../../utils/CirclePainter.dart'; -import '../../utils/definitions/ColorPairs.dart'; +import '../../utils/circle_painter.dart'; +import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; -import '../../utils/logic/PreferencesService.dart'; -import '../../utils/widgets/QuestionSliderWidget.dart'; +import '../../utils/logic/preferences_service.dart'; +import '../../utils/widgets/question_slider_widget.dart'; class WritePage extends StatefulWidget { final SliderChangeData sliderData; const WritePage({Key? key, required this.sliderData}) : super(key: key); @override - _WritePageState createState() => _WritePageState(); + State createState() => _WritePage(); } -class _WritePageState extends State { +class _WritePage extends State { SliderChangeData _sliderData = SliderChangeData(0, 0); final bool _sliderChanged = true; final PreferencesService _prefsService = PreferencesService(); @@ -43,7 +44,6 @@ class _WritePageState extends State { // Create a DiaryEntry object from the input try { List texts = _textController.text.isEmpty ? [] : [_textController.text]; - print("DerText:${_textController.text}"); DiaryEntry entry = DiaryEntry( date: DateTime.now(), // or some date picker value percentValue: _sliderData.value.toInt(), @@ -55,7 +55,9 @@ class _WritePageState extends State { // Handle successful save here, maybe show a snackbar or navigate away } catch (e) { // Handle any errors here, such as invalid percent value or failed save - print("Error saving entry: $e"); // Consider showing an error dialog or toast instead + if (kDebugMode) { + print("Error saving entry: $e"); + } // Consider showing an error dialog or toast instead } } diff --git a/test/my_app_test.dart b/test/my_app_test.dart new file mode 100644 index 0000000..2a1f64f --- /dev/null +++ b/test/my_app_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:moody/main.dart'; +import 'package:moody/utils/slide_direction.dart'; +import 'package:moody/views/settings_page/settings_page.dart'; + +void main() { + // Test for basic rendering of MyApp + testWidgets('MyApp renders correctly', (WidgetTester tester) async { + await tester.pumpWidget(const MyApp()); + expect(find.byType(MaterialApp), findsOneWidget); + }); + + // Test for route configuration + testWidgets('Navigating to /settings shows SettingsPage', (WidgetTester tester) async { + await tester.pumpWidget(const MyApp()); + await tester.tap(find.text('Settings')); + await tester.pumpAndSettle(); + expect(find.byType(SettingsPage), findsOneWidget); + }); + + // Test for custom logic - determineSlideDirection + test('determineSlideDirection returns correct SlideDirection', () { + expect(determineSlideDirection('/', '/settings'), equals(SlideDirection.left)); + // Add more test cases for different route combinations + }); +}