Improved mobile layout

This commit is contained in:
2024-02-18 12:59:45 +01:00
parent 57ed6f44cd
commit b2175ddafd
8 changed files with 160 additions and 78 deletions

View File

@@ -14,8 +14,103 @@ 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),
@@ -24,60 +119,16 @@ class StatsPage extends StatelessWidget {
child: BlocBuilder<ChartBloc, ChartState>(
builder: (context, state) => ListView(
children: [
Center (
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 1000
),
child: Column(
children: [
Row(
children: [
Expanded(
flex: 2,
child: GlobalCounter(value: state.globalTotal)
),
Expanded(
flex: 1,
child: AccountCounter(accountsTotals: state.accountsTotals)
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const YearSelector(),
ProfitIndicator(profit: state.scoppedProfit)
],
),
]
)
)
),
smallVerticalScreen ? _smallScreenHeader(state) : _largeScreenHeader(state),
SizedBox(
height: 200,
height: smallVerticalScreen ? 100 : 200,
child: GlobalTotalChart(monthlyTotals: state.scopedMonthlyTotals)
),
SizedBox(
height: 500,
height: smallVerticalScreen ? 200 : 500,
child: MonthlyCategoriesTotalChart(categoriesMonthlyTotals: state.scopedCategoriesMonthlyTotals)
),
Center (
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 1500
),
child: SizedBox(
height: 450,
child: OverflowBar(
children: [
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
],
)
)
)
),
smallVerticalScreen ? _smallScreenTotalsCharts(state) : _largeScreenTotalsCharts(state),
],
)
),

View File

@@ -31,7 +31,7 @@ class AccountCounter extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(20),
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Theme.of(context).colorScheme.primaryContainer,

View File

@@ -11,7 +11,7 @@ class CategoriesTotalsChart extends StatelessWidget {
const CategoriesTotalsChart({super.key, required this.categoriesTotals, required this.categoriesTotalsPercents});
List<PieChartSectionData> _convertDataForChart(Map<String, Color> categoriesColors) {
List<PieChartSectionData> _convertDataForChart(Map<String, Color> categoriesColors, bool smallVerticalScreen) {
return categoriesTotalsPercents
.map((item) =>
PieChartSectionData(
@@ -21,9 +21,10 @@ class CategoriesTotalsChart extends StatelessWidget {
fontSize: 15,
fontWeight: FontWeight.w300
),
showTitle: !smallVerticalScreen,
titlePositionPercentageOffset: 0.5,
borderSide: const BorderSide(width: 0),
radius: 40,
radius: smallVerticalScreen ? 30 : 40,
color: categoriesColors[item.label]
))
.toList();
@@ -60,10 +61,11 @@ class CategoriesTotalsChart extends StatelessWidget {
@override
Widget build(BuildContext context) {
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
return BlocBuilder<CategoryBloc, CategoryState>(
builder: (context, state) => Container(
height: 320,
width: 500,
width: smallVerticalScreen ? null : 500,
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(20),
decoration: BoxDecoration(
@@ -84,11 +86,11 @@ class CategoriesTotalsChart extends StatelessWidget {
Expanded(
child: PieChart(
PieChartData(
sections: _convertDataForChart(state.categoriesColors),
sections: _convertDataForChart(state.categoriesColors, smallVerticalScreen),
borderData: FlBorderData(
show: false
),
centerSpaceRadius: 50,
centerSpaceRadius: smallVerticalScreen ? 30 :50,
sectionsSpace: 4
)
),

View File

@@ -10,7 +10,7 @@ class GlobalCounter extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(20),
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Theme.of(context).colorScheme.primaryContainer,