fix paddings of buttons and other widgets

This commit is contained in:
Marco 2024-06-10 17:35:21 +02:00
parent 0080e39605
commit d2ab82aaf5
5 changed files with 41 additions and 62 deletions

View File

@ -36,6 +36,9 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
controller: kcalPerMassController); controller: kcalPerMassController);
var enterButton = ElevatedButton( var enterButton = ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () { onPressed: () {
double massAsNumber = 0.0; double massAsNumber = 0.0;
double kcalPerMassAsNumber = 0.0; double kcalPerMassAsNumber = 0.0;
@ -81,12 +84,15 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
}, },
child: const Icon(Icons.add)); child: const Icon(Icons.add));
return RowWidgetWithSpacers( return Padding(
nameWidget, padding: const EdgeInsets.only(left: 8.0, right: 4.0),
massWidget, child: RowWidget(
kcalPerMassWidget, nameWidget,
null, massWidget,
enterButton, kcalPerMassWidget,
null,
enterButton,
),
); );
} }
} }

View File

@ -12,16 +12,20 @@ class FoodEntryWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(
child: RowWidgetWithSpacers( child: Padding(
Text(entry.name), padding: const EdgeInsets.only(left: 4.0),
Text(entry.mass.toString()), child: RowWidget(
Text(entry.kcalPerMass.toString()), Text(entry.name),
Text((entry.mass * entry.kcalPerMass / 100).toString()), Text(entry.mass.toString()),
ElevatedButton( Text(entry.kcalPerMass.toString()),
onPressed: () { Text((entry.mass * entry.kcalPerMass / 100).toString()),
onDelete(context); IconButton(
}, style: IconButton.styleFrom(padding: EdgeInsets.zero),
child: const Icon(Icons.delete_forever_rounded)), onPressed: () {
onDelete(context);
},
icon: const Icon(Icons.delete_forever_rounded)),
),
), ),
); );
} }

View File

@ -27,7 +27,7 @@ class PerDateWidget extends StatelessWidget {
itemBuilder: (BuildContext itemBuilderContext, int index) { itemBuilder: (BuildContext itemBuilderContext, int index) {
if (index == state.foodEntries.length) { if (index == state.foodEntries.length) {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 15), padding: const EdgeInsets.symmetric(vertical: 10),
child: SumWidget(limit: state.kcalLimit), child: SumWidget(limit: state.kcalLimit),
); );
} }

View File

@ -1,63 +1,32 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class RowWidgetWithSpacers extends StatefulWidget { class RowWidget extends StatefulWidget {
final Widget? widget1; final Widget? widget1;
final Widget? widget2; final Widget? widget2;
final Widget? widget3; final Widget? widget3;
final Widget? widget4; final Widget? widget4;
final Widget? widget5; final Widget? widget5;
const RowWidgetWithSpacers( const RowWidget(
this.widget1, this.widget2, this.widget3, this.widget4, this.widget5, this.widget1, this.widget2, this.widget3, this.widget4, this.widget5,
{super.key}); {super.key});
@override @override
State<RowWidgetWithSpacers> createState() => _RowWidgetWithSpacersState(); State<RowWidget> createState() => _RowWidgetState();
} }
class _RowWidgetWithSpacersState extends State<RowWidgetWithSpacers> { class _RowWidgetState extends State<RowWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Row(
padding: const EdgeInsets.symmetric(vertical: 4.0), mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Row( children: [
mainAxisAlignment: MainAxisAlignment.end, Expanded(flex: 10, child: widget.widget1 ?? Container()),
children: [ Expanded(flex: 6, child: widget.widget2 ?? Container()),
Expanded( Expanded(flex: 6, child: widget.widget3 ?? Container()),
flex: 5, Expanded(flex: 8, child: widget.widget4 ?? Container()),
child: Padding( Expanded(flex: 3, child: widget.widget5 ?? Container()),
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(),
)),
],
),
); );
} }
} }

View File

@ -17,7 +17,7 @@ class SumWidget extends StatelessWidget {
sum += entry.kcalPerMass / 100 * entry.mass; sum += entry.kcalPerMass / 100 * entry.mass;
} }
return RowWidgetWithSpacers( return RowWidget(
null, null,
null, null,
const Text("kcal heute:"), const Text("kcal heute:"),