From 76e16e7ace492be498df2cd7b26d07c36f7bd805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rigo?= <104947103+RIGOandre@users.noreply.github.com> Date: Tue, 11 Mar 2025 16:10:23 -0300 Subject: [PATCH] Revert "Update build.gradle" --- android/app/build.gradle | 21 +-- android/app/src/main/AndroidManifest.xml | 3 +- lib/db/database_helper.dart | 169 ++++++----------------- 3 files changed, 51 insertions(+), 142 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 62124b8..32e7238 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -41,30 +41,21 @@ android { } defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.matchmaster" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } - signingConfigs { - release { - keyAlias 'androiddebugkey' - keyPassword 'android' - storeFile file('debug.keystore') - storePassword 'android' - } - } - buildTypes { release { - signingConfig signingConfigs.release - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - signingConfig signingConfigs.release + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug } } } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 41b0743..7c0bda6 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ 'DatabaseException: $message ${code != null ? '(Code: $code)' : ''}'; -} - class DatabaseHelper { static final DatabaseHelper _instance = DatabaseHelper._internal(); static Database? _database; @@ -32,30 +22,25 @@ class DatabaseHelper { sqfliteFfiInit(); databaseFactory = databaseFactoryFfi; } + Future partidaExiste(String nomePartida) async { + final db = await database; + var res = await db.query('matches', where: 'nomePartida = ?', whereArgs: [nomePartida]); + return res.isNotEmpty; + } + _database = await _initDatabase(); return _database!; } - Future partidaExiste(String nomePartida) async { - final db = await database; - var res = await db.query('matches', where: 'nomePartida = ?', whereArgs: [nomePartida]); - return res.isNotEmpty; - } - Future _initDatabase() async { - try { - String path = join(await getDatabasesPath(), 'matchmasterrr.db'); - return await openDatabase( - path, - version: 2, - onCreate: _onCreate, - onUpgrade: _onUpgrade, - ); - } catch (e) { - print('Error initializing database: $e'); - throw Exception('Could not initialize database'); - } + String path = join(await getDatabasesPath(), 'matchmasterrr.db'); + return await openDatabase( + path, + version: 2, //v2 + onCreate: _onCreate, + + ); } Future _onCreate(Database db, int version) async { @@ -68,42 +53,24 @@ class DatabaseHelper { ); - await db.execute(''' - CREATE TABLE matches( + await db.execute( + '''CREATE TABLE matches( id INTEGER PRIMARY KEY AUTOINCREMENT, - team1Name TEXT NOT NULL, - team2Name TEXT NOT NULL, - team1Score INTEGER NOT NULL, - team2Score INTEGER NOT NULL, - matchDuration TEXT NOT NULL, - nomePartida TEXT UNIQUE NOT NULL, - team1Players TEXT NOT NULL, - team2Players TEXT NOT NULL, - winner TEXT NOT NULL, - sport TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ) - '''); - - // Add indexes - await db.execute('CREATE INDEX idx_sport ON matches(sport)'); - await db.execute('CREATE INDEX idx_winner ON matches(winner)'); + team1Name TEXT, + team2Name TEXT, + team1Score INTEGER, + team2Score INTEGER, + matchDuration TEXT, + nomePartida TEXT, + team1Players TEXT, + team2Players TEXT, + winner TEXT, + sport TEXT + )''', + ); } - Future _onUpgrade(Database db, int oldVersion, int newVersion) async { - // Xử lý upgrade database version - } - Future deleteDatabase() async { - try { - String path = join(await getDatabasesPath(), 'matchmasterrr.db'); - await databaseFactory.deleteDatabase(path); - _database = null; - } catch (e) { - print('Error deleting database: $e'); - throw Exception('Could not delete database'); - } - } Future insertMatch( String team1Name, @@ -117,37 +84,22 @@ class DatabaseHelper { String sport, {required String nomePartida,} ) async { - // Validate data - if (team1Name.isEmpty || team2Name.isEmpty) { - throw Exception('Team names cannot be empty'); - } - - if (team1Score < 0 || team2Score < 0) { - throw Exception('Scores cannot be negative'); - } - - try { - final db = await database; - return await db.insert( - 'matches', - { - 'team1Name': team1Name, - 'team2Name': team2Name, - 'team1Score': team1Score, - 'team2Score': team2Score, - 'matchDuration': duration, - 'nomePartida': nomePartida, - 'team1Players': team1Players, - 'team2Players': team2Players, - 'winner': winner, - 'sport': sport, - }, - conflictAlgorithm: ConflictAlgorithm.replace, - ); - } catch (e) { - print('Error inserting match: $e'); - throw Exception('Could not save match'); - } + final db = await database; + return await db.insert( + 'matches', + { + 'team1Name': team1Name, + 'team2Name': team2Name, + 'team1Score': team1Score, + 'team2Score': team2Score, + 'matchDuration': duration, + 'nomePartida': nomePartida, + 'team1Players': team1Players, + 'team2Players': team2Players, + 'winner': winner, + 'sport': sport, + }, + ); } Future>> getMatches() async { @@ -159,39 +111,4 @@ class DatabaseHelper { final db = await database; await db.close(); } - - // Get matches by sport - Future>> getMatchesBySport(String sport) async { - final db = await database; - return await db.query( - 'matches', - where: 'sport = ?', - whereArgs: [sport], - orderBy: 'created_at DESC', - ); - } - - // Update match - Future updateMatch(int id, Map data) async { - try { - final db = await database; - return await db.update( - 'matches', - data, - where: 'id = ?', - whereArgs: [id], - ); - } catch (e) { - print('Error updating match: $e'); - throw Exception('Could not update match'); - } - } - - // Execute in transaction - Future executeInTransaction(Future Function(Transaction txn) action) async { - final db = await database; - await db.transaction((txn) async { - await action(txn); - }); - } } \ No newline at end of file