137 lines
4.8 KiB
Dart
137 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:tunas/domains/charts/chart_bloc.dart';
|
|
import 'package:tunas/pages/stats/widgets/account_counters.dart';
|
|
import 'package:tunas/pages/stats/widgets/categories_totals_chart.dart';
|
|
import 'package:tunas/pages/stats/widgets/global_counter.dart';
|
|
import 'package:tunas/pages/stats/widgets/monthly_categories_total_chart.dart';
|
|
import 'package:tunas/pages/stats/widgets/global_total_chart.dart';
|
|
import 'package:tunas/pages/stats/widgets/profit_indicator.dart';
|
|
import 'package:tunas/pages/stats/widgets/year_selector.dart';
|
|
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
|
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
|
|
|
class StatsPage extends StatelessWidget {
|
|
const StatsPage({super.key});
|
|
|
|
Widget _largeScreenHeader(ChartState state) {
|
|
return Center (
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
|
constraints: const BoxConstraints(
|
|
maxWidth: 1000
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
flex: 2,
|
|
child: GlobalCounter(value: state.globalTotal)
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
flex: 1,
|
|
child: AccountCounter(accountsTotals: state.accountsTotals)
|
|
),
|
|
],
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
const YearSelector(),
|
|
ProfitIndicator(profit: state.scoppedProfit)
|
|
],
|
|
),
|
|
]
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget _smallScreenHeader(ChartState state) {
|
|
return Center (
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
|
constraints: const BoxConstraints(
|
|
maxWidth: 1000
|
|
),
|
|
child: Column(
|
|
children: [
|
|
GlobalCounter(value: state.globalTotal),
|
|
AccountCounter(accountsTotals: state.accountsTotals),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
ProfitIndicator(profit: state.scoppedProfit),
|
|
const YearSelector(),
|
|
],
|
|
),
|
|
]
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget _largeScreenTotalsCharts(ChartState state) {
|
|
return Center (
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(
|
|
maxWidth: 1500
|
|
),
|
|
child: SizedBox(
|
|
height: 450,
|
|
child: Row(
|
|
children: [
|
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
|
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
|
|
],
|
|
)
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
Widget _smallScreenTotalsCharts(ChartState state) {
|
|
return Center (
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(
|
|
maxWidth: 1500
|
|
),
|
|
child: Column(
|
|
children: [
|
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
|
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
|
|
],
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
|
return BlocProvider(
|
|
create: (context) => ChartBloc(
|
|
metadataRepository: RepositoryProvider.of<MetadataRepository>(context),
|
|
transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context),
|
|
),
|
|
child: BlocBuilder<ChartBloc, ChartState>(
|
|
builder: (context, state) => ListView(
|
|
children: [
|
|
smallVerticalScreen ? _smallScreenHeader(state) : _largeScreenHeader(state),
|
|
SizedBox(
|
|
height: smallVerticalScreen ? 100 : 200,
|
|
child: GlobalTotalChart(monthlyTotals: state.scopedMonthlyTotals)
|
|
),
|
|
SizedBox(
|
|
height: smallVerticalScreen ? 200 : 500,
|
|
child: MonthlyCategoriesTotalChart(categoriesMonthlyTotals: state.scopedCategoriesMonthlyTotals)
|
|
),
|
|
smallVerticalScreen ? _smallScreenTotalsCharts(state) : _largeScreenTotalsCharts(state),
|
|
],
|
|
)
|
|
),
|
|
);
|
|
}
|
|
} |