98 lines
3.4 KiB
Dart
98 lines
3.4 KiB
Dart
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/style_guide.dart';
|
|
import '../../utils/logic/PreferencesService.dart';
|
|
import '../../utils/widgets/BottomNavigationWidget.dart';
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
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,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
floatingActionButton: CustomBottomNavigationBar(initialSelectedIndex: 0),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|