import 'package:flutter/material.dart'; import 'package:moody/utils/widgets/no_Glow_scroll_behavior.dart'; import 'package:moody/views/statistic/widget/calendar_widget.dart'; import 'package:moody/views/statistic/widget/streak_widget.dart'; import '../../utils/definitions/color_pair.dart'; import '../../utils/definitions/style_guide.dart'; import '../../utils/logic/preferences_service.dart'; import '../../utils/widgets/custom_bottom_navigation_bar.dart'; class StatisticPage extends StatefulWidget { const StatisticPage({super.key}); @override State createState() => _StatisticPage(); } class _StatisticPage extends State { Color backgroundColor = Colors.white; // Default fallback color Color textColor = Colors.black; // Default fallback color final ScrollController _scrollController = ScrollController(); @override void initState() { super.initState(); _loadColor(); // Load the colors right when the widget is inserted into the tree WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom()); } void _loadColor() async { ColorPair colorPair = await PreferencesService().loadColorPair(); if (mounted) { setState(() { backgroundColor = colorPair.backgroundColor; textColor = colorPair.textColor; }); } } void _scrollToBottom() { if (_scrollController.hasClients) { _scrollController.jumpTo(_scrollController.position.maxScrollExtent); } } @override Widget build(BuildContext context) { return MaterialApp( home: SafeArea( child: Scaffold( backgroundColor: AppStyle.backgroundColor, body: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const SizedBox( height: 50, ), Column( children: [ FutureBuilder( future: PreferencesService().calculateStreak(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return StreakWidget( dayCount: snapshot.data!, color: backgroundColor, ); } else { return const CircularProgressIndicator(); // or some placeholder } }, ), const Text( "browse your memories!", style: TextStyle(fontSize: 24), ), ], ), Expanded( child: ScrollConfiguration( behavior: NoGlowScrollBehavior(), child: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ 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, ) ], ), ), ), ), ]), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0), ), ), ); } }