diff --git a/lib/database/database_service.dart b/lib/database/database_service.dart index be57d0b..d2c01b5 100644 --- a/lib/database/database_service.dart +++ b/lib/database/database_service.dart @@ -68,16 +68,22 @@ class DatabaseService { static Future addCategory(Category category) async { final db = await _getDatabase(); - return await db.insert(categoryTableName, category.toJson(), - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.insert( + categoryTableName, + category.toJson(), + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future updateCategory(Category category) async { final db = await _getDatabase(); - return await db.update(categoryTableName, category.toJson(), - where: 'id = ?', - whereArgs: [category.id], - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.update( + categoryTableName, + category.toJson(), + where: 'id = ?', + whereArgs: [category.id], + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future deleteCategory(Category category) async { @@ -93,7 +99,9 @@ class DatabaseService { await db.query(categoryTableName, orderBy: orderBy); if (maps.isNotEmpty) { return List.generate( - maps.length, (index) => Category.fromJson(maps[index])); + maps.length, + (index) => Category.fromJson(maps[index]), + ); } else { return null; } @@ -105,16 +113,22 @@ class DatabaseService { static Future addReview(Review review) async { final db = await _getDatabase(); - return await db.insert(reviewTableName, review.toJson(), - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.insert( + reviewTableName, + review.toJson(), + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future updateReview(Review review) async { final db = await _getDatabase(); - return await db.update(reviewTableName, review.toJson(), - where: 'id = ?', - whereArgs: [review.id], - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.update( + reviewTableName, + review.toJson(), + where: 'id = ?', + whereArgs: [review.id], + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future deleteReview(Review review) async { @@ -123,14 +137,17 @@ class DatabaseService { .delete(reviewTableName, where: 'id = ?', whereArgs: [review.id]); } - static Future?> getAllReviews( - {String orderBy = 'restaurantName ASC'}) async { + static Future?> getAllReviews({ + String orderBy = 'restaurantName ASC', + }) async { final db = await _getDatabase(); final List> maps = await db.query(reviewTableName, orderBy: orderBy); if (maps.isNotEmpty) { return List.generate( - maps.length, (index) => Review.fromJson(maps[index])); + maps.length, + (index) => Review.fromJson(maps[index]), + ); } else { return null; } @@ -148,26 +165,38 @@ class DatabaseService { } static Future?> getReviewsByColumn( - String columnName, String columnValue, - {String orderBy = 'restaurantName ASC'}) async { + String columnName, + String columnValue, { + String orderBy = 'restaurantName ASC', + }) async { final db = await _getDatabase(); - final List> maps = await db.query(reviewTableName, - orderBy: orderBy, - where: '$columnName LIKE ? OR $columnName LIKE ? OR $columnName LIKE ?', - whereArgs: ['%$columnValue', '%$columnValue,%', '%, $columnValue, %']); + final List> maps = await db.query( + reviewTableName, + orderBy: orderBy, + where: '$columnName LIKE ? OR $columnName LIKE ? OR $columnName LIKE ?', + whereArgs: ['%$columnValue', '%$columnValue,%', '%, $columnValue, %'], + ); if (maps.isNotEmpty) { return List.generate( - maps.length, (index) => Review.fromJson(maps[index])); + maps.length, + (index) => Review.fromJson(maps[index]), + ); } else { return null; } } static Future updateReviewFavourite( - int reviewId, int isFavourite) async { + int reviewId, + int isFavourite, + ) async { final db = await _getDatabase(); - return await db.update(reviewTableName, {'isFavourite': isFavourite}, - where: 'id = ?', whereArgs: [reviewId]); + return await db.update( + reviewTableName, + {'isFavourite': isFavourite}, + where: 'id = ?', + whereArgs: [reviewId], + ); } //============================= @@ -176,16 +205,22 @@ class DatabaseService { static Future addChecklistItem(ChecklistItem item) async { final db = await _getDatabase(); - return await db.insert(checklistItemTableName, item.toJson(), - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.insert( + checklistItemTableName, + item.toJson(), + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future updateChecklistItem(ChecklistItem item) async { final db = await _getDatabase(); - return await db.update(checklistItemTableName, item.toJson(), - where: 'id = ?', - whereArgs: [item.id], - conflictAlgorithm: ConflictAlgorithm.replace); + return await db.update( + checklistItemTableName, + item.toJson(), + where: 'id = ?', + whereArgs: [item.id], + conflictAlgorithm: ConflictAlgorithm.replace, + ); } static Future deleteChecklistItem(ChecklistItem item) async { @@ -201,7 +236,9 @@ class DatabaseService { await db.query(checklistItemTableName, orderBy: orderBy); if (maps.isNotEmpty) { return List.generate( - maps.length, (index) => ChecklistItem.fromJson(maps[index])); + maps.length, + (index) => ChecklistItem.fromJson(maps[index]), + ); } else { return null; } @@ -213,16 +250,22 @@ class DatabaseService { .query(checklistItemTableName, where: 'isChecked = ?', whereArgs: [0]); if (maps.isNotEmpty) { return List.generate( - maps.length, (index) => ChecklistItem.fromJson(maps[index])); + maps.length, + (index) => ChecklistItem.fromJson(maps[index]), + ); } else { - throw Exception('Checklist not found'); + return null; } } static Future updateChecklistItemChecked(int id, int isChecked) async { final db = await _getDatabase(); - return await db.update(checklistItemTableName, {'isChecked': isChecked}, - where: 'id = ?', whereArgs: [id]); + return await db.update( + checklistItemTableName, + {'isChecked': isChecked}, + where: 'id = ?', + whereArgs: [id], + ); } static backupDatabase() async { @@ -242,8 +285,12 @@ class DatabaseService { File source = File('$dbFolder/$databaseName'); Directory copyTo = Directory('/storage/emulated/0/Tabemashou Backup'); await copyTo.create(); - await source.copy(join(copyTo.path, - 'FoodReviews_${now.day}_${now.month}_${now.year}-${now.hour}_${now.minute}.db')); + await source.copy( + join( + copyTo.path, + 'FoodReviews_${now.day}_${now.month}_${now.year}-${now.hour}_${now.minute}.db', + ), + ); } catch (e) { print(e); } @@ -294,8 +341,11 @@ class DatabaseService { // Check if the "reviews" table exists bool reviewTableExists = false; try { - var result = await database.query('sqlite_master', - where: 'name = ?', whereArgs: [reviewTableName]); + var result = await database.query( + 'sqlite_master', + where: 'name = ?', + whereArgs: [reviewTableName], + ); reviewTableExists = result.isNotEmpty; } catch (e) { print("Error checking 'reviews' table: $e"); @@ -304,8 +354,11 @@ class DatabaseService { // Check if the "categories" table exists bool categoryTableExists = false; try { - var result = await database.query('sqlite_master', - where: 'name = ?', whereArgs: [categoryTableName]); + var result = await database.query( + 'sqlite_master', + where: 'name = ?', + whereArgs: [categoryTableName], + ); categoryTableExists = result.isNotEmpty; } catch (e) { print("Error checking 'categories' table: $e"); @@ -314,8 +367,11 @@ class DatabaseService { // Check if the "checklist items" table exists bool checklistItemTableExists = false; try { - var result = await database.query('sqlite_master', - where: 'name = ?', whereArgs: [checklistItemTableName]); + var result = await database.query( + 'sqlite_master', + where: 'name = ?', + whereArgs: [checklistItemTableName], + ); checklistItemTableExists = result.isNotEmpty; } catch (e) { print("Error checking 'checklist items' table: $e"); diff --git a/lib/widgets/form/review_form.dart b/lib/widgets/form/review_form.dart index ceaa8ea..0f57d84 100644 --- a/lib/widgets/form/review_form.dart +++ b/lib/widgets/form/review_form.dart @@ -222,6 +222,7 @@ class _ReviewFormState extends State { //-----Select Categories Button----- SizedBox( width: 110, + height: 60, child: ElevatedButton( onPressed: _selectCategories, child: Text( diff --git a/pubspec.yaml b/pubspec.yaml index b4a362d..3c6f6c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.1.0 +version: 1.1.1 environment: sdk: '>=3.0.6 <4.0.0'