From d2ab82aaf5d2bac390a400d43eee25a973b44978 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 10 Jun 2024 17:35:21 +0200 Subject: [PATCH] fix paddings of buttons and other widgets --- lib/enter_food_widget.dart | 18 ++++++---- lib/food_entry_widget.dart | 24 ++++++++------ lib/perdate_widget.dart | 2 +- lib/row_with_spacers_widget.dart | 57 ++++++++------------------------ lib/sum_widget.dart | 2 +- 5 files changed, 41 insertions(+), 62 deletions(-) diff --git a/lib/enter_food_widget.dart b/lib/enter_food_widget.dart index b7857ad..bf1f8dd 100644 --- a/lib/enter_food_widget.dart +++ b/lib/enter_food_widget.dart @@ -36,6 +36,9 @@ class _EnterFoodWidgetState extends State { controller: kcalPerMassController); var enterButton = ElevatedButton( + style: ElevatedButton.styleFrom( + padding: EdgeInsets.zero, + ), onPressed: () { double massAsNumber = 0.0; double kcalPerMassAsNumber = 0.0; @@ -81,12 +84,15 @@ class _EnterFoodWidgetState extends State { }, child: const Icon(Icons.add)); - return RowWidgetWithSpacers( - nameWidget, - massWidget, - kcalPerMassWidget, - null, - enterButton, + return Padding( + padding: const EdgeInsets.only(left: 8.0, right: 4.0), + child: RowWidget( + nameWidget, + massWidget, + kcalPerMassWidget, + null, + enterButton, + ), ); } } diff --git a/lib/food_entry_widget.dart b/lib/food_entry_widget.dart index 18aa777..97e3071 100644 --- a/lib/food_entry_widget.dart +++ b/lib/food_entry_widget.dart @@ -12,16 +12,20 @@ class FoodEntryWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Card( - child: RowWidgetWithSpacers( - Text(entry.name), - Text(entry.mass.toString()), - Text(entry.kcalPerMass.toString()), - Text((entry.mass * entry.kcalPerMass / 100).toString()), - ElevatedButton( - onPressed: () { - onDelete(context); - }, - child: const Icon(Icons.delete_forever_rounded)), + child: Padding( + padding: const EdgeInsets.only(left: 4.0), + child: RowWidget( + Text(entry.name), + Text(entry.mass.toString()), + Text(entry.kcalPerMass.toString()), + Text((entry.mass * entry.kcalPerMass / 100).toString()), + IconButton( + style: IconButton.styleFrom(padding: EdgeInsets.zero), + onPressed: () { + onDelete(context); + }, + icon: const Icon(Icons.delete_forever_rounded)), + ), ), ); } diff --git a/lib/perdate_widget.dart b/lib/perdate_widget.dart index 2c9bfd7..c3959b1 100644 --- a/lib/perdate_widget.dart +++ b/lib/perdate_widget.dart @@ -27,7 +27,7 @@ class PerDateWidget extends StatelessWidget { itemBuilder: (BuildContext itemBuilderContext, int index) { if (index == state.foodEntries.length) { return Padding( - padding: const EdgeInsets.symmetric(vertical: 15), + padding: const EdgeInsets.symmetric(vertical: 10), child: SumWidget(limit: state.kcalLimit), ); } diff --git a/lib/row_with_spacers_widget.dart b/lib/row_with_spacers_widget.dart index 8005911..5a529ac 100644 --- a/lib/row_with_spacers_widget.dart +++ b/lib/row_with_spacers_widget.dart @@ -1,63 +1,32 @@ import 'package:flutter/material.dart'; -class RowWidgetWithSpacers extends StatefulWidget { +class RowWidget extends StatefulWidget { final Widget? widget1; final Widget? widget2; final Widget? widget3; final Widget? widget4; final Widget? widget5; - const RowWidgetWithSpacers( + const RowWidget( this.widget1, this.widget2, this.widget3, this.widget4, this.widget5, {super.key}); @override - State createState() => _RowWidgetWithSpacersState(); + State createState() => _RowWidgetState(); } -class _RowWidgetWithSpacersState extends State { +class _RowWidgetState extends State { @override Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Expanded( - flex: 5, - child: Padding( - padding: const EdgeInsets.only( - left: 8.0, - right: 2.0, - ), - child: widget.widget1 ?? Container(), - )), - Expanded( - flex: 5, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 2.0), - child: widget.widget2 ?? Container(), - )), - Expanded( - flex: 5, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 2.0), - child: widget.widget3 ?? Container(), - )), - Expanded( - flex: 5, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 2.0), - child: widget.widget4 ?? Container(), - )), - Expanded( - flex: 2, - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 2.0), - child: widget.widget5 ?? Container(), - )), - ], - ), + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded(flex: 10, child: widget.widget1 ?? Container()), + Expanded(flex: 6, child: widget.widget2 ?? Container()), + Expanded(flex: 6, child: widget.widget3 ?? Container()), + Expanded(flex: 8, child: widget.widget4 ?? Container()), + Expanded(flex: 3, child: widget.widget5 ?? Container()), + ], ); } } diff --git a/lib/sum_widget.dart b/lib/sum_widget.dart index 1b329ae..507d6f3 100644 --- a/lib/sum_widget.dart +++ b/lib/sum_widget.dart @@ -17,7 +17,7 @@ class SumWidget extends StatelessWidget { sum += entry.kcalPerMass / 100 * entry.mass; } - return RowWidgetWithSpacers( + return RowWidget( null, null, const Text("kcal heute:"),