Flutter-Ernaehrungsapp/lib/android/config/setup_todaybox_config.dart

54 lines
1.4 KiB
Dart
Raw Normal View History

import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:hive/hive.dart';
import '../models/food.dart';
final List<Food> emptyList = [];
Future<void> setupTodayBox() async {
final todayBoxExist = await Hive.boxExists(dotenv.env['TODAY_BOX']!);
final todayBoxOpened = Hive.isBoxOpen(dotenv.env['TODAY_BOX']!);
if (!todayBoxOpened && !todayBoxExist){
Hive.openBox(dotenv.env['TODAY_BOX']!);
}
setupEatingKeys();
}
void setupEatingKeys() async {
final todayBox = Hive.box(dotenv.env['TODAY_BOX']!);
final breakfastExist = todayBox.containsKey(dotenv.env['BREAKFAST_FIELD']!);
final lunchExist = todayBox.containsKey(dotenv.env['LUNCH_FIELD']!);
final dinnerExist = todayBox.containsKey(dotenv.env['DINNER_FIELD']!);
if (!breakfastExist){
todayBox.put(dotenv.env['BREAKFAST_FIELD']!, emptyList);
}
if (!lunchExist){
todayBox.put(dotenv.env['LUNCH_FIELD']!, emptyList);
}
if (!dinnerExist){
todayBox.put(dotenv.env['DINNER_FIELD']!, emptyList);
}
setupDateField();
}
void setupDateField() async{
final todayBox = Hive.box(dotenv.env['TODAY_BOX']!);
final dateExist = todayBox.containsKey(dotenv.env['DATE_FIELD']!);
if (!dateExist){
todayBox.put(dotenv.env['DATE_FIELD']!, getFormatedTodayDate());
}
}
void moveTodayBoxDataToYesterdayAndBefore() async{
}
String getFormatedTodayDate(){
return DateTime.now().toString().substring(0,10);
}