Compare commits

...

3 Commits

24 changed files with 413 additions and 308 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
android {
namespace = "com.example.calorimeter"
namespace = "de.swgross.calorimeter"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
@ -21,7 +21,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.calorimeter"
applicationId = "de.swgross.calorimeter"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion

View File

@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" />
<application
android:label="calorimeter"
android:label="Calorimeter"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity

View File

@ -1,4 +1,4 @@
package com.example.calorimeter
package de.swgross.calorimeter
import io.flutter.embedding.android.FlutterActivity

View File

@ -368,7 +368,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
@ -384,7 +384,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -401,7 +401,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
@ -416,7 +416,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
@ -547,7 +547,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@ -569,7 +569,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;

View File

@ -1,142 +0,0 @@
import 'package:calorimeter/storage/storage.dart';
import 'package:flutter/material.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/row_with_spacers_widget.dart';
class EnterFoodWidget extends StatefulWidget {
final Function(BuildContext context, FoodEntry entry) onAdd;
const EnterFoodWidget({super.key, required this.onAdd});
@override
State<EnterFoodWidget> createState() => _EnterFoodWidgetState();
}
class _EnterFoodWidgetState extends State<EnterFoodWidget> {
String perFoodresult = "dings";
TextEditingController nameController = TextEditingController();
TextEditingController massController = TextEditingController();
TextEditingController kcalPerMassController = TextEditingController();
Map<String, double> suggestions = {};
@override
void initState() {
suggestions = FoodStorage.getInstance().getFoodEntryLookupDatabase;
super.initState();
}
@override
Widget build(BuildContext context) {
var nameWidget = Autocomplete<String>(
optionsViewOpenDirection: OptionsViewOpenDirection.down,
fieldViewBuilder: (context, controller, focusNode, onSubmitted) {
nameController = controller;
return TextFormField(
controller: controller,
focusNode: focusNode,
decoration: const InputDecoration(
label: Text("Name"),
),
);
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<String>.empty();
}
return suggestions.keys.where(
(name) {
return name
.toLowerCase()
.contains(textEditingValue.text.toLowerCase());
},
);
},
onSelected: (selectedFood) {
double kcalPerMassForSelectedFood = suggestions[selectedFood]!;
setState(() {
kcalPerMassController.text = kcalPerMassForSelectedFood.toString();
});
});
var massWidget = TextField(
textAlign: TextAlign.end,
decoration: const InputDecoration(
label: Align(alignment: Alignment.centerRight, child: Text("Menge")),
),
keyboardType: TextInputType.number,
controller: massController,
onSubmitted: (value) => onSubmitAction(),
);
var kcalPerMassWidget = TextField(
textAlign: TextAlign.end,
decoration: const InputDecoration(
label:
Align(alignment: Alignment.centerRight, child: Text("kcal pro"))),
keyboardType: TextInputType.number,
controller: kcalPerMassController,
onSubmitted: (value) => onSubmitAction(),
);
var enterButton = ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () => onSubmitAction(),
child: const Icon(Icons.add));
return Padding(
padding: const EdgeInsets.only(left: 8.0, right: 4.0),
child: RowWidget(
nameWidget,
massWidget,
kcalPerMassWidget,
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: enterButton,
),
),
);
}
void onSubmitAction() {
double massAsNumber = 0.0;
double kcalPerMassAsNumber = 0.0;
try {
massAsNumber = double.parse(massController.text.replaceAll(",", "."));
} catch (e) {
var snackbar = const SnackBar(content: Text("Menge muss eine Zahl sein"));
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackbar);
return;
}
try {
kcalPerMassAsNumber =
double.parse(kcalPerMassController.text.replaceAll(",", "."));
} catch (e) {
var snackbar =
const SnackBar(content: Text("'kcal pro 100g' muss eine Zahl sein"));
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackbar);
return;
}
try {
massAsNumber = double.parse(massController.text.replaceAll(",", "."));
} catch (e) {
var snackbar = const SnackBar(content: Text("Menge muss eine Zahl sein"));
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackbar);
return;
}
var entry = FoodEntry(
name: nameController.text,
mass: massAsNumber,
kcalPerMass: kcalPerMassAsNumber);
widget.onAdd(context, entry);
}
}

View File

@ -0,0 +1,143 @@
import 'package:calorimeter/perdate/perdate_widget.dart';
import 'package:calorimeter/storage/storage.dart';
import 'package:flutter/material.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
import 'package:provider/provider.dart';
class EnterFoodWidget extends StatefulWidget {
final Function(BuildContext context, FoodEntry entry) onAdd;
const EnterFoodWidget({super.key, required this.onAdd});
@override
State<EnterFoodWidget> createState() => _EnterFoodWidgetState();
}
class _EnterFoodWidgetState extends State<EnterFoodWidget> {
late TextEditingController nameController;
late TextEditingController massController;
late TextEditingController kcalPerMassController;
late Map<String, double> suggestions;
@override
void initState() {
nameController = TextEditingController();
massController = TextEditingController();
kcalPerMassController = TextEditingController();
suggestions = FoodStorage.getInstance().getFoodEntryLookupDatabase;
super.initState();
}
@override
Widget build(BuildContext context) {
return Consumer<EnterFoodController>(
builder: (context, food, child) {
nameController.text = food.name;
kcalPerMassController.text = food.kcalPer100g;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: RowWidget(
Autocomplete<String>(
optionsViewOpenDirection: OptionsViewOpenDirection.down,
fieldViewBuilder:
(context, controller, focusNode, onSubmitted) {
nameController = controller;
return TextFormField(
controller: controller,
focusNode: focusNode,
decoration: const InputDecoration(
label: Text("Name"),
),
);
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text == '') {
return const Iterable<String>.empty();
}
return suggestions.keys.where(
(name) {
return name
.toLowerCase()
.contains(textEditingValue.text.toLowerCase());
},
);
},
onSelected: (selectedFood) {
double kcalPerMassForSelectedFood =
suggestions[selectedFood]!;
context
.read<EnterFoodController>()
.set(selectedFood, kcalPerMassForSelectedFood.toString());
}),
TextField(
textAlign: TextAlign.end,
decoration: const InputDecoration(
label: Align(
alignment: Alignment.centerRight, child: Text("Menge")),
),
keyboardType: TextInputType.number,
controller: massController,
onSubmitted: (value) => onSubmitAction(),
),
TextField(
textAlign: TextAlign.end,
decoration: const InputDecoration(
label: Align(
alignment: Alignment.centerRight,
child: Text("kcal pro"))),
keyboardType: TextInputType.number,
controller: kcalPerMassController,
onSubmitted: (value) => onSubmitAction(),
),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
),
onPressed: () => onSubmitAction(),
child: const Icon(Icons.add)),
),
),
);
},
);
}
void onSubmitAction() {
double massAsNumber = 0.0;
double kcalPerMassAsNumber = 0.0;
try {
massAsNumber = double.parse(massController.text.replaceAll(",", "."));
} catch (e) {
var snackbar = const SnackBar(content: Text("Menge muss eine Zahl sein"));
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackbar);
return;
}
try {
kcalPerMassAsNumber =
double.parse(kcalPerMassController.text.replaceAll(",", "."));
} catch (e) {
var snackbar =
const SnackBar(content: Text("'kcal pro 100g' muss eine Zahl sein"));
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackbar);
return;
}
var entry = FoodEntry(
name: nameController.text,
mass: massAsNumber,
kcalPerMass: kcalPerMassAsNumber);
widget.onAdd(context, entry);
context.read<EnterFoodController>().set("", "");
}
}

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/row_with_spacers_widget.dart';
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
class FoodEntryWidget extends StatefulWidget {
final FoodEntry entry;
@ -15,6 +15,7 @@ class FoodEntryWidget extends StatefulWidget {
class _FoodEntryWidgetState extends State<FoodEntryWidget> {
late bool showCancelAndDelete;
@override
void initState() {
showCancelAndDelete = false;

View File

@ -0,0 +1,34 @@
import 'dart:convert';
import 'dart:io';
class FoodFactLookupClient {
FoodFactLookupClient();
static const String host = "world.openfoodfacts.org";
static const String url = "https://world.openfoodfacts.org/api/v3/product/";
String getProductUrl(String ean) {
return "$url$ean.json";
}
Future<FoodFactModel> retrieveFoodInfo(String ean) async {
HttpClient client = HttpClient();
var request = await client.getUrl(Uri.parse(getProductUrl(ean)));
var response = await request.close();
var asString = await response.transform(utf8.decoder).join();
return FoodFactModel.fromJson(jsonDecode(asString));
}
}
class FoodFactModel {
final String name;
final int kcalPer100g;
FoodFactModel({required this.name, required this.kcalPer100g});
factory FoodFactModel.fromJson(Map<String, dynamic> json) {
return FoodFactModel(
name: json['product']['product_name'],
kcalPer100g: json['product']['nutriments']['energy-kcal_100g']);
}
}

View File

@ -1,5 +1,5 @@
import 'package:calorimeter/perdate/perdate_widget.dart';
import 'package:calorimeter/storage/storage.dart';
import 'package:calorimeter/utils/router.dart';
import 'package:calorimeter/utils/settings_bloc.dart';
import 'package:calorimeter/utils/theme_bloc.dart';
import 'package:flutter/material.dart';
@ -56,7 +56,8 @@ class MainApp extends StatelessWidget {
newBrightness = Brightness.dark;
}
return MaterialApp.router(
return MaterialApp(
home: PerDateWidget(date: DateTime.now()),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
@ -72,7 +73,6 @@ class MainApp extends StatelessWidget {
brightness: newBrightness,
),
),
routerConfig: getRouterConfig(),
);
},
),

View File

@ -1,4 +1,4 @@
import 'package:calorimeter/enter_food_widget.dart';
import 'package:calorimeter/food_entry/enter_food_widget.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/food_entry/food_entry_widget.dart';
import 'package:flutter/material.dart';

View File

@ -1,13 +1,18 @@
import 'package:calorimeter/app_drawer.dart';
import 'package:calorimeter/utils/calendar_floating_button.dart';
import 'package:calorimeter/perdate/entry_list.dart';
import 'dart:developer';
import 'package:calorimeter/utils/scan_food_floating_button.dart';
import 'package:calorimeter/utils/app_drawer.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/perdate/entry_list.dart';
import 'package:calorimeter/storage/storage.dart';
import 'package:calorimeter/utils/calendar_floating_button.dart';
import 'package:calorimeter/utils/rectangular_notch_shape.dart';
import 'package:calorimeter/utils/sum_widget.dart';
import 'package:calorimeter/utils/theme_switcher_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class PerDateWidget extends StatefulWidget {
final DateTime date;
@ -21,11 +26,10 @@ class _PerDateWidgetState extends State<PerDateWidget> {
late FoodStorage storage;
late Future<List<FoodEntry>> entriesFuture;
List<FoodEntry> entries = [];
String formattedDate = '';
@override
void initState() {
formattedDate = DateFormat.yMMMMd('de').format(widget.date);
log("PerDateWidgetState's initState()");
storage = FoodStorage.getInstance();
entriesFuture = storage.getEntriesForDate(widget.date);
entriesFuture.then((val) {
@ -36,37 +40,67 @@ class _PerDateWidgetState extends State<PerDateWidget> {
@override
Widget build(BuildContext context) {
log("PerDateWidgetState's build()");
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: const [ThemeSwitcherButton()],
),
body: FoodEntryList(entries: state.foodEntries),
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);
}),
return ChangeNotifierProvider(
create: (context) => EnterFoodController(),
child: 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(DateFormat.yMMMMd('de').format(widget.date)),
actions: const [ThemeSwitcherButton()],
),
body: FoodEntryList(entries: state.foodEntries),
bottomNavigationBar: BottomAppBar(
shape: const RectangularNotchShape(),
color: Theme.of(context).colorScheme.secondary,
child: SumWidget(foodEntries: state.foodEntries)),
drawer: const AppDrawer(),
floatingActionButton: OverflowBar(children: [
const ScanFoodFloatingButton(),
const SizedBox(width: 8),
CalendarFloatingButton(
startFromDate: widget.date,
onDateSelected: (dateSelected) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return PerDateWidget(date: dateSelected);
},
),
);
},
),
]),
floatingActionButtonLocation:
FloatingActionButtonLocation.endDocked);
}),
),
);
}
});
}
}
class EnterFoodController extends ChangeNotifier {
String name = "";
String kcalPer100g = "";
void set(String newName, String newKcal) {
name = newName;
kcalPer100g = newKcal;
notifyListeners();
}
}

View File

@ -1,5 +1,5 @@
import 'package:calorimeter/utils/settings.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class AppDrawer extends StatelessWidget {
const AppDrawer({
@ -20,7 +20,7 @@ class AppDrawer extends StatelessWidget {
leading: IconButton(
icon: const Icon(Icons.close),
onPressed: () {
context.pop();
Navigator.of(context).pop();
},
),
title: const Text('Menü')),
@ -29,8 +29,9 @@ class AppDrawer extends StatelessWidget {
title: const Text('Einstellungen'),
trailing: const Icon(Icons.settings),
onTap: () {
context.pop();
context.pushNamed('settings');
Navigator.of(context).pop();
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const SettingsWidget()));
},
),
],

View File

@ -1,27 +1,31 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class CalendarFloatingButton extends StatelessWidget {
final DateTime date;
final DateTime startFromDate;
final Function(DateTime) onDateSelected;
const CalendarFloatingButton({super.key, required this.date});
const CalendarFloatingButton(
{super.key, required this.startFromDate, required this.onDateSelected});
@override
Widget build(BuildContext context) {
return FloatingActionButton(
onPressed: () async {
var router = GoRouter.of(context);
var datePicked = await showDatePicker(
locale: const Locale('de'),
context: context,
initialDate: date,
currentDate: DateTime.now(),
firstDate: DateTime.now().subtract(const Duration(days: 365 * 10)),
lastDate: DateTime.now(),
);
onPressed: () async {
var datePicked = await showDatePicker(
locale: const Locale('de'),
context: context,
initialDate: startFromDate,
currentDate: DateTime.now(),
firstDate: DateTime.now().subtract(const Duration(days: 365 * 10)),
lastDate: DateTime.now(),
);
router.pushNamed('perDay', extra: datePicked);
},
child: const Icon(Icons.today));
if (!context.mounted) return;
onDateSelected(datePicked ?? DateTime.now());
},
heroTag: "calendarFAB",
child: const Icon(Icons.today),
);
}
}

View File

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
class RectangularNotchShape extends NotchedShape {
const RectangularNotchShape();
@override
Path getOuterPath(Rect host, Rect? guest) {
if (guest == null || !host.overlaps(guest)) {
return Path()..addRect(host);
}
var margin = 20;
return Path()
..moveTo(host.left, host.top)
..lineTo(guest.left - margin, host.top)
..quadraticBezierTo(guest.left, host.top, guest.left, host.top + margin)
..lineTo(guest.left, guest.bottom - margin)
..quadraticBezierTo(
guest.left, guest.bottom, guest.left + margin, guest.bottom)
..lineTo(guest.right - margin, guest.bottom)
..quadraticBezierTo(
guest.right, guest.bottom, guest.right, guest.bottom - margin)
..lineTo(guest.right, host.top + margin)
..quadraticBezierTo(guest.right, host.top, guest.right + margin, host.top)
..lineTo(host.right, host.top)
..lineTo(host.right, host.bottom)
..lineTo(host.left, host.bottom)
..close();
}
}

View File

@ -1,28 +0,0 @@
import 'package:calorimeter/perdate/perdate_widget.dart';
import 'package:calorimeter/utils/settings.dart';
import 'package:go_router/go_router.dart';
GoRouter getRouterConfig() {
return GoRouter(initialLocation: '/day', routes: [
GoRoute(
path: '/day',
name: 'perDay',
builder: (context, state) {
DateTime date;
if (state.extra == null || state.extra is! DateTime) {
date = DateTime.now();
} else {
date = state.extra as DateTime;
}
return PerDateWidget(date: date);
}),
GoRoute(
path: '/settings',
name: 'settings',
builder: (context, state) {
return const SettingsWidget();
},
)
]);
}

View File

@ -0,0 +1,31 @@
import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:calorimeter/food_scan/food_fact_lookup.dart';
import 'package:calorimeter/perdate/perdate_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ScanFoodFloatingButton extends StatelessWidget {
const ScanFoodFloatingButton({
super.key,
});
@override
Widget build(BuildContext context) {
return FloatingActionButton(
heroTag: "scanFoodFAB",
child: const Icon(Icons.barcode_reader),
onPressed: () async {
var client = FoodFactLookupClient();
var scanResult = await BarcodeScanner.scan();
var food = await client.retrieveFoodInfo(scanResult.rawContent);
if (!context.mounted) return;
context
.read<EnterFoodController>()
.set(food.name, food.kcalPer100g.toString());
},
);
}
}

View File

@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:calorimeter/app_drawer.dart';
import 'package:calorimeter/utils/calendar_floating_button.dart';
import 'package:calorimeter/utils/app_drawer.dart';
import 'package:calorimeter/utils/settings_bloc.dart';
import 'package:settings_ui/settings_ui.dart';
@ -19,48 +17,48 @@ class _SettingsWidgetState extends State<SettingsWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<SettingsDataBloc, SettingsState>(
builder: (context, state) {
return SettingsList(sections: [
SettingsSection(
title: const Text('Deine persönlichen Einstellungen'),
tiles: [
SettingsTile.navigation(
leading: const Icon(Icons.food_bank),
title: const Text('Kalorienlimit pro Tag'),
value: Text(state.kcalLimit.toString()),
onPressed: (context) async {
await showDialog(
builder: (ctx) {
return AlertDialog(
title: const Text("Kalorienlimit pro Tag"),
content: TextField(controller: kcalPerDayCtrl),
actions: [
TextButton(
onPressed: () {
double setting;
try {
setting =
double.parse(kcalPerDayCtrl.text);
} catch (e) {
setting = 2000.0;
}
context.read<SettingsDataBloc>().add(
DailyKcalLimitUpdated(kcal: setting));
ctx.pop();
},
child: const Text('Ok'))
],
);
},
context: context);
}),
],
),
]);
}),
drawer: const AppDrawer(),
appBar: AppBar(title: const Text('Einstellungen')),
floatingActionButton: CalendarFloatingButton(date: DateTime.now()));
body: BlocBuilder<SettingsDataBloc, SettingsState>(
builder: (context, state) {
return SettingsList(sections: [
SettingsSection(
title: const Text('Deine persönlichen Einstellungen'),
tiles: [
SettingsTile.navigation(
leading: const Icon(Icons.food_bank),
title: const Text('Kalorienlimit pro Tag'),
value: Text(state.kcalLimit.toString()),
onPressed: (context) async {
await showDialog(
builder: (ctx) {
return AlertDialog(
title: const Text("Kalorienlimit pro Tag"),
content: TextField(controller: kcalPerDayCtrl),
actions: [
TextButton(
onPressed: () {
double setting;
try {
setting =
double.parse(kcalPerDayCtrl.text);
} catch (e) {
setting = 2000.0;
}
context.read<SettingsDataBloc>().add(
DailyKcalLimitUpdated(kcal: setting));
Navigator.of(context).pop();
},
child: const Text('Ok'))
],
);
},
context: context);
}),
],
),
]);
}),
drawer: const AppDrawer(),
appBar: AppBar(title: const Text('Einstellungen')),
);
}
}

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/utils/settings_bloc.dart';
import 'package:calorimeter/row_with_spacers_widget.dart';
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
class SumWidget extends StatefulWidget {
final List<FoodEntry> foodEntries;

View File

@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "calorimeter")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.calorimeter")
set(APPLICATION_ID "de.swgross.calorimeter")
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.

View File

@ -385,7 +385,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calorimeter.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calorimeter";
@ -399,7 +399,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calorimeter.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calorimeter";
@ -413,7 +413,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/calorimeter.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/calorimeter";

View File

@ -8,7 +8,7 @@
PRODUCT_NAME = calorimeter
// The application's bundle identifier
PRODUCT_BUNDLE_IDENTIFIER = com.example.calorimeter
PRODUCT_BUNDLE_IDENTIFIER = de.swgross.calorimeter
// The copyright displayed in application information
PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved.

View File

@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
barcode_scan2:
dependency: "direct main"
description:
name: barcode_scan2
sha256: a2ab566027cd57b2795ea42aa26835dbaa8fe70bcc1aff54942a14d3705dff97
url: "https://pub.dev"
source: hosted
version: "4.3.3"
bloc:
dependency: transitive
description:
@ -112,19 +120,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
go_router:
dependency: "direct main"
description:
name: go_router
sha256: "2ddb88e9ad56ae15ee144ed10e33886777eb5ca2509a914850a5faa7b52ff459"
url: "https://pub.dev"
source: hosted
version: "14.2.7"
intl:
dependency: "direct main"
description:
@ -165,14 +160,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
@ -277,8 +264,16 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
provider:
protobuf:
dependency: transitive
description:
name: protobuf
sha256: "68645b24e0716782e58948f8467fd42a880f255096a821f9e7d0ec625b00c84d"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
provider:
dependency: "direct main"
description:
name: provider
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c

View File

@ -12,12 +12,13 @@ dependencies:
flutter_bloc: ^8.1.6
flutter_localizations:
sdk: flutter
go_router: ^14.2.7
intl: any
path_provider: ^2.1.4
settings_ui: ^2.0.2
universal_platform: ^1.1.0
uuid: ^4.5.0
barcode_scan2: ^4.3.3
provider: ^6.1.2
dev_dependencies:
flutter_test: