2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-01-13 17:07:11 +01:00
|
|
|
import 'package:moody/utils/widgets/no_Glow_scroll_behavior.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
import 'package:moody/views/statistic/widget/calendar_widget.dart';
|
|
|
|
import 'package:moody/views/statistic/widget/streak_widget.dart';
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
import '../../utils/definitions/color_pair.dart';
|
2024-01-08 19:34:48 +01:00
|
|
|
import '../../utils/definitions/style_guide.dart';
|
2024-01-09 12:34:44 +01:00
|
|
|
import '../../utils/logic/preferences_service.dart';
|
|
|
|
import '../../utils/widgets/custom_bottom_navigation_bar.dart';
|
2023-12-18 17:51:22 +01:00
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
class StatisticPage extends StatefulWidget {
|
2024-01-09 12:34:44 +01:00
|
|
|
const StatisticPage({super.key});
|
|
|
|
|
2024-01-08 19:34:48 +01:00
|
|
|
@override
|
2024-01-09 12:34:44 +01:00
|
|
|
State<StatisticPage> createState() => _StatisticPage();
|
2024-01-08 19:34:48 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:34:44 +01:00
|
|
|
class _StatisticPage extends State<StatisticPage> {
|
2024-01-08 19:34:48 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-17 23:00:31 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
2024-01-08 19:34:48 +01:00
|
|
|
home: SafeArea(
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor: AppStyle.backgroundColor,
|
|
|
|
body: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
2024-01-09 12:34:44 +01:00
|
|
|
const SizedBox(
|
2024-01-08 19:34:48 +01:00
|
|
|
height: 50,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
FutureBuilder<int>(
|
|
|
|
future: PreferencesService().calculateStreak(),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
|
|
return StreakWidget(
|
|
|
|
dayCount: snapshot.data!,
|
|
|
|
color: backgroundColor,
|
|
|
|
);
|
|
|
|
} else {
|
2024-01-09 12:34:44 +01:00
|
|
|
return const CircularProgressIndicator(); // or some placeholder
|
2024-01-08 19:34:48 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2024-01-09 12:34:44 +01:00
|
|
|
const Text(
|
2024-01-08 19:34:48 +01:00
|
|
|
"browse your memories!",
|
|
|
|
style: TextStyle(fontSize: 24),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
2024-01-13 17:07:11 +01:00
|
|
|
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,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2023-12-18 17:51:22 +01:00
|
|
|
),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
2024-01-09 12:34:44 +01:00
|
|
|
floatingActionButton: const CustomBottomNavigationBar(initialSelectedIndex: 0),
|
2024-01-08 19:34:48 +01:00
|
|
|
),
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|