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:flutter/material.dart';
import 'package:calodiary/food_entry_bloc.dart';

View File

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

View File

@ -21,7 +21,7 @@ class PerDateWidget extends StatefulWidget {
class _PerDateWidgetState extends State<PerDateWidget> {
late FoodStorage storage;
late Future<List<FoodEntry>> entriesFuture;
late List<FoodEntry> entries;
late List<FoodEntry> entries = [];
@override
void initState() {
@ -37,26 +37,7 @@ class _PerDateWidgetState extends State<PerDateWidget> {
@override
Widget build(BuildContext context) {
var formattedDate = DateFormat.yMMMMd('de').format(widget.date);
return Scaffold(
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(
return FutureBuilder(
future: entriesFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
@ -69,16 +50,32 @@ class _PerDateWidgetState extends State<PerDateWidget> {
forDate: widget.date),
child: BlocBuilder<FoodEntryBloc, FoodEntryState>(
builder: (context, state) {
return ListView.builder(
itemCount: state.foodEntries.length + 2,
itemBuilder: (BuildContext itemBuilderContext, int index) {
if (index == state.foodEntries.length) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: SumWidget(foodEntries: state.foodEntries),
);
return Scaffold(
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);
}
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(
children: [
EnterFoodWidget(
@ -93,10 +90,11 @@ class _PerDateWidgetState extends State<PerDateWidget> {
);
}
var entryIndex = listIndex;
return Column(
children: [
FoodEntryWidget(
entry: state.foodEntries[index],
entry: state.foodEntries[entryIndex],
onDelete: (callbackContext, id) {
callbackContext
.read<FoodEntryBloc>()
@ -105,16 +103,24 @@ class _PerDateWidgetState extends State<PerDateWidget> {
));
},
),
if (listIndex != state.foodEntries.length - 1)
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 {
static late FoodStorage _instance;
late String path;
late Map<String, double> _foodLookupDatabase = {};
final Map<String, double> _foodLookupDatabase = {};
FoodStorage._create();

View File

@ -23,10 +23,16 @@ class _SumWidgetState extends State<SumWidget> {
}
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,
const Text("kcal heute:"),
Text('${sum.ceil().toString()}/${state.kcalLimit.ceil()}'),
null,
);
},