Make shit pretty

This commit is contained in:
Marco 2024-09-05 16:36:35 +02:00
parent 131f39c1c8
commit 1db4e5e351
5 changed files with 96 additions and 81 deletions

View File

@ -1,5 +1,3 @@
import 'dart:developer';
import 'package:calodiary/storage/storage.dart'; import 'package:calodiary/storage/storage.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:calodiary/food_entry_bloc.dart'; import 'package:calodiary/food_entry_bloc.dart';

View File

@ -53,9 +53,9 @@ class MainApp extends StatelessWidget {
], ],
child: BlocBuilder<ThemeDataBloc, ThemeState>( child: BlocBuilder<ThemeDataBloc, ThemeState>(
builder: (context, state) { builder: (context, state) {
var switchToTheme = ThemeData.light(); var newBrightness = Brightness.light;
if (state.brightness == 'dark') { if (state.brightness == 'dark') {
switchToTheme = ThemeData.dark(); newBrightness = Brightness.dark;
} }
return MaterialApp.router( return MaterialApp.router(
@ -67,7 +67,12 @@ class MainApp extends StatelessWidget {
supportedLocales: const [ supportedLocales: const [
Locale('de'), Locale('de'),
], ],
theme: switchToTheme, theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.lightBlue,
brightness: newBrightness,
),
),
routerConfig: router, routerConfig: router,
); );
}, },

View File

@ -21,7 +21,7 @@ class PerDateWidget extends StatefulWidget {
class _PerDateWidgetState extends State<PerDateWidget> { class _PerDateWidgetState extends State<PerDateWidget> {
late FoodStorage storage; late FoodStorage storage;
late Future<List<FoodEntry>> entriesFuture; late Future<List<FoodEntry>> entriesFuture;
late List<FoodEntry> entries; late List<FoodEntry> entries = [];
@override @override
void initState() { void initState() {
@ -37,26 +37,7 @@ class _PerDateWidgetState extends State<PerDateWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var formattedDate = DateFormat.yMMMMd('de').format(widget.date); var formattedDate = DateFormat.yMMMMd('de').format(widget.date);
return Scaffold( return FutureBuilder(
appBar: AppBar(
title: Text(formattedDate),
actions: [
BlocBuilder<ThemeDataBloc, ThemeState>(builder: (context, state) {
var icon = const Icon(Icons.light_mode);
if (state.brightness == 'light') {
icon = const Icon(Icons.dark_mode);
}
return IconButton(
icon: icon,
onPressed: () {
context.read<ThemeDataBloc>().add(ThemeToggleEvent());
},
);
}),
],
),
drawer: const AppDrawer(),
body: FutureBuilder(
future: entriesFuture, future: entriesFuture,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) { if (snapshot.connectionState != ConnectionState.done) {
@ -69,16 +50,32 @@ class _PerDateWidgetState extends State<PerDateWidget> {
forDate: widget.date), forDate: widget.date),
child: BlocBuilder<FoodEntryBloc, FoodEntryState>( child: BlocBuilder<FoodEntryBloc, FoodEntryState>(
builder: (context, state) { builder: (context, state) {
return ListView.builder( return Scaffold(
itemCount: state.foodEntries.length + 2, appBar: AppBar(
itemBuilder: (BuildContext itemBuilderContext, int index) { title: Text(formattedDate),
if (index == state.foodEntries.length) { actions: [
return Padding( BlocBuilder<ThemeDataBloc, ThemeState>(
padding: const EdgeInsets.symmetric(vertical: 10), builder: (context, state) {
child: SumWidget(foodEntries: state.foodEntries), var icon = const Icon(Icons.light_mode);
); if (state.brightness == 'light') {
icon = const Icon(Icons.dark_mode);
} }
if (index == state.foodEntries.length + 1) { return IconButton(
icon: icon,
onPressed: () {
context
.read<ThemeDataBloc>()
.add(ThemeToggleEvent());
},
);
}),
],
),
body: ListView.builder(
itemCount: state.foodEntries.length + 1,
itemBuilder:
(BuildContext itemBuilderContext, int listIndex) {
if (listIndex == state.foodEntries.length) {
return Column( return Column(
children: [ children: [
EnterFoodWidget( EnterFoodWidget(
@ -93,10 +90,11 @@ class _PerDateWidgetState extends State<PerDateWidget> {
); );
} }
var entryIndex = listIndex;
return Column( return Column(
children: [ children: [
FoodEntryWidget( FoodEntryWidget(
entry: state.foodEntries[index], entry: state.foodEntries[entryIndex],
onDelete: (callbackContext, id) { onDelete: (callbackContext, id) {
callbackContext callbackContext
.read<FoodEntryBloc>() .read<FoodEntryBloc>()
@ -105,16 +103,24 @@ class _PerDateWidgetState extends State<PerDateWidget> {
)); ));
}, },
), ),
if (listIndex != state.foodEntries.length - 1)
const Divider(), const Divider(),
], ],
); );
}, },
); ),
bottomNavigationBar: BottomAppBar(
shape: const CircularNotchedRectangle(),
color: Theme.of(context).colorScheme.secondary,
child: SumWidget(foodEntries: state.foodEntries)),
drawer: const AppDrawer(),
floatingActionButton:
CalendarFloatingButton(date: widget.date),
floatingActionButtonLocation:
FloatingActionButtonLocation.endDocked);
}), }),
); );
} }
}, });
),
floatingActionButton: CalendarFloatingButton(date: widget.date));
} }
} }

View File

@ -8,7 +8,7 @@ import 'package:universal_platform/universal_platform.dart';
class FoodStorage { class FoodStorage {
static late FoodStorage _instance; static late FoodStorage _instance;
late String path; late String path;
late Map<String, double> _foodLookupDatabase = {}; final Map<String, double> _foodLookupDatabase = {};
FoodStorage._create(); FoodStorage._create();

View File

@ -23,10 +23,16 @@ class _SumWidgetState extends State<SumWidget> {
} }
return RowWidget( return RowWidget(
Text(
'kcal heute: ${sum.ceil().toString()}/${state.kcalLimit.ceil()}',
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Theme.of(context).colorScheme.onPrimary),
),
null,
null, null,
null, null,
const Text("kcal heute:"),
Text('${sum.ceil().toString()}/${state.kcalLimit.ceil()}'),
null, null,
); );
}, },