Compare commits
No commits in common. "master" and "fix-empty-page-bug" have entirely different histories.
master
...
fix-empty-
@ -1,10 +1,12 @@
|
|||||||
|
import 'package:calorimeter/utils/enter_food_controller.dart';
|
||||||
import 'package:calorimeter/storage/storage.dart';
|
import 'package:calorimeter/storage/storage.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
||||||
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
|
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class EnterFoodWidget extends StatefulWidget {
|
class EnterFoodWidget extends StatefulWidget {
|
||||||
final Function(BuildContext context, FoodEntryState entry) onAdd;
|
final Function(BuildContext context, FoodEntry entry) onAdd;
|
||||||
|
|
||||||
const EnterFoodWidget({super.key, required this.onAdd});
|
const EnterFoodWidget({super.key, required this.onAdd});
|
||||||
|
|
||||||
@ -16,7 +18,7 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
late TextEditingController nameController;
|
late TextEditingController nameController;
|
||||||
late TextEditingController massController;
|
late TextEditingController massController;
|
||||||
late TextEditingController kcalPerMassController;
|
late TextEditingController kcalPerMassController;
|
||||||
late Map<String, int> suggestions;
|
late Map<String, double> suggestions;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -30,12 +32,18 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return Consumer<EnterFoodController>(
|
||||||
|
builder: (context, food, child) {
|
||||||
|
nameController.text = food.name;
|
||||||
|
kcalPerMassController.text = food.kcalPer100g;
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
child: RowWidget(
|
child: RowWidget(
|
||||||
Autocomplete<String>(
|
Autocomplete<String>(
|
||||||
optionsViewOpenDirection: OptionsViewOpenDirection.down,
|
optionsViewOpenDirection: OptionsViewOpenDirection.down,
|
||||||
fieldViewBuilder: (context, controller, focusNode, onSubmitted) {
|
fieldViewBuilder:
|
||||||
|
(context, controller, focusNode, onSubmitted) {
|
||||||
nameController = controller;
|
nameController = controller;
|
||||||
return TextFormField(
|
return TextFormField(
|
||||||
controller: controller,
|
controller: controller,
|
||||||
@ -59,18 +67,17 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onSelected: (selectedFood) {
|
onSelected: (selectedFood) {
|
||||||
int kcalPerMassForSelectedFood = suggestions[selectedFood]!;
|
double kcalPerMassForSelectedFood =
|
||||||
setState(() {
|
suggestions[selectedFood]!;
|
||||||
nameController.text = selectedFood;
|
context
|
||||||
kcalPerMassController.text =
|
.read<EnterFoodController>()
|
||||||
kcalPerMassForSelectedFood.toString();
|
.set(selectedFood, kcalPerMassForSelectedFood.toString());
|
||||||
});
|
|
||||||
}),
|
}),
|
||||||
TextField(
|
TextField(
|
||||||
textAlign: TextAlign.end,
|
textAlign: TextAlign.end,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
label:
|
label: Align(
|
||||||
Align(alignment: Alignment.centerRight, child: Text("Menge")),
|
alignment: Alignment.centerRight, child: Text("Menge")),
|
||||||
),
|
),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
controller: massController,
|
controller: massController,
|
||||||
@ -80,7 +87,8 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
textAlign: TextAlign.end,
|
textAlign: TextAlign.end,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
label: Align(
|
label: Align(
|
||||||
alignment: Alignment.centerRight, child: Text("kcal pro"))),
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text("kcal pro"))),
|
||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
controller: kcalPerMassController,
|
controller: kcalPerMassController,
|
||||||
onSubmitted: (value) => onSubmitAction(),
|
onSubmitted: (value) => onSubmitAction(),
|
||||||
@ -96,14 +104,16 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSubmitAction() {
|
void onSubmitAction() {
|
||||||
int massAsNumber = 0;
|
double massAsNumber = 0.0;
|
||||||
int kcalPerMassAsNumber = 0;
|
double kcalPerMassAsNumber = 0.0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
massAsNumber = int.parse(massController.text.replaceAll(",", "."));
|
massAsNumber = double.parse(massController.text.replaceAll(",", "."));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var snackbar = const SnackBar(content: Text("Menge muss eine Zahl sein"));
|
var snackbar = const SnackBar(content: Text("Menge muss eine Zahl sein"));
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
@ -113,28 +123,21 @@ class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
kcalPerMassAsNumber =
|
kcalPerMassAsNumber =
|
||||||
int.parse(kcalPerMassController.text.replaceAll(",", "."));
|
double.parse(kcalPerMassController.text.replaceAll(",", "."));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var snackbar =
|
var snackbar =
|
||||||
const SnackBar(content: Text("'kcal pro 100g' muss eine Zahl sein"));
|
const SnackBar(content: Text("'kcal pro 100g' muss eine Zahl sein"));
|
||||||
ScaffoldMessenger.of(context).removeCurrentSnackBar();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var entry = FoodEntryState(
|
var entry = FoodEntry(
|
||||||
name: nameController.text,
|
name: nameController.text,
|
||||||
mass: massAsNumber,
|
mass: massAsNumber,
|
||||||
kcalPer100: kcalPerMassAsNumber,
|
kcalPerMass: kcalPerMassAsNumber);
|
||||||
waitingForNetwork: false,
|
|
||||||
isSelected: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
widget.onAdd(context, entry);
|
widget.onAdd(context, entry);
|
||||||
setState(() {
|
context.read<EnterFoodController>().set("", "");
|
||||||
nameController.text = "";
|
|
||||||
massController.text = "";
|
|
||||||
kcalPerMassController.text = "";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,305 +1,102 @@
|
|||||||
import 'package:barcode_scan2/barcode_scan2.dart';
|
|
||||||
import 'package:calorimeter/food_scan/food_fact_lookup.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:calorimeter/storage/storage.dart';
|
import 'package:calorimeter/storage/storage.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class FoodEntryBloc extends Bloc<FoodEvent, GlobalEntryState> {
|
class FoodEntryBloc extends Bloc<FoodEvent, FoodEntryState> {
|
||||||
final GlobalEntryState initialState;
|
final FoodEntryState initialState;
|
||||||
final FoodStorage storage;
|
final FoodStorage storage;
|
||||||
|
final DateTime forDate;
|
||||||
|
|
||||||
FoodEntryBloc({required this.initialState, required this.storage})
|
FoodEntryBloc(
|
||||||
|
{required this.initialState,
|
||||||
|
required this.forDate,
|
||||||
|
required this.storage})
|
||||||
: super(initialState) {
|
: super(initialState) {
|
||||||
on<PageBeingInitialized>(handlePageBeingInitialized);
|
|
||||||
on<FoodEntryEvent>(handleFoodEntryEvent);
|
on<FoodEntryEvent>(handleFoodEntryEvent);
|
||||||
on<FoodChangedEvent>(handleFoodChangedEvent);
|
on<FoodDeletionEvent>(deleteFood);
|
||||||
on<FoodDeletionEvent>(handleDeleteFoodEvent);
|
on<PageChangedEvent>(updateEntries);
|
||||||
on<BarcodeScanned>(handleBarcodeScannedEvent);
|
|
||||||
on<FoodEntryTapped>(handleFoodEntryTapped);
|
|
||||||
}
|
|
||||||
void handlePageBeingInitialized(
|
|
||||||
PageBeingInitialized event, Emitter<GlobalEntryState> emit) async {
|
|
||||||
var newList = await storage.getEntriesForDate(event.forDate);
|
|
||||||
state.foodEntries.addAll({event.forDate: newList});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: state.foodEntries));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleFoodEntryEvent(
|
void handleFoodEntryEvent(
|
||||||
FoodEntryEvent event, Emitter<GlobalEntryState> emit) async {
|
FoodEntryEvent event, Emitter<FoodEntryState> emit) async {
|
||||||
var entriesForDate = state.foodEntries[event.forDate];
|
FoodEntryState newState = FoodEntryState.from(state);
|
||||||
entriesForDate ??= [];
|
newState.addEntry(event.entry);
|
||||||
|
|
||||||
entriesForDate.add(event.entry);
|
await storage.writeEntriesForDate(forDate, newState.foodEntries);
|
||||||
|
|
||||||
await storage.writeEntriesForDate(event.forDate, entriesForDate);
|
|
||||||
storage.addFoodEntryToLookupDatabase(event.entry);
|
storage.addFoodEntryToLookupDatabase(event.entry);
|
||||||
|
|
||||||
// this is just checking if writing to the database worked
|
emit(newState);
|
||||||
// can be optimized out by just emitting newState
|
|
||||||
var newList = await storage.getEntriesForDate(event.forDate);
|
|
||||||
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: newList});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: newFoodEntries));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleFoodChangedEvent(
|
void deleteFood(FoodDeletionEvent event, Emitter<FoodEntryState> emit) async {
|
||||||
FoodChangedEvent event, Emitter<GlobalEntryState> emit) async {
|
state.foodEntries.removeWhere((entry) => entry.id == event.entryID);
|
||||||
var entriesForDate = state.foodEntries[event.forDate];
|
|
||||||
if (entriesForDate == null) return;
|
|
||||||
|
|
||||||
var index = entriesForDate.indexWhere((entry) {
|
await storage.writeEntriesForDate(forDate, state.foodEntries);
|
||||||
return entry.id == event.newEntry.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
entriesForDate.removeAt(index);
|
emit(FoodEntryState.from(state));
|
||||||
entriesForDate.insert(index, event.newEntry);
|
|
||||||
|
|
||||||
await storage.writeEntriesForDate(event.forDate, entriesForDate);
|
|
||||||
storage.addFoodEntryToLookupDatabase(event.newEntry);
|
|
||||||
|
|
||||||
// this is just checking if writing to the database worked
|
|
||||||
// can be optimized out by just emitting newState
|
|
||||||
var newList = await storage.getEntriesForDate(event.forDate);
|
|
||||||
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: newList});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: newFoodEntries));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleDeleteFoodEvent(
|
void updateEntries(
|
||||||
FoodDeletionEvent event, Emitter<GlobalEntryState> emit) async {
|
PageChangedEvent event, Emitter<FoodEntryState> emit) async {
|
||||||
var entriesForDate = state.foodEntries[event.forDate];
|
var entries = await storage.getEntriesForDate(event.changedToDate);
|
||||||
if (entriesForDate == null) return;
|
var newState = FoodEntryState(foodEntries: entries);
|
||||||
|
emit(newState);
|
||||||
entriesForDate.removeWhere((entry) => entry.id == event.entryID);
|
|
||||||
|
|
||||||
await storage.writeEntriesForDate(event.forDate, entriesForDate);
|
|
||||||
|
|
||||||
// this is just checking if writing to the database worked
|
|
||||||
// can be optimized out by just emitting newState
|
|
||||||
var newList = await storage.getEntriesForDate(event.forDate);
|
|
||||||
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: newList});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: newFoodEntries));
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleBarcodeScannedEvent(
|
|
||||||
BarcodeScanned event, Emitter<GlobalEntryState> emit) async {
|
|
||||||
var entriesForDate = state.foodEntries[event.forDate];
|
|
||||||
if (entriesForDate == null) return;
|
|
||||||
|
|
||||||
var client = FoodFactLookupClient();
|
|
||||||
var scanResult = await event.scanResultFuture;
|
|
||||||
|
|
||||||
if (scanResult.type == ResultType.Cancelled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (scanResult.type == ResultType.Error) {
|
|
||||||
emit(GlobalEntryState(
|
|
||||||
foodEntries: state.foodEntries,
|
|
||||||
errorString: "Fehler beim Scannen des Barcodes"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var responseFuture = client.retrieveFoodInfo(scanResult.rawContent);
|
|
||||||
|
|
||||||
var newEntryWaiting = FoodEntryState(
|
|
||||||
kcalPer100: 0,
|
|
||||||
name: "",
|
|
||||||
mass: 0,
|
|
||||||
waitingForNetwork: true,
|
|
||||||
isSelected: false,
|
|
||||||
);
|
|
||||||
entriesForDate.add(newEntryWaiting);
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: entriesForDate});
|
|
||||||
emit(GlobalEntryState(foodEntries: newFoodEntries));
|
|
||||||
|
|
||||||
await responseFuture.then((response) async {
|
|
||||||
var index = entriesForDate
|
|
||||||
.indexWhere((entryState) => entryState.id == newEntryWaiting.id);
|
|
||||||
|
|
||||||
// element not found (was deleted previously)
|
|
||||||
if (index == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.status == FoodFactResponseStatus.barcodeNotFound) {
|
|
||||||
entriesForDate.removeWhere((entry) => entry.id == newEntryWaiting.id);
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: entriesForDate});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(
|
|
||||||
foodEntries: newFoodEntries,
|
|
||||||
errorString: "Barcode konnte nicht gefunden werden."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (response.status ==
|
|
||||||
FoodFactResponseStatus.foodFactServerNotReachable) {
|
|
||||||
entriesForDate.removeWhere((entry) => entry.id == newEntryWaiting.id);
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: entriesForDate});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(
|
|
||||||
foodEntries: newFoodEntries,
|
|
||||||
errorString: "OpenFoodFacts-Server konnte nicht erreicht werden."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newEntryFinishedWaiting = FoodEntryState(
|
|
||||||
name: response.food?.name ?? "",
|
|
||||||
mass: response.food?.mass ?? 0,
|
|
||||||
kcalPer100: response.food?.kcalPer100g ?? 0,
|
|
||||||
waitingForNetwork: false,
|
|
||||||
isSelected: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
entriesForDate.removeAt(index);
|
|
||||||
entriesForDate.insert(index, newEntryFinishedWaiting);
|
|
||||||
|
|
||||||
await storage.writeEntriesForDate(event.forDate, entriesForDate);
|
|
||||||
storage.addFoodEntryToLookupDatabase(newEntryFinishedWaiting);
|
|
||||||
|
|
||||||
var entriesFromStorage = await storage.getEntriesForDate(event.forDate);
|
|
||||||
var newFoodEntries = state.foodEntries;
|
|
||||||
newFoodEntries.addAll({event.forDate: entriesFromStorage});
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: newFoodEntries));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleFoodEntryTapped(
|
|
||||||
FoodEntryTapped event, Emitter<GlobalEntryState> emit) async {
|
|
||||||
var entriesForDate = state.foodEntries[event.forDate];
|
|
||||||
if (entriesForDate == null) return;
|
|
||||||
|
|
||||||
var oldStateOfTappedEntry = event.entry.isSelected;
|
|
||||||
|
|
||||||
for (var entry in entriesForDate) {
|
|
||||||
entry.isSelected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedEntry = entriesForDate.firstWhere((entry) {
|
|
||||||
return entry.id == event.entry.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
selectedEntry.isSelected = !oldStateOfTappedEntry;
|
|
||||||
|
|
||||||
emit(GlobalEntryState(foodEntries: state.foodEntries));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FoodEvent {
|
class FoodEvent {}
|
||||||
final DateTime forDate;
|
|
||||||
|
|
||||||
FoodEvent({required this.forDate});
|
|
||||||
}
|
|
||||||
|
|
||||||
class PageBeingInitialized extends FoodEvent {
|
|
||||||
PageBeingInitialized({required super.forDate});
|
|
||||||
}
|
|
||||||
|
|
||||||
class FoodEntryEvent extends FoodEvent {
|
class FoodEntryEvent extends FoodEvent {
|
||||||
final FoodEntryState entry;
|
final FoodEntry entry;
|
||||||
|
|
||||||
FoodEntryEvent({required this.entry, required super.forDate});
|
FoodEntryEvent({required this.entry});
|
||||||
}
|
|
||||||
|
|
||||||
class FoodChangedEvent extends FoodEvent {
|
|
||||||
final FoodEntryState newEntry;
|
|
||||||
|
|
||||||
FoodChangedEvent({required this.newEntry, required super.forDate});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FoodDeletionEvent extends FoodEvent {
|
class FoodDeletionEvent extends FoodEvent {
|
||||||
final String entryID;
|
final String entryID;
|
||||||
|
|
||||||
FoodDeletionEvent({required this.entryID, required super.forDate});
|
FoodDeletionEvent({required this.entryID});
|
||||||
}
|
}
|
||||||
|
|
||||||
class BarcodeScanned extends FoodEvent {
|
class PageChangedEvent extends FoodEvent {
|
||||||
final Future<ScanResult> scanResultFuture;
|
final DateTime changedToDate;
|
||||||
|
|
||||||
BarcodeScanned({required this.scanResultFuture, required super.forDate});
|
PageChangedEvent({required this.changedToDate});
|
||||||
}
|
|
||||||
|
|
||||||
class FoodEntryTapped extends FoodEvent {
|
|
||||||
final FoodEntryState entry;
|
|
||||||
|
|
||||||
FoodEntryTapped({required this.entry, required super.forDate});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This is the state for one date/page
|
|
||||||
class GlobalEntryState {
|
|
||||||
final Map<DateTime, List<FoodEntryState>> foodEntries;
|
|
||||||
final String? errorString;
|
|
||||||
|
|
||||||
GlobalEntryState({required this.foodEntries, this.errorString});
|
|
||||||
|
|
||||||
factory GlobalEntryState.init() {
|
|
||||||
return GlobalEntryState(foodEntries: {});
|
|
||||||
}
|
|
||||||
|
|
||||||
static from(GlobalEntryState state) {
|
|
||||||
return GlobalEntryState(foodEntries: state.foodEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addEntry(FoodEntryState entry, DateTime date) {
|
|
||||||
var list = foodEntries[date];
|
|
||||||
|
|
||||||
if (list == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
list.add(entry);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FoodEntryState {
|
class FoodEntryState {
|
||||||
final String id;
|
final List<FoodEntry> foodEntries;
|
||||||
final String name;
|
|
||||||
final int mass;
|
|
||||||
final int kcalPer100;
|
|
||||||
final bool waitingForNetwork;
|
|
||||||
bool isSelected;
|
|
||||||
|
|
||||||
factory FoodEntryState({
|
FoodEntryState({required this.foodEntries});
|
||||||
required name,
|
|
||||||
required mass,
|
factory FoodEntryState.init() {
|
||||||
required kcalPer100,
|
return FoodEntryState(foodEntries: []);
|
||||||
required waitingForNetwork,
|
|
||||||
required isSelected,
|
|
||||||
}) {
|
|
||||||
return FoodEntryState.withID(
|
|
||||||
id: const Uuid().v1(),
|
|
||||||
name: name,
|
|
||||||
mass: mass,
|
|
||||||
kcalPer100: kcalPer100,
|
|
||||||
waitingForNetwork: waitingForNetwork,
|
|
||||||
isSelected: isSelected,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FoodEntryState.withID({
|
static from(FoodEntryState state) {
|
||||||
required this.id,
|
List<FoodEntry> newList = List.from(state.foodEntries);
|
||||||
|
return FoodEntryState(foodEntries: newList);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addEntry(FoodEntry entry) {
|
||||||
|
foodEntries.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FoodEntry {
|
||||||
|
final String name;
|
||||||
|
final double mass;
|
||||||
|
final double kcalPerMass;
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
FoodEntry({
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.mass,
|
required this.mass,
|
||||||
required this.kcalPer100,
|
required this.kcalPerMass,
|
||||||
required this.waitingForNetwork,
|
}) : id = const Uuid().v1();
|
||||||
required this.isSelected,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
//we use quotation marks around the name because the name might contain
|
return '$id,$name,$mass,$kcalPerMass';
|
||||||
//commas and we want to store it in a csv file
|
|
||||||
return '$id,"$name",$mass,$kcalPer100';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,33 +3,33 @@ import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
|||||||
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
|
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
|
||||||
|
|
||||||
class FoodEntryWidget extends StatefulWidget {
|
class FoodEntryWidget extends StatefulWidget {
|
||||||
final FoodEntryState entry;
|
final FoodEntry entry;
|
||||||
final Function(BuildContext context, String id) onDelete;
|
final Function(BuildContext context, String id) onDelete;
|
||||||
final Function(BuildContext context, FoodEntryState entry) onChange;
|
|
||||||
final Function(BuildContext context, FoodEntryState entry) onTap;
|
|
||||||
|
|
||||||
const FoodEntryWidget({
|
const FoodEntryWidget(
|
||||||
super.key,
|
{super.key, required this.entry, required this.onDelete});
|
||||||
required this.entry,
|
|
||||||
required this.onDelete,
|
|
||||||
required this.onChange,
|
|
||||||
required this.onTap,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FoodEntryWidget> createState() => _FoodEntryWidgetState();
|
State<FoodEntryWidget> createState() => _FoodEntryWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
||||||
|
late bool showCancelAndDelete;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
showCancelAndDelete = false;
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => widget.onTap(context, widget.entry),
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
showCancelAndDelete = !showCancelAndDelete;
|
||||||
|
});
|
||||||
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
@ -38,28 +38,15 @@ class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
child: RowWidget(
|
child: RowWidget(
|
||||||
widget.entry.waitingForNetwork
|
Text(widget.entry.name),
|
||||||
? const Center(child: CircularProgressIndicator())
|
Text(widget.entry.mass.ceil().toString(),
|
||||||
: Text(widget.entry.name),
|
textAlign: TextAlign.end),
|
||||||
widget.entry.waitingForNetwork
|
Text(widget.entry.kcalPerMass.ceil().toString(),
|
||||||
? Container()
|
|
||||||
: Text(widget.entry.mass.ceil().toString(),
|
|
||||||
textAlign: TextAlign.end),
|
textAlign: TextAlign.end),
|
||||||
Opacity(
|
Opacity(
|
||||||
opacity: widget.entry.isSelected ? 0.0 : 1.0,
|
opacity: showCancelAndDelete ? 0.0 : 1.0,
|
||||||
child: widget.entry.waitingForNetwork
|
child: Text(
|
||||||
? Container()
|
(widget.entry.mass * widget.entry.kcalPerMass / 100)
|
||||||
: Text(widget.entry.kcalPer100.ceil().toString(),
|
|
||||||
textAlign: TextAlign.end),
|
|
||||||
),
|
|
||||||
Opacity(
|
|
||||||
opacity: widget.entry.isSelected ? 0.0 : 1.0,
|
|
||||||
child: widget.entry.waitingForNetwork
|
|
||||||
? Container()
|
|
||||||
: Text(
|
|
||||||
(widget.entry.mass *
|
|
||||||
widget.entry.kcalPer100 /
|
|
||||||
100)
|
|
||||||
.ceil()
|
.ceil()
|
||||||
.toString(),
|
.toString(),
|
||||||
textAlign: TextAlign.end),
|
textAlign: TextAlign.end),
|
||||||
@ -68,35 +55,26 @@ class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Opacity(
|
Opacity(
|
||||||
opacity: widget.entry.isSelected ? 0.66 : 0.0,
|
opacity: showCancelAndDelete ? 0.66 : 0.0,
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Theme.of(context).colorScheme.secondary)),
|
color: Theme.of(context).colorScheme.secondary)),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
Opacity(
|
Opacity(
|
||||||
opacity: widget.entry.isSelected ? 1.0 : 0.0,
|
opacity: showCancelAndDelete ? 1.0 : 0.0,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
padding: const EdgeInsets.all(0.0),
|
padding: const EdgeInsets.all(0.0),
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.cancel),
|
||||||
onPressed: widget.entry.isSelected
|
onPressed: showCancelAndDelete
|
||||||
? () async {
|
? () => setState(() {
|
||||||
widget.onTap(context, widget.entry);
|
showCancelAndDelete = false;
|
||||||
await showDialog(
|
})
|
||||||
context: context,
|
: null,
|
||||||
builder: (dialogContext) {
|
),
|
||||||
return FoodEntryChangeDialog(
|
|
||||||
entry: widget.entry,
|
|
||||||
onChange: (context, entry) {
|
|
||||||
widget.onChange(context, entry);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
: null),
|
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
@ -104,7 +82,7 @@ class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
|||||||
iconSize: 24,
|
iconSize: 24,
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.delete),
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
onPressed: widget.entry.isSelected
|
onPressed: showCancelAndDelete
|
||||||
? () => widget.onDelete(context, widget.entry.id)
|
? () => widget.onDelete(context, widget.entry.id)
|
||||||
: null),
|
: null),
|
||||||
),
|
),
|
||||||
@ -116,125 +94,3 @@ class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FoodEntryChangeDialog extends StatefulWidget {
|
|
||||||
final FoodEntryState entry;
|
|
||||||
final Function(BuildContext context, FoodEntryState entry) onChange;
|
|
||||||
|
|
||||||
const FoodEntryChangeDialog(
|
|
||||||
{required this.entry, super.key, required this.onChange});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<FoodEntryChangeDialog> createState() => _FoodEntryChangeDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _FoodEntryChangeDialogState extends State<FoodEntryChangeDialog> {
|
|
||||||
late TextEditingController nameController;
|
|
||||||
late TextEditingController massController;
|
|
||||||
late TextEditingController kcalPer100Controller;
|
|
||||||
|
|
||||||
static const textFieldVerticalPadding = 16.0;
|
|
||||||
static const textFieldHorizontalPadding = 16.0;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
nameController = TextEditingController();
|
|
||||||
nameController.text = widget.entry.name;
|
|
||||||
|
|
||||||
massController = TextEditingController();
|
|
||||||
massController.text = widget.entry.mass.toString();
|
|
||||||
|
|
||||||
kcalPer100Controller = TextEditingController();
|
|
||||||
kcalPer100Controller.text = widget.entry.kcalPer100.toString();
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: textFieldVerticalPadding,
|
|
||||||
horizontal: textFieldHorizontalPadding),
|
|
||||||
child: TextField(
|
|
||||||
onSubmitted: (val) => _onSubmitAction(),
|
|
||||||
controller: nameController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
label: Text("Name"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: textFieldVerticalPadding,
|
|
||||||
horizontal: textFieldHorizontalPadding),
|
|
||||||
child: TextField(
|
|
||||||
onSubmitted: (val) => _onSubmitAction(),
|
|
||||||
controller: massController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
label: Text("Menge"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: textFieldVerticalPadding,
|
|
||||||
horizontal: textFieldHorizontalPadding),
|
|
||||||
child: TextField(
|
|
||||||
onSubmitted: (val) => _onSubmitAction(),
|
|
||||||
controller: kcalPer100Controller,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
label: Text("kcal pro Menge"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.cancel)),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () => _onSubmitAction(),
|
|
||||||
icon: const Icon(Icons.check),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onSubmitAction() {
|
|
||||||
int mass;
|
|
||||||
int kcalPer100;
|
|
||||||
|
|
||||||
try {
|
|
||||||
mass = int.parse(massController.text);
|
|
||||||
} catch (e) {
|
|
||||||
mass = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
kcalPer100 = int.parse(kcalPer100Controller.text);
|
|
||||||
} catch (e) {
|
|
||||||
kcalPer100 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newEntry = FoodEntryState.withID(
|
|
||||||
id: widget.entry.id,
|
|
||||||
name: nameController.text,
|
|
||||||
mass: mass,
|
|
||||||
kcalPer100: kcalPer100,
|
|
||||||
waitingForNetwork: widget.entry.waitingForNetwork,
|
|
||||||
isSelected: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
widget.onChange(context, newEntry);
|
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -45,28 +45,13 @@ class FoodFactLookupClient {
|
|||||||
class FoodFactModel {
|
class FoodFactModel {
|
||||||
final String name;
|
final String name;
|
||||||
final int kcalPer100g;
|
final int kcalPer100g;
|
||||||
final int mass;
|
|
||||||
|
|
||||||
FoodFactModel({
|
FoodFactModel({required this.name, required this.kcalPer100g});
|
||||||
required this.name,
|
|
||||||
required this.mass,
|
|
||||||
required this.kcalPer100g,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory FoodFactModel.fromJson(Map<String, dynamic> json) {
|
factory FoodFactModel.fromJson(Map<String, dynamic> json) {
|
||||||
String quantityString = json['product']['product_quantity'] ?? "0";
|
|
||||||
int quantity;
|
|
||||||
|
|
||||||
try {
|
|
||||||
quantity = int.parse(quantityString);
|
|
||||||
} catch (e) {
|
|
||||||
quantity = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FoodFactModel(
|
return FoodFactModel(
|
||||||
name: json['product']['product_name'],
|
name: json['product']['product_name'],
|
||||||
kcalPer100g: json['product']['nutriments']['energy-kcal_100g'],
|
kcalPer100g: json['product']['nutriments']['energy-kcal_100g']);
|
||||||
mass: quantity);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,33 +1,15 @@
|
|||||||
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
import 'package:calorimeter/perdate/perdate_widget.dart';
|
||||||
import 'package:calorimeter/perdate/perdate_pageview.dart';
|
|
||||||
import 'package:calorimeter/storage/storage.dart';
|
import 'package:calorimeter/storage/storage.dart';
|
||||||
import 'package:calorimeter/utils/settings_bloc.dart';
|
import 'package:calorimeter/utils/settings_bloc.dart';
|
||||||
import 'package:calorimeter/utils/theme_bloc.dart';
|
import 'package:calorimeter/utils/theme_bloc.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
|
|
||||||
List<FoodEntryState> entriesForToday = [];
|
|
||||||
DateTime timeNow = DateTime.now();
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
var storage = await FoodStorage.create();
|
var storage = await FoodStorage.create();
|
||||||
await storage.buildFoodLookupDatabase();
|
await storage.buildFoodLookupDatabase();
|
||||||
timeNow = DateTime.now().copyWith(
|
|
||||||
hour: 0,
|
|
||||||
isUtc: true,
|
|
||||||
minute: 0,
|
|
||||||
second: 0,
|
|
||||||
millisecond: 0,
|
|
||||||
microsecond: 0);
|
|
||||||
|
|
||||||
entriesForToday = await storage.getEntriesForDate(timeNow);
|
|
||||||
|
|
||||||
var kcalLimit = await storage.readLimit();
|
var kcalLimit = await storage.readLimit();
|
||||||
var brightness = await storage.readBrightness();
|
var brightness = await storage.readBrightness();
|
||||||
|
|
||||||
@ -56,13 +38,6 @@ class MainApp extends StatelessWidget {
|
|||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: MultiBlocProvider(
|
child: MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(
|
|
||||||
create: (context) => FoodEntryBloc(
|
|
||||||
storage: storage,
|
|
||||||
initialState:
|
|
||||||
GlobalEntryState(foodEntries: {timeNow: entriesForToday}),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => SettingsDataBloc(
|
create: (context) => SettingsDataBloc(
|
||||||
SettingsState(kcalLimit: kcalLimit),
|
SettingsState(kcalLimit: kcalLimit),
|
||||||
@ -81,25 +56,8 @@ class MainApp extends StatelessWidget {
|
|||||||
newBrightness = Brightness.dark;
|
newBrightness = Brightness.dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MaterialApp.router(
|
return MaterialApp(
|
||||||
routerConfig: GoRouter(
|
home: PerDateWidget(date: DateTime.now()),
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: '/',
|
|
||||||
builder: (context, state) {
|
|
||||||
return PerDatePageview(
|
|
||||||
initalDate: DateTime.now().copyWith(
|
|
||||||
hour: 0,
|
|
||||||
minute: 0,
|
|
||||||
second: 0,
|
|
||||||
millisecond: 0,
|
|
||||||
microsecond: 0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
localizationsDelegates: const [
|
localizationsDelegates: const [
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
GlobalWidgetsLocalizations.delegate,
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
@ -5,12 +5,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
class FoodEntryList extends StatelessWidget {
|
class FoodEntryList extends StatelessWidget {
|
||||||
final List<FoodEntryState> entries;
|
final List<FoodEntry> entries;
|
||||||
final DateTime date;
|
|
||||||
|
|
||||||
const FoodEntryList({
|
const FoodEntryList({
|
||||||
required this.entries,
|
required this.entries,
|
||||||
required this.date,
|
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -19,7 +17,6 @@ class FoodEntryList extends StatelessWidget {
|
|||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: entries.length + 1,
|
itemCount: entries.length + 1,
|
||||||
itemBuilder: (BuildContext itemBuilderContext, int listIndex) {
|
itemBuilder: (BuildContext itemBuilderContext, int listIndex) {
|
||||||
//last item in list is the widget to enter food
|
|
||||||
if (listIndex == entries.length) {
|
if (listIndex == entries.length) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
@ -27,7 +24,7 @@ class FoodEntryList extends StatelessWidget {
|
|||||||
onAdd: (context, entry) {
|
onAdd: (context, entry) {
|
||||||
context
|
context
|
||||||
.read<FoodEntryBloc>()
|
.read<FoodEntryBloc>()
|
||||||
.add(FoodEntryEvent(entry: entry, forDate: date));
|
.add(FoodEntryEvent(entry: entry));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 75),
|
const SizedBox(height: 75),
|
||||||
@ -41,20 +38,10 @@ class FoodEntryList extends StatelessWidget {
|
|||||||
FoodEntryWidget(
|
FoodEntryWidget(
|
||||||
key: ValueKey(entries[entryIndex].id),
|
key: ValueKey(entries[entryIndex].id),
|
||||||
entry: entries[entryIndex],
|
entry: entries[entryIndex],
|
||||||
onDelete: (_, id) {
|
onDelete: (callbackContext, id) {
|
||||||
context
|
callbackContext.read<FoodEntryBloc>().add(FoodDeletionEvent(
|
||||||
.read<FoodEntryBloc>()
|
entryID: id,
|
||||||
.add(FoodDeletionEvent(entryID: id, forDate: date));
|
));
|
||||||
},
|
|
||||||
onChange: (_, changedEntry) {
|
|
||||||
context.read<FoodEntryBloc>().add(
|
|
||||||
FoodChangedEvent(newEntry: changedEntry, forDate: date),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onTap: (_, tappedEntry) {
|
|
||||||
context.read<FoodEntryBloc>().add(
|
|
||||||
FoodEntryTapped(entry: tappedEntry, forDate: date),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
import 'package:calorimeter/perdate/perdate_widget.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
class PerDatePageview extends StatefulWidget {
|
|
||||||
// this is the date for which the PerDate widget will be shown on screen
|
|
||||||
// left of it will be yesterday's PerDate widget
|
|
||||||
// right of it will be tomorrow's PerDate widget
|
|
||||||
final DateTime initalDate;
|
|
||||||
const PerDatePageview({required this.initalDate, super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<PerDatePageview> createState() => _PerDatePageviewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PerDatePageviewState extends State<PerDatePageview> {
|
|
||||||
late PageController pageController;
|
|
||||||
late DateTime displayedDate;
|
|
||||||
late List<int> visitedIndexes = [];
|
|
||||||
final int initialOffset = 36500000;
|
|
||||||
|
|
||||||
//TODO: that is just ugly
|
|
||||||
bool backButtonWasPressed = false;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
pageController = PageController(initialPage: initialOffset);
|
|
||||||
displayedDate = widget.initalDate;
|
|
||||||
visitedIndexes.add(initialOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BackButtonListener(
|
|
||||||
onBackButtonPressed: () async {
|
|
||||||
if (visitedIndexes.length == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
visitedIndexes.removeLast();
|
|
||||||
|
|
||||||
backButtonWasPressed = true;
|
|
||||||
pageController.jumpToPage(visitedIndexes.last);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
child: PageView.builder(
|
|
||||||
reverse: true,
|
|
||||||
controller: pageController,
|
|
||||||
onPageChanged: (value) {
|
|
||||||
if (backButtonWasPressed) {
|
|
||||||
backButtonWasPressed = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
visitedIndexes.add(value);
|
|
||||||
},
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
var dateToBuildWidgetFor =
|
|
||||||
displayedDate.subtract(Duration(days: index - initialOffset));
|
|
||||||
|
|
||||||
return PerDateWidget(
|
|
||||||
key: ValueKey(dateToBuildWidgetFor.toString()),
|
|
||||||
date: dateToBuildWidgetFor.copyWith(isUtc: true),
|
|
||||||
onDateSelected: (dateSelected) {
|
|
||||||
if (dateSelected == null) return;
|
|
||||||
|
|
||||||
var diff = dateSelected.difference(dateToBuildWidgetFor);
|
|
||||||
var newIndex = index - diff.inDays;
|
|
||||||
|
|
||||||
pageController.jumpToPage(newIndex);
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,6 @@
|
|||||||
import 'package:barcode_scan2/barcode_scan2.dart';
|
import 'package:barcode_scan2/barcode_scan2.dart';
|
||||||
|
import 'package:calorimeter/food_scan/food_fact_lookup.dart';
|
||||||
|
import 'package:calorimeter/utils/enter_food_controller.dart';
|
||||||
import 'package:calorimeter/utils/scan_food_floating_button.dart';
|
import 'package:calorimeter/utils/scan_food_floating_button.dart';
|
||||||
import 'package:calorimeter/utils/app_drawer.dart';
|
import 'package:calorimeter/utils/app_drawer.dart';
|
||||||
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
||||||
@ -11,83 +13,84 @@ import 'package:calorimeter/utils/theme_switcher_button.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class PerDateWidget extends StatefulWidget {
|
class PerDateWidget extends StatefulWidget {
|
||||||
final DateTime date;
|
final DateTime date;
|
||||||
final Function(DateTime?) onDateSelected;
|
const PerDateWidget({super.key, required this.date});
|
||||||
const PerDateWidget(
|
|
||||||
{super.key, required this.date, required this.onDateSelected});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PerDateWidget> createState() => _PerDateWidgetState();
|
State<PerDateWidget> createState() => _PerDateWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PerDateWidgetState extends State<PerDateWidget>
|
class _PerDateWidgetState extends State<PerDateWidget> {
|
||||||
with AutomaticKeepAliveClientMixin<PerDateWidget> {
|
|
||||||
late FoodStorage storage;
|
late FoodStorage storage;
|
||||||
List<FoodEntryState> entries = [];
|
late Future<List<FoodEntry>> entriesFuture;
|
||||||
|
List<FoodEntry> entries = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
context
|
storage = FoodStorage.getInstance();
|
||||||
.read<FoodEntryBloc>()
|
entriesFuture = storage.getEntriesForDate(widget.date);
|
||||||
.add(PageBeingInitialized(forDate: widget.date));
|
entriesFuture.then((val) {
|
||||||
|
entries = val;
|
||||||
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
super.build(context);
|
return FutureBuilder(
|
||||||
|
future: entriesFuture,
|
||||||
return BlocConsumer<FoodEntryBloc, GlobalEntryState>(
|
builder: (context, snapshot) {
|
||||||
listener: (context, pageState) {
|
return snapshot.connectionState != ConnectionState.done
|
||||||
if (pageState.errorString != null) {
|
? const Center(child: CircularProgressIndicator())
|
||||||
showNewSnackbarWith(context, pageState.errorString!);
|
: MultiProvider(
|
||||||
}
|
providers: [
|
||||||
},
|
ChangeNotifierProvider(
|
||||||
builder: (context, globalState) {
|
create: (context) => EnterFoodController()),
|
||||||
|
BlocProvider(
|
||||||
|
create: (context) => FoodEntryBloc(
|
||||||
|
initialState: FoodEntryState(foodEntries: entries),
|
||||||
|
storage: storage,
|
||||||
|
forDate: widget.date,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
child: BlocBuilder<FoodEntryBloc, FoodEntryState>(
|
||||||
|
builder: (context, state) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(DateFormat.yMMMMd('de').format(widget.date)),
|
title:
|
||||||
|
Text(DateFormat.yMMMMd('de').format(widget.date)),
|
||||||
actions: const [ThemeSwitcherButton()],
|
actions: const [ThemeSwitcherButton()],
|
||||||
),
|
),
|
||||||
body: FoodEntryList(
|
body: FoodEntryList(entries: state.foodEntries),
|
||||||
entries: globalState.foodEntries[widget.date] ?? [],
|
|
||||||
date: widget.date),
|
|
||||||
bottomNavigationBar: BottomAppBar(
|
bottomNavigationBar: BottomAppBar(
|
||||||
shape: const RectangularNotchShape(),
|
shape: const RectangularNotchShape(),
|
||||||
color: Theme.of(context).colorScheme.secondary,
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
child: SumWidget(
|
child: SumWidget(foodEntries: state.foodEntries)),
|
||||||
foodEntries: globalState.foodEntries[widget.date] ?? [])),
|
|
||||||
drawer: const AppDrawer(),
|
drawer: const AppDrawer(),
|
||||||
floatingActionButton: OverflowBar(children: [
|
floatingActionButton: OverflowBar(
|
||||||
ScanFoodFloatingButton(
|
children: [
|
||||||
onPressed: () {
|
ScanFoodFloatingButton(onPressed: () {
|
||||||
var result = BarcodeScanner.scan();
|
_onScanButtonPressed(context);
|
||||||
context.read<FoodEntryBloc>().add(
|
}),
|
||||||
BarcodeScanned(
|
|
||||||
scanResultFuture: result,
|
|
||||||
forDate: widget.date,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
CalendarFloatingButton(
|
CalendarFloatingButton(
|
||||||
startFromDate: widget.date,
|
startFromDate: widget.date,
|
||||||
onDateSelected: (dateSelected) {
|
onDateSelected: (dateSelected) {
|
||||||
widget.onDateSelected(dateSelected);
|
_onDateSelected(dateSelected);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]),
|
],
|
||||||
|
),
|
||||||
floatingActionButtonLocation:
|
floatingActionButtonLocation:
|
||||||
FloatingActionButtonLocation.endDocked);
|
FloatingActionButtonLocation.endDocked);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,8 +103,61 @@ class _PerDateWidgetState extends State<PerDateWidget>
|
|||||||
..showSnackBar(snackbar);
|
..showSnackBar(snackbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
void _onDateSelected(DateTime date) {
|
||||||
bool get wantKeepAlive => true;
|
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 scanResult = await BarcodeScanner.scan();
|
||||||
|
|
||||||
|
if (scanResult.type == ResultType.Cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
|
if (scanResult.type == ResultType.Error) {
|
||||||
|
showNewSnackbarWith(context, "Fehler beim Scannen des Barcodes.");
|
||||||
|
}
|
||||||
|
var response = await client.retrieveFoodInfo(scanResult.rawContent);
|
||||||
|
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
|
if (response.status == FoodFactResponseStatus.barcodeNotFound) {
|
||||||
|
showNewSnackbarWith(context, "Barcode konnte nicht gefunden werden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status == FoodFactResponseStatus.foodFactServerNotReachable) {
|
||||||
|
showNewSnackbarWith(
|
||||||
|
context, "OpenFoodFacts-Server konnte nicht erreicht werden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.read<EnterFoodController>().set(
|
||||||
|
response.food!.name,
|
||||||
|
response.food!.kcalPer100g.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ErrorSnackbar extends SnackBar {
|
class ErrorSnackbar extends SnackBar {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:developer';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
||||||
@ -7,7 +8,7 @@ import 'package:universal_platform/universal_platform.dart';
|
|||||||
class FoodStorage {
|
class FoodStorage {
|
||||||
static late FoodStorage _instance;
|
static late FoodStorage _instance;
|
||||||
late String path;
|
late String path;
|
||||||
final Map<String, int> _foodLookupDatabase = {};
|
final Map<String, double> _foodLookupDatabase = {};
|
||||||
|
|
||||||
FoodStorage._create();
|
FoodStorage._create();
|
||||||
|
|
||||||
@ -30,8 +31,8 @@ class FoodStorage {
|
|||||||
|
|
||||||
static FoodStorage getInstance() => _instance;
|
static FoodStorage getInstance() => _instance;
|
||||||
|
|
||||||
Future<List<FoodEntryState>> getEntriesForDate(DateTime date) async {
|
Future<List<FoodEntry>> getEntriesForDate(DateTime date) async {
|
||||||
List<FoodEntryState> entries = [];
|
List<FoodEntry> entries = [];
|
||||||
var filePath = '$path/${date.year}/${date.month}/${date.day}';
|
var filePath = '$path/${date.year}/${date.month}/${date.day}';
|
||||||
|
|
||||||
var file = File(filePath);
|
var file = File(filePath);
|
||||||
@ -42,29 +43,11 @@ class FoodStorage {
|
|||||||
var lines = await file.readAsLines();
|
var lines = await file.readAsLines();
|
||||||
|
|
||||||
for (var line in lines) {
|
for (var line in lines) {
|
||||||
var fields = line.splitWithIgnore(',', ignoreIn: '"');
|
var fields = line.split(',');
|
||||||
int mass = 0;
|
var entry = FoodEntry(
|
||||||
int kcalPerMass = 0;
|
name: fields[1],
|
||||||
|
mass: double.parse(fields[2]),
|
||||||
try {
|
kcalPerMass: double.parse(fields[3]));
|
||||||
mass = int.parse(fields[2]);
|
|
||||||
} catch (e) {
|
|
||||||
mass = double.parse(fields[2]).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
kcalPerMass = int.parse(fields[3]);
|
|
||||||
} catch (e) {
|
|
||||||
kcalPerMass = double.parse(fields[3]).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
var entry = FoodEntryState(
|
|
||||||
name: fields[1].replaceAll('"', ""),
|
|
||||||
mass: mass,
|
|
||||||
kcalPer100: kcalPerMass,
|
|
||||||
waitingForNetwork: false,
|
|
||||||
isSelected: false,
|
|
||||||
);
|
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +55,7 @@ class FoodStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> writeEntriesForDate(
|
Future<void> writeEntriesForDate(
|
||||||
DateTime date, List<FoodEntryState> foodEntries) async {
|
DateTime date, List<FoodEntry> foodEntries) async {
|
||||||
var filePath = '$path/${date.year}/${date.month}/${date.day}';
|
var filePath = '$path/${date.year}/${date.month}/${date.day}';
|
||||||
var file = File(filePath);
|
var file = File(filePath);
|
||||||
|
|
||||||
@ -156,11 +139,11 @@ class FoodStorage {
|
|||||||
Future<void> buildFoodLookupDatabase() async {
|
Future<void> buildFoodLookupDatabase() async {
|
||||||
// get a list of dates of the last 365 days
|
// get a list of dates of the last 365 days
|
||||||
var dates = List<DateTime>.generate(365, (idx) {
|
var dates = List<DateTime>.generate(365, (idx) {
|
||||||
var durationToPast = Duration(days: idx);
|
var pastDay = Duration(days: idx);
|
||||||
return DateTime.now().subtract(durationToPast);
|
return DateTime.now().subtract(pastDay);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var date in dates.reversed) {
|
for (var date in dates) {
|
||||||
addFoodEntryToLookupDatabaseFor(date);
|
addFoodEntryToLookupDatabaseFor(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,52 +152,15 @@ class FoodStorage {
|
|||||||
var entriesForDate = await getEntriesForDate(date);
|
var entriesForDate = await getEntriesForDate(date);
|
||||||
|
|
||||||
for (var entry in entriesForDate) {
|
for (var entry in entriesForDate) {
|
||||||
_foodLookupDatabase[entry.name] = entry.kcalPer100;
|
_foodLookupDatabase[entry.name] = entry.kcalPerMass;
|
||||||
|
log("Added entry: ${entry.name}/${entry.kcalPerMass}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addFoodEntryToLookupDatabase(FoodEntryState entry) {
|
void addFoodEntryToLookupDatabase(FoodEntry entry) {
|
||||||
_foodLookupDatabase[entry.name] = entry.kcalPer100;
|
_foodLookupDatabase[entry.name] = entry.kcalPerMass;
|
||||||
|
log("Added entry: ${entry.name}/${entry.kcalPerMass}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, int> get getFoodEntryLookupDatabase => _foodLookupDatabase;
|
Map<String, double> get getFoodEntryLookupDatabase => _foodLookupDatabase;
|
||||||
}
|
|
||||||
|
|
||||||
extension SplitWithIgnore on String {
|
|
||||||
List<String> splitWithIgnore(String delimiter, {String? ignoreIn}) {
|
|
||||||
List<String> parts = [];
|
|
||||||
|
|
||||||
if (ignoreIn == null) {
|
|
||||||
return split(delimiter);
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = -1;
|
|
||||||
int indexCharAfterDelimiter = 0;
|
|
||||||
bool inIgnore = false;
|
|
||||||
for (var rune in runes) {
|
|
||||||
var char = String.fromCharCode(rune);
|
|
||||||
|
|
||||||
index += 1;
|
|
||||||
|
|
||||||
if (char == ignoreIn) {
|
|
||||||
inIgnore = !inIgnore;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inIgnore) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (char == delimiter) {
|
|
||||||
parts.add(substring(indexCharAfterDelimiter, index));
|
|
||||||
indexCharAfterDelimiter = index + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index + 1 == length) {
|
|
||||||
parts.add(substring(indexCharAfterDelimiter, length));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class CalendarFloatingButton extends StatelessWidget {
|
class CalendarFloatingButton extends StatelessWidget {
|
||||||
final DateTime startFromDate;
|
final DateTime startFromDate;
|
||||||
final Function(DateTime?) onDateSelected;
|
final Function(DateTime) onDateSelected;
|
||||||
|
|
||||||
const CalendarFloatingButton(
|
const CalendarFloatingButton(
|
||||||
{super.key, required this.startFromDate, required this.onDateSelected});
|
{super.key, required this.startFromDate, required this.onDateSelected});
|
||||||
@ -17,12 +17,12 @@ class CalendarFloatingButton extends StatelessWidget {
|
|||||||
initialDate: startFromDate,
|
initialDate: startFromDate,
|
||||||
currentDate: DateTime.now(),
|
currentDate: DateTime.now(),
|
||||||
firstDate: DateTime.now().subtract(const Duration(days: 365 * 10)),
|
firstDate: DateTime.now().subtract(const Duration(days: 365 * 10)),
|
||||||
lastDate: DateTime.now().add(const Duration(days: 365 * 10)),
|
lastDate: DateTime.now(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
onDateSelected(datePicked);
|
onDateSelected(datePicked ?? DateTime.now());
|
||||||
},
|
},
|
||||||
heroTag: "calendarFAB",
|
heroTag: "calendarFAB",
|
||||||
child: const Icon(Icons.today),
|
child: const Icon(Icons.today),
|
||||||
|
12
lib/utils/enter_food_controller.dart
Normal file
12
lib/utils/enter_food_controller.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class EnterFoodController extends ChangeNotifier {
|
||||||
|
String name = "";
|
||||||
|
String kcalPer100g = "";
|
||||||
|
|
||||||
|
void set(String newName, String newKcal) {
|
||||||
|
name = newName;
|
||||||
|
kcalPer100g = newKcal;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
|||||||
import 'package:calorimeter/utils/settings_bloc.dart';
|
import 'package:calorimeter/utils/settings_bloc.dart';
|
||||||
|
|
||||||
class SumWidget extends StatelessWidget {
|
class SumWidget extends StatelessWidget {
|
||||||
final List<FoodEntryState> foodEntries;
|
final List<FoodEntry> foodEntries;
|
||||||
const SumWidget({required this.foodEntries, super.key});
|
const SumWidget({required this.foodEntries, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -13,7 +13,7 @@ class SumWidget extends StatelessWidget {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
var sum = 0.0;
|
var sum = 0.0;
|
||||||
for (var entry in foodEntries) {
|
for (var entry in foodEntries) {
|
||||||
sum += entry.kcalPer100 / 100 * entry.mass;
|
sum += entry.kcalPerMass / 100 * entry.mass;
|
||||||
}
|
}
|
||||||
var diff = state.kcalLimit - sum;
|
var diff = state.kcalLimit - sum;
|
||||||
var diffLimit = state.kcalLimit ~/ 4;
|
var diffLimit = state.kcalLimit ~/ 4;
|
||||||
|
294
pubspec.lock
294
pubspec.lock
@ -1,27 +1,6 @@
|
|||||||
# Generated by pub
|
# Generated by pub
|
||||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||||
packages:
|
packages:
|
||||||
_fe_analyzer_shared:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: _fe_analyzer_shared
|
|
||||||
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "72.0.0"
|
|
||||||
_macros:
|
|
||||||
dependency: transitive
|
|
||||||
description: dart
|
|
||||||
source: sdk
|
|
||||||
version: "0.3.2"
|
|
||||||
analyzer:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: analyzer
|
|
||||||
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "6.7.0"
|
|
||||||
archive:
|
archive:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -110,22 +89,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.18.0"
|
version: "1.18.0"
|
||||||
convert:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: convert
|
|
||||||
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.1.1"
|
|
||||||
coverage:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: coverage
|
|
||||||
sha256: c1fb2dce3c0085f39dc72668e85f8e0210ec7de05345821ff58530567df345a5
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.9.2"
|
|
||||||
crypto:
|
crypto:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -150,14 +113,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.1.3"
|
||||||
file:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: file
|
|
||||||
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "7.0.0"
|
|
||||||
fixnum:
|
fixnum:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -183,18 +138,18 @@ packages:
|
|||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: flutter_launcher_icons
|
name: flutter_launcher_icons
|
||||||
sha256: "619817c4b65b322b5104b6bb6dfe6cda62d9729bd7ad4303ecc8b4e690a67a77"
|
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.14.1"
|
version: "0.13.1"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: flutter_lints
|
name: flutter_lints
|
||||||
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
|
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.0"
|
version: "4.0.0"
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -205,51 +160,6 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_web_plugins:
|
|
||||||
dependency: transitive
|
|
||||||
description: flutter
|
|
||||||
source: sdk
|
|
||||||
version: "0.0.0"
|
|
||||||
frontend_server_client:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: frontend_server_client
|
|
||||||
sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "4.0.0"
|
|
||||||
glob:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: glob
|
|
||||||
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.1.2"
|
|
||||||
go_router:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: go_router
|
|
||||||
sha256: "6f1b756f6e863259a99135ff3c95026c3cdca17d10ebef2bba2261a25ddc8bbc"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "14.3.0"
|
|
||||||
http_multi_server:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: http_multi_server
|
|
||||||
sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.2.1"
|
|
||||||
http_parser:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: http_parser
|
|
||||||
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "4.0.2"
|
|
||||||
image:
|
image:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -266,22 +176,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.19.0"
|
version: "0.19.0"
|
||||||
io:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: io
|
|
||||||
sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.4"
|
|
||||||
js:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: js
|
|
||||||
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.7.1"
|
|
||||||
json_annotation:
|
json_annotation:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -318,26 +212,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: lints
|
name: lints
|
||||||
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
|
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.0"
|
version: "4.0.0"
|
||||||
logging:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: logging
|
|
||||||
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.0"
|
|
||||||
macros:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: macros
|
|
||||||
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.1.2-main.4"
|
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -362,14 +240,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0"
|
version: "1.15.0"
|
||||||
mime:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: mime
|
|
||||||
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.0"
|
|
||||||
nested:
|
nested:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -378,22 +248,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
node_preamble:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: node_preamble
|
|
||||||
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.2"
|
|
||||||
package_config:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: package_config
|
|
||||||
sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.1.0"
|
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -414,10 +268,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: path_provider_android
|
name: path_provider_android
|
||||||
sha256: f7544c346a0742aee1450f9e5c0f5269d7c602b9c95fdbcd9fb8f5b1df13b1cc
|
sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.2.11"
|
version: "2.2.10"
|
||||||
path_provider_foundation:
|
path_provider_foundation:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -474,14 +328,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.8"
|
version: "2.1.8"
|
||||||
pool:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pool
|
|
||||||
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.5.1"
|
|
||||||
protobuf:
|
protobuf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -498,14 +344,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.2"
|
version: "6.1.2"
|
||||||
pub_semver:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: pub_semver
|
|
||||||
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.1.4"
|
|
||||||
settings_ui:
|
settings_ui:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -514,59 +352,11 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.2"
|
version: "2.0.2"
|
||||||
shelf:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shelf
|
|
||||||
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.4.1"
|
|
||||||
shelf_packages_handler:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shelf_packages_handler
|
|
||||||
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.0.2"
|
|
||||||
shelf_static:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shelf_static
|
|
||||||
sha256: c87c3875f91262785dade62d135760c2c69cb217ac759485334c5857ad89f6e3
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.1.3"
|
|
||||||
shelf_web_socket:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: shelf_web_socket
|
|
||||||
sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.0"
|
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.99"
|
version: "0.0.99"
|
||||||
source_map_stack_trace:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: source_map_stack_trace
|
|
||||||
sha256: c0713a43e323c3302c2abe2a1cc89aa057a387101ebd280371d6a6c9fa68516b
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.1.2"
|
|
||||||
source_maps:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: source_maps
|
|
||||||
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.10.12"
|
|
||||||
source_span:
|
source_span:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -615,14 +405,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.1"
|
version: "1.2.1"
|
||||||
test:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: test
|
|
||||||
sha256: "7ee44229615f8f642b68120165ae4c2a75fe77ae2065b1e55ae4711f6cf0899e"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.25.7"
|
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -631,14 +413,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.2"
|
version: "0.7.2"
|
||||||
test_core:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: test_core
|
|
||||||
sha256: "55ea5a652e38a1dfb32943a7973f3681a60f872f8c3a05a14664ad54ef9c6696"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.6.4"
|
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -659,10 +433,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: uuid
|
name: uuid
|
||||||
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
|
sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.5.1"
|
version: "4.5.0"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -679,54 +453,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "14.2.5"
|
version: "14.2.5"
|
||||||
watcher:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: watcher
|
|
||||||
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.1.0"
|
|
||||||
web:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: web
|
|
||||||
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.1.0"
|
|
||||||
web_socket:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: web_socket
|
|
||||||
sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "0.1.6"
|
|
||||||
web_socket_channel:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: web_socket_channel
|
|
||||||
sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "3.0.1"
|
|
||||||
webkit_inspection_protocol:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: webkit_inspection_protocol
|
|
||||||
sha256: "87d3f2333bb240704cd3f1c6b5b7acd8a10e7f0bc28c28dcf14e782014f4a572"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "1.2.1"
|
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: xdg_directories
|
name: xdg_directories
|
||||||
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
|
sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.0.4"
|
||||||
xml:
|
xml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -744,5 +478,5 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.5.3 <4.0.0"
|
dart: ">=3.5.2 <4.0.0"
|
||||||
flutter: ">=3.24.0"
|
flutter: ">=3.22.0"
|
||||||
|
@ -4,7 +4,7 @@ publish_to: 'none'
|
|||||||
version: 1.1.0
|
version: 1.1.0
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.3
|
sdk: ^3.5.2
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
@ -19,14 +19,12 @@ dependencies:
|
|||||||
uuid: ^4.5.0
|
uuid: ^4.5.0
|
||||||
barcode_scan2: ^4.3.3
|
barcode_scan2: ^4.3.3
|
||||||
provider: ^6.1.2
|
provider: ^6.1.2
|
||||||
test: ^1.25.7
|
|
||||||
go_router: ^14.3.0
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_lints: ^5.0.0
|
flutter_lints: ^4.0.0
|
||||||
flutter_launcher_icons: ^0.14.1
|
flutter_launcher_icons: "^0.13.1"
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
import 'package:calorimeter/storage/storage.dart';
|
|
||||||
import 'package:test/test.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group(
|
|
||||||
'Test custom split with ignore',
|
|
||||||
() {
|
|
||||||
test('string without ignoring', () {
|
|
||||||
var testString = 'This is a test string';
|
|
||||||
var resultingList = testString.splitWithIgnore(' ');
|
|
||||||
|
|
||||||
expect(resultingList[0], equals('This'));
|
|
||||||
expect(resultingList[1], equals('is'));
|
|
||||||
expect(resultingList[2], equals('a'));
|
|
||||||
expect(resultingList[3], equals('test'));
|
|
||||||
expect(resultingList[4], equals('string'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('string that does not contain the ignored character', () {
|
|
||||||
var testString = 'This is a test string';
|
|
||||||
var resultingList = testString.splitWithIgnore(' ', ignoreIn: '"');
|
|
||||||
|
|
||||||
expect(resultingList[0], equals('This'));
|
|
||||||
expect(resultingList[1], equals('is'));
|
|
||||||
expect(resultingList[2], equals('a'));
|
|
||||||
expect(resultingList[3], equals('test'));
|
|
||||||
expect(resultingList[4], equals('string'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test(
|
|
||||||
'string that contains ignored character',
|
|
||||||
() {
|
|
||||||
var testString = 'This is "a test" string';
|
|
||||||
var resultingList = testString.splitWithIgnore(' ', ignoreIn: '"');
|
|
||||||
|
|
||||||
expect(resultingList[0], equals('This'));
|
|
||||||
expect(resultingList[1], equals('is'));
|
|
||||||
expect(resultingList[2], equals('"a test"'));
|
|
||||||
expect(resultingList[3], equals('string'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
|
||||||
'string that contains commas that should be ignored',
|
|
||||||
() {
|
|
||||||
var testString =
|
|
||||||
'f9a96b80-71f9-11ef-8df4-f3628a737a16,"Erdnüsse, geröstet",120.0,100.0';
|
|
||||||
var resultingList = testString.splitWithIgnore(',', ignoreIn: '"');
|
|
||||||
|
|
||||||
expect(
|
|
||||||
resultingList[0], equals('f9a96b80-71f9-11ef-8df4-f3628a737a16'));
|
|
||||||
expect(resultingList[1], equals('"Erdnüsse, geröstet"'));
|
|
||||||
expect(resultingList[2], equals('120.0'));
|
|
||||||
expect(resultingList[3], equals('100.0'));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user