Fix bug that left PerDate widget empty when popped to. #5
@ -71,9 +71,60 @@ class _PerDateWidgetState extends State<PerDateWidget> {
|
|||||||
color: Theme.of(context).colorScheme.secondary,
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
child: SumWidget(foodEntries: state.foodEntries)),
|
child: SumWidget(foodEntries: state.foodEntries)),
|
||||||
drawer: const AppDrawer(),
|
drawer: const AppDrawer(),
|
||||||
floatingActionButton: OverflowBar(children: [
|
floatingActionButton: OverflowBar(
|
||||||
ScanFoodFloatingButton(
|
children: [
|
||||||
onPressed: () async {
|
ScanFoodFloatingButton(onPressed: () {
|
||||||
|
_onScanButtonPressed(context);
|
||||||
|
}),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
CalendarFloatingButton(
|
||||||
|
startFromDate: widget.date,
|
||||||
|
onDateSelected: (dateSelected) {
|
||||||
|
_onDateSelected(dateSelected);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
floatingActionButtonLocation:
|
||||||
|
FloatingActionButtonLocation.endDocked);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void showNewSnackbarWith(BuildContext context, String text) {
|
||||||
|
var snackbar =
|
||||||
|
ErrorSnackbar(colorScheme: Theme.of(context).colorScheme, text: text);
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context)
|
||||||
|
..removeCurrentSnackBar()
|
||||||
|
..showSnackBar(snackbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onDateSelected(DateTime date) {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
|
return PerDateWidget(date: date);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
).then((val) {
|
||||||
|
setState(
|
||||||
|
() {
|
||||||
|
entriesFuture = storage.getEntriesForDate(widget.date);
|
||||||
|
entriesFuture.then(
|
||||||
|
(val) {
|
||||||
|
entries = val;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onScanButtonPressed(BuildContext context) async {
|
||||||
var client = FoodFactLookupClient();
|
var client = FoodFactLookupClient();
|
||||||
|
|
||||||
var scanResult = await BarcodeScanner.scan();
|
var scanResult = await BarcodeScanner.scan();
|
||||||
@ -85,26 +136,20 @@ class _PerDateWidgetState extends State<PerDateWidget> {
|
|||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
if (scanResult.type == ResultType.Error) {
|
if (scanResult.type == ResultType.Error) {
|
||||||
showNewSnackbarWith(context,
|
showNewSnackbarWith(context, "Fehler beim Scannen des Barcodes.");
|
||||||
"Fehler beim Scannen des Barcodes.");
|
|
||||||
}
|
}
|
||||||
var response = await client
|
var response = await client.retrieveFoodInfo(scanResult.rawContent);
|
||||||
.retrieveFoodInfo(scanResult.rawContent);
|
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
if (response.status ==
|
if (response.status == FoodFactResponseStatus.barcodeNotFound) {
|
||||||
FoodFactResponseStatus.barcodeNotFound) {
|
showNewSnackbarWith(context, "Barcode konnte nicht gefunden werden.");
|
||||||
showNewSnackbarWith(context,
|
|
||||||
"Barcode konnte nicht gefunden werden.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status ==
|
if (response.status == FoodFactResponseStatus.foodFactServerNotReachable) {
|
||||||
FoodFactResponseStatus
|
showNewSnackbarWith(
|
||||||
.foodFactServerNotReachable) {
|
context, "OpenFoodFacts-Server konnte nicht erreicht werden.");
|
||||||
showNewSnackbarWith(context,
|
|
||||||
"OpenFoodFacts-Server konnte nicht erreicht werden.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,35 +157,6 @@ class _PerDateWidgetState extends State<PerDateWidget> {
|
|||||||
response.food!.name,
|
response.food!.name,
|
||||||
response.food!.kcalPer100g.toString(),
|
response.food!.kcalPer100g.toString(),
|
||||||
);
|
);
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
CalendarFloatingButton(
|
|
||||||
startFromDate: widget.date,
|
|
||||||
onDateSelected: (dateSelected) {
|
|
||||||
Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) {
|
|
||||||
return PerDateWidget(date: dateSelected);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
floatingActionButtonLocation:
|
|
||||||
FloatingActionButtonLocation.endDocked);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void showNewSnackbarWith(BuildContext context, String text) {
|
|
||||||
var snackbar =
|
|
||||||
ErrorSnackbar(colorScheme: Theme.of(context).colorScheme, text: text);
|
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user