diff --git a/lib/enter_food_widget.dart b/lib/enter_food_widget.dart index 0be078b..ea59a20 100644 --- a/lib/enter_food_widget.dart +++ b/lib/enter_food_widget.dart @@ -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'; diff --git a/lib/main.dart b/lib/main.dart index 39b3d05..32d8740 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -53,9 +53,9 @@ class MainApp extends StatelessWidget { ], child: BlocBuilder( 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, ); }, diff --git a/lib/perdate_widget.dart b/lib/perdate_widget.dart index ef7fa3c..3ec8c36 100644 --- a/lib/perdate_widget.dart +++ b/lib/perdate_widget.dart @@ -21,7 +21,7 @@ class PerDateWidget extends StatefulWidget { class _PerDateWidgetState extends State { late FoodStorage storage; late Future> entriesFuture; - late List entries; + late List entries = []; @override void initState() { @@ -37,84 +37,90 @@ class _PerDateWidgetState extends State { @override Widget build(BuildContext context) { var formattedDate = DateFormat.yMMMMd('de').format(widget.date); - return Scaffold( - appBar: AppBar( - title: Text(formattedDate), - actions: [ - BlocBuilder(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().add(ThemeToggleEvent()); - }, - ); - }), - ], - ), - drawer: const AppDrawer(), - body: FutureBuilder( - future: entriesFuture, - builder: (context, snapshot) { - if (snapshot.connectionState != ConnectionState.done) { - return const Center(child: CircularProgressIndicator()); - } else { - return BlocProvider( - create: (context) => FoodEntryBloc( - initialState: FoodEntryState(foodEntries: entries), - storage: storage, - forDate: widget.date), - child: BlocBuilder( - 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), - ); - } - if (index == state.foodEntries.length + 1) { + return FutureBuilder( + future: entriesFuture, + builder: (context, snapshot) { + if (snapshot.connectionState != ConnectionState.done) { + return const Center(child: CircularProgressIndicator()); + } else { + return BlocProvider( + create: (context) => FoodEntryBloc( + initialState: FoodEntryState(foodEntries: entries), + storage: storage, + forDate: widget.date), + child: BlocBuilder( + builder: (context, state) { + return Scaffold( + appBar: AppBar( + title: Text(formattedDate), + actions: [ + BlocBuilder( + 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() + .add(ThemeToggleEvent()); + }, + ); + }), + ], + ), + body: ListView.builder( + itemCount: state.foodEntries.length + 1, + itemBuilder: + (BuildContext itemBuilderContext, int listIndex) { + if (listIndex == state.foodEntries.length) { + return Column( + children: [ + EnterFoodWidget( + onAdd: (context, entry) { + context + .read() + .add(FoodEntryEvent(entry: entry)); + }, + ), + const SizedBox(height: 75), + ], + ); + } + + var entryIndex = listIndex; return Column( children: [ - EnterFoodWidget( - onAdd: (context, entry) { - context + FoodEntryWidget( + entry: state.foodEntries[entryIndex], + onDelete: (callbackContext, id) { + callbackContext .read() - .add(FoodEntryEvent(entry: entry)); + .add(FoodDeletionEvent( + entryID: id, + )); }, ), - const SizedBox(height: 75), + if (listIndex != state.foodEntries.length - 1) + const Divider(), ], ); - } - - return Column( - children: [ - FoodEntryWidget( - entry: state.foodEntries[index], - onDelete: (callbackContext, id) { - callbackContext - .read() - .add(FoodDeletionEvent( - entryID: id, - )); - }, - ), - const Divider(), - ], - ); - }, - ); - }), - ); - } - }, - ), - floatingActionButton: CalendarFloatingButton(date: widget.date)); + }, + ), + 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); + }), + ); + } + }); } } diff --git a/lib/storage/storage.dart b/lib/storage/storage.dart index cd9e47f..b6fc749 100644 --- a/lib/storage/storage.dart +++ b/lib/storage/storage.dart @@ -8,7 +8,7 @@ import 'package:universal_platform/universal_platform.dart'; class FoodStorage { static late FoodStorage _instance; late String path; - late Map _foodLookupDatabase = {}; + final Map _foodLookupDatabase = {}; FoodStorage._create(); diff --git a/lib/sum_widget.dart b/lib/sum_widget.dart index d9b2c1e..c800576 100644 --- a/lib/sum_widget.dart +++ b/lib/sum_widget.dart @@ -23,10 +23,16 @@ class _SumWidgetState extends State { } 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, ); },