From 2ed94a4eb96966debd10f8578de7e7f0964067c7 Mon Sep 17 00:00:00 2001 From: lmnd Date: Sun, 10 Nov 2024 10:23:12 +0100 Subject: [PATCH 1/2] fix: 180 - loading widget with height --- .../widgets/categories/categories_card.dart | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/pages/graphs_page/widgets/categories/categories_card.dart b/lib/pages/graphs_page/widgets/categories/categories_card.dart index f57d7de..2263383 100644 --- a/lib/pages/graphs_page/widgets/categories/categories_card.dart +++ b/lib/pages/graphs_page/widgets/categories/categories_card.dart @@ -11,11 +11,18 @@ import 'categories_bar_chart.dart'; import 'categories_pie_chart2.dart'; import 'category_label.dart'; -class CategoriesCard extends ConsumerWidget { +class CategoriesCard extends ConsumerStatefulWidget { const CategoriesCard({super.key}); @override - Widget build(BuildContext context, WidgetRef ref) { + ConsumerState createState() => CategoriesCardState(); +} + +class CategoriesCardState extends ConsumerState { + int _categoriesCount = 0; + + @override + Widget build(BuildContext context) { final categoryType = ref.watch(categoryTypeProvider); final categoryMap = ref.watch(categoryMapProvider(categoryType)); final categoryTotalAmount = @@ -28,12 +35,14 @@ class CategoriesCard extends ConsumerWidget { DefaultContainer( child: categoryMap.when( data: (categories) { + _categoriesCount = categories.length; + return categoryTotalAmount != 0 ? CategoriesContent( categories: categories, totalAmount: categoryTotalAmount) : const NoTransactionsContent(); }, - loading: () => const SizedBox.shrink(), + loading: () => LoadingContentWidget(previousCategoriesCount: _categoriesCount), error: (e, s) => Text("Error: $e"), ), ), @@ -117,6 +126,32 @@ class CategoryItem extends StatelessWidget { } } +class LoadingContentWidget extends StatelessWidget { + final int previousCategoriesCount; + + const LoadingContentWidget({ + super.key, + required this.previousCategoriesCount, + }); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + const MonthSelector(type: MonthSelectorType.simple), + const SizedBox(height: 20), + const CategoryTypeButton(), + const SizedBox(height: 20), + const SizedBox(height: 200), // height of CategoriesPieChart2 + const SizedBox(height: 20), + SizedBox(height: 50.0 * previousCategoriesCount), // Height of CategoryItem's list + const SizedBox(height: 30), + const SizedBox(height: 200), // Height of CategoriesBarChart + ], + ); + } +} + class NoTransactionsContent extends StatelessWidget { const NoTransactionsContent({super.key}); From a30ab92900aa56fcc28e387f16b786d27e9f3940 Mon Sep 17 00:00:00 2001 From: lmnd Date: Sun, 10 Nov 2024 10:23:41 +0100 Subject: [PATCH 2/2] fix: 180 - code formatting --- .../widgets/categories/categories_card.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/pages/graphs_page/widgets/categories/categories_card.dart b/lib/pages/graphs_page/widgets/categories/categories_card.dart index 2263383..251eb69 100644 --- a/lib/pages/graphs_page/widgets/categories/categories_card.dart +++ b/lib/pages/graphs_page/widgets/categories/categories_card.dart @@ -25,8 +25,7 @@ class CategoriesCardState extends ConsumerState { Widget build(BuildContext context) { final categoryType = ref.watch(categoryTypeProvider); final categoryMap = ref.watch(categoryMapProvider(categoryType)); - final categoryTotalAmount = - ref.watch(categoryTotalAmountProvider(categoryType)).value ?? 0; + final categoryTotalAmount = ref.watch(categoryTotalAmountProvider(categoryType)).value ?? 0; return Column( children: [ @@ -39,7 +38,9 @@ class CategoriesCardState extends ConsumerState { return categoryTotalAmount != 0 ? CategoriesContent( - categories: categories, totalAmount: categoryTotalAmount) + categories: categories, + totalAmount: categoryTotalAmount, + ) : const NoTransactionsContent(); }, loading: () => LoadingContentWidget(previousCategoriesCount: _categoriesCount), @@ -52,8 +53,11 @@ class CategoriesCardState extends ConsumerState { } class CategoriesContent extends StatelessWidget { - const CategoriesContent( - {required this.categories, required this.totalAmount, super.key}); + const CategoriesContent({ + required this.categories, + required this.totalAmount, + super.key, + }); final Map categories; final double totalAmount; @@ -79,7 +83,10 @@ class CategoriesContent extends StatelessWidget { final category = categories.keys.elementAt(i); final amount = categories[category] ?? 0; return CategoryItem( - category: category, amount: amount, totalAmount: totalAmount); + category: category, + amount: amount, + totalAmount: totalAmount, + ); }, ), const SizedBox(height: 30),