Improved json auto save & budget mobile UI
This commit is contained in:
@@ -1,135 +1,50 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tunas/domains/budget/budget_bloc.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/budget_cards.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/budget_compare_selector.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/budget_radar.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
||||
|
||||
class BudgetComparator extends StatelessWidget {
|
||||
const BudgetComparator({super.key});
|
||||
|
||||
List<RadarDataSet> _computeDataSet(BuildContext context, List<Budget> targetBudgets, List<Budget> realBudgets) {
|
||||
RadarDataSet targetDataSet = RadarDataSet(
|
||||
fillColor: Theme.of(context).colorScheme.primary.withAlpha(100),
|
||||
borderColor: Theme.of(context).colorScheme.primary,
|
||||
entryRadius: 5,
|
||||
dataEntries: targetBudgets.map((budget) => RadarEntry(value: budget.value)).toList(),
|
||||
);
|
||||
if (realBudgets.isNotEmpty) {
|
||||
targetDataSet.dataEntries.add(const RadarEntry(value: 0));
|
||||
}
|
||||
RadarDataSet realDataSet = RadarDataSet(
|
||||
fillColor: Theme.of(context).colorScheme.onPrimary.withAlpha(100),
|
||||
borderColor: Theme.of(context).colorScheme.onPrimary,
|
||||
entryRadius: 8,
|
||||
dataEntries: realBudgets.map((budget) => RadarEntry(value: budget.value)).toList(),
|
||||
);
|
||||
return realBudgets.isEmpty ? [RadarDataSet(dataEntries: [const RadarEntry(value: 1), const RadarEntry(value: 2), const RadarEntry(value: 3)])] : [realDataSet, targetDataSet];
|
||||
}
|
||||
|
||||
RadarChartTitle _computeDataSetTitle(int index, List<Budget> realBudgets) {
|
||||
return realBudgets.isEmpty ? const RadarChartTitle(text: 'No data') : RadarChartTitle(text: realBudgets[index].label);
|
||||
}
|
||||
|
||||
List<Widget> _computeOtherBudgets(BuildContext context, List<Budget> otherBudgets) {
|
||||
List<Widget> list = [
|
||||
const Text('Hors budget'),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 2,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||
)
|
||||
)
|
||||
),
|
||||
)
|
||||
];
|
||||
|
||||
list.addAll(otherBudgets.map((budget) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(width: 5),
|
||||
Text(budget.label),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
NumberFormat("#00 €").format(budget.value.abs()),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'NovaMono',
|
||||
)
|
||||
)
|
||||
],
|
||||
)));
|
||||
return list;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||
builder: (context, state) => TitledContainer(
|
||||
title: 'Compare',
|
||||
child: Column(
|
||||
child: smallVerticalScreen
|
||||
? const Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => context.read<BudgetBloc>().add(BudgetComparePrevious()),
|
||||
icon: const Icon(Icons.skip_previous)
|
||||
),
|
||||
Text('${NumberFormat('00', 'fr_FR').format(state.compareMonth)} - ${state.compareYear}'),
|
||||
IconButton(
|
||||
onPressed: () => context.read<BudgetBloc>().add(BudgetCompareNext()),
|
||||
icon: const Icon(Icons.skip_next)
|
||||
),
|
||||
],
|
||||
BudgetCompareSelector(),
|
||||
SizedBox(
|
||||
height: 500,
|
||||
child: BudgetRadar(),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
SizedBox(
|
||||
height: 500,
|
||||
child: BudgetCards(),
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Column(
|
||||
children: [
|
||||
BudgetCompareSelector(),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
height: 300,
|
||||
width: 250,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
color: Theme.of(context).colorScheme.secondaryContainer
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _computeOtherBudgets(context, state.otherBudgets),
|
||||
),
|
||||
)
|
||||
),
|
||||
Expanded(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1.3,
|
||||
child: RadarChart(
|
||||
RadarChartData(
|
||||
titlePositionPercentageOffset: 0.15,
|
||||
tickBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 1),
|
||||
gridBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 2),
|
||||
radarBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 3),
|
||||
radarBackgroundColor: Theme.of(context).colorScheme.secondaryContainer.withAlpha(100),
|
||||
radarShape: RadarShape.circle,
|
||||
dataSets: _computeDataSet(context, state.budgets, state.compareBudgets),
|
||||
getTitle: (index, angle) => _computeDataSetTitle(index, state.compareBudgets),
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
BudgetCards(),
|
||||
BudgetRadar(),
|
||||
],
|
||||
)
|
||||
],
|
||||
]
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user