ModernMemoires/lib/views/statistic/statistic_page.dart

98 lines
3.4 KiB
Dart
Raw Normal View History

2023-12-17 23:00:31 +01:00
import 'package:flutter/material.dart';
import 'package:moody/views/statistic/widget/calendar_widget.dart';
import 'package:moody/views/statistic/widget/streak_widget.dart';
2024-01-08 19:34:48 +01:00
import '../../utils/definitions/ColorPairs.dart';
import '../../utils/definitions/style_guide.dart';
import '../../utils/logic/PreferencesService.dart';
2023-12-18 17:51:22 +01:00
import '../../utils/widgets/BottomNavigationWidget.dart';
2024-01-08 19:34:48 +01:00
class StatisticPage extends StatefulWidget {
@override
_StatisticPageState createState() => _StatisticPageState();
}
class _StatisticPageState extends State<StatisticPage> {
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: [
SizedBox(
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 {
return CircularProgressIndicator(); // or some placeholder
}
},
),
Text(
"browse your memories!",
style: TextStyle(fontSize: 24),
),
],
),
Expanded(
child: SingleChildScrollView(
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(
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,
floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 0),
),
2023-12-17 23:00:31 +01:00
),
);
}
}