Make shit pretty
This commit is contained in:
parent
131f39c1c8
commit
1db4e5e351
@ -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';
|
||||
|
@ -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,
|
||||
);
|
||||
},
|
||||
|
@ -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,84 +37,90 @@ 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(
|
||||
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<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),
|
||||
);
|
||||
}
|
||||
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<FoodEntryBloc, FoodEntryState>(
|
||||
builder: (context, state) {
|
||||
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());
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
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<FoodEntryBloc>()
|
||||
.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<FoodEntryBloc>()
|
||||
.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<FoodEntryBloc>()
|
||||
.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);
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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,
|
||||
);
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user