[settings] blank page for now with just local storage reset [storage] implement diary
This commit is contained in:
		
							parent
							
								
									33fe0eff39
								
							
						
					
					
						commit
						85cdd68ac1
					
				
					 6 changed files with 84 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -32,4 +32,17 @@ class Diary {
 | 
			
		|||
        carb = map['carb'] as double,
 | 
			
		||||
        fat = map['fat'] as double,
 | 
			
		||||
        fiber = map['fiber'] as double;
 | 
			
		||||
 | 
			
		||||
  Map<String, Object?> toMap() {
 | 
			
		||||
    return {
 | 
			
		||||
      'id': id,
 | 
			
		||||
      'date': date.toIso8601String(),
 | 
			
		||||
      'meals': meals.map((e) => e.toMap()).toList(),
 | 
			
		||||
      'calories': calories,
 | 
			
		||||
      'protein': protein,
 | 
			
		||||
      'carb': carb,
 | 
			
		||||
      'fat': fat,
 | 
			
		||||
      'fiber': fiber,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,4 +33,18 @@ class Entry {
 | 
			
		|||
        fat = map['fat'] as double,
 | 
			
		||||
        fiber = map['fiber'] as double,
 | 
			
		||||
        carb = map['carb'] as double;
 | 
			
		||||
 | 
			
		||||
  Map<String, Object?> toMap() {
 | 
			
		||||
    return {
 | 
			
		||||
      'id': id,
 | 
			
		||||
      'grams': grams,
 | 
			
		||||
      'product': product.toMap(),
 | 
			
		||||
      'mealId': mealId,
 | 
			
		||||
      'calories': calories,
 | 
			
		||||
      'protein': protein,
 | 
			
		||||
      'fat': fat,
 | 
			
		||||
      'fiber': fiber,
 | 
			
		||||
      'carb': carb,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,4 +38,18 @@ class Meal {
 | 
			
		|||
        fat = map['fat'] as double,
 | 
			
		||||
        fiber = map['fiber'] as double,
 | 
			
		||||
        diaryId = map['diary_id'] as int;
 | 
			
		||||
 | 
			
		||||
  Map<String, Object?> toMap() {
 | 
			
		||||
    return {
 | 
			
		||||
      'id': id,
 | 
			
		||||
      'name': name,
 | 
			
		||||
      'order': order,
 | 
			
		||||
      'calories': calories,
 | 
			
		||||
      'protein': protein,
 | 
			
		||||
      'fat': fat,
 | 
			
		||||
      'fiber': fiber,
 | 
			
		||||
      'carb': carb,
 | 
			
		||||
      'diaryId': diaryId,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,4 +25,16 @@ class Preset {
 | 
			
		|||
        carb = map['carb'] as double,
 | 
			
		||||
        fat = map['fat'] as double,
 | 
			
		||||
        fiber = map['fiber'] as double;
 | 
			
		||||
 | 
			
		||||
  Map<String, Object?> toMap() {
 | 
			
		||||
    return {
 | 
			
		||||
      'id': id,
 | 
			
		||||
      'name': name,
 | 
			
		||||
      'calories': calories,
 | 
			
		||||
      'protein': protein,
 | 
			
		||||
      'fat': fat,
 | 
			
		||||
      'fiber': fiber,
 | 
			
		||||
      'carb': carb,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ import 'package:fooder/components/app_bar.dart';
 | 
			
		|||
import 'package:fooder/components/navigation_bar.dart';
 | 
			
		||||
import 'package:fooder/screens/login.dart';
 | 
			
		||||
import 'package:fooder/screens/main.dart';
 | 
			
		||||
import 'package:fooder/screens/settings.dart';
 | 
			
		||||
 | 
			
		||||
TextStyle logoStyle(context) {
 | 
			
		||||
  return Theme.of(context).textTheme.labelLarge!.copyWith(
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +31,7 @@ abstract class BasedState<T extends BasedScreen> extends State<T> {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  void backToLogin() {
 | 
			
		||||
    Navigator.of(context).popUntil((route) => route.isFirst);
 | 
			
		||||
    Navigator.pushReplacement(
 | 
			
		||||
      context,
 | 
			
		||||
      MaterialPageRoute(
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +41,7 @@ abstract class BasedState<T extends BasedScreen> extends State<T> {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  void backToDiary() {
 | 
			
		||||
    Navigator.of(context).popUntil((route) => route.isFirst);
 | 
			
		||||
    Navigator.pushReplacement(
 | 
			
		||||
      context,
 | 
			
		||||
      MaterialPageRoute(
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +50,15 @@ abstract class BasedState<T extends BasedScreen> extends State<T> {
 | 
			
		|||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void navigateToSettings() {
 | 
			
		||||
    Navigator.push(
 | 
			
		||||
      context,
 | 
			
		||||
      MaterialPageRoute(
 | 
			
		||||
        builder: (context) => SettingsScreen(ctx: ctx),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  FAppBar appBar() {
 | 
			
		||||
    return FAppBar(
 | 
			
		||||
      actions: [
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +105,7 @@ abstract class BasedState<T extends BasedScreen> extends State<T> {
 | 
			
		|||
                Icons.person,
 | 
			
		||||
                color: Theme.of(context).colorScheme.onSurfaceVariant,
 | 
			
		||||
              ),
 | 
			
		||||
              onPressed: () {},
 | 
			
		||||
              onPressed: navigateToSettings,
 | 
			
		||||
            ),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,14 +4,16 @@ import 'package:flutter/widgets.dart';
 | 
			
		|||
import 'package:path/path.dart';
 | 
			
		||||
import 'package:sqflite/sqflite.dart';
 | 
			
		||||
import 'package:fooder/storage/product.dart';
 | 
			
		||||
import 'package:fooder/storage/diary.dart';
 | 
			
		||||
 | 
			
		||||
class Storage {
 | 
			
		||||
  Database db;
 | 
			
		||||
  ProductStorage product;
 | 
			
		||||
  DiaryStorage diary;
 | 
			
		||||
 | 
			
		||||
  static const String path = "storage.db";
 | 
			
		||||
 | 
			
		||||
  Storage({required this.db, required this.product});
 | 
			
		||||
  Storage({required this.db, required this.product, required this.diary});
 | 
			
		||||
 | 
			
		||||
  static Future<Storage> create() async {
 | 
			
		||||
    WidgetsFlutterBinding.ensureInitialized();
 | 
			
		||||
| 
						 | 
				
			
			@ -20,12 +22,26 @@ class Storage {
 | 
			
		|||
      onCreate: createTables,
 | 
			
		||||
      version: 1,
 | 
			
		||||
    );
 | 
			
		||||
    return Storage(db: db, product: ProductStorage(db: db));
 | 
			
		||||
    return Storage(
 | 
			
		||||
        db: db, product: ProductStorage(db: db), diary: DiaryStorage(db: db));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> reset() async {
 | 
			
		||||
    await db.close();
 | 
			
		||||
    await deleteDatabase(join(await getDatabasesPath(), path));
 | 
			
		||||
    db = await openDatabase(
 | 
			
		||||
      join(await getDatabasesPath(), path),
 | 
			
		||||
      onCreate: createTables,
 | 
			
		||||
      version: 1,
 | 
			
		||||
    );
 | 
			
		||||
    product = ProductStorage(db: db);
 | 
			
		||||
    diary = DiaryStorage(db: db);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static Future<void> createTables(Database db, int version) async {
 | 
			
		||||
    var batch = db.batch();
 | 
			
		||||
    await ProductStorage.createTable(batch);
 | 
			
		||||
    await DiaryStorage.createTable(batch);
 | 
			
		||||
    await batch.commit(noResult: true);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue