From 90a8524b83300781955d3e0fd21e1b69d0d3fe01 Mon Sep 17 00:00:00 2001 From: Azmat-7860 Date: Wed, 23 Sep 2026 23:04:22 +0530 Subject: [PATCH] fixing wireframe issue --- lib/LocalStorage/DatabaseHelper.dart | 14 +++++++++----- lib/LocalStorage/TableQuery.dart | 10 ++++++---- lib/LocalStorage/UniController.dart | 14 +++++++++++--- lib/main.dart | 15 +++++++++++---- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/LocalStorage/DatabaseHelper.dart b/lib/LocalStorage/DatabaseHelper.dart index 5aaf546..bdbd2ab 100644 --- a/lib/LocalStorage/DatabaseHelper.dart +++ b/lib/LocalStorage/DatabaseHelper.dart @@ -40,14 +40,17 @@ class DatabaseHelper { var openDb = await openDatabase( path, - version: 1, - onCreate: (db, version) => _createDatabaseTables(db), + // OLD: version: 1, + version: 2, + // OLD: onCreate: (db, version) => _createDatabaseTables(db), + onCreate: (db, version) async => await _createDatabaseTables(db), onUpgrade: (db, int oldversion, int newversion) async { if (oldversion < newversion) { - print("Version Upgrade"); + // OLD: print("Version Upgrade"); + await _createDatabaseTables(db); } }, - ); + ); // fix version upgrade + await table creation - by Azmat on 23-sep // Check if the table exists // var tableResult = await openDb.query('sqlite_master', @@ -71,7 +74,8 @@ class DatabaseHelper { } Future _createDatabaseTables(Database db) async { - tablequery.createOtherTable(db); + // OLD: tablequery.createOtherTable(db); + await tablequery.createOtherTable(db); // await table creation before queries run - by Azmat on 23-sep } // create other table diff --git a/lib/LocalStorage/TableQuery.dart b/lib/LocalStorage/TableQuery.dart index 7de839b..c4f2e33 100644 --- a/lib/LocalStorage/TableQuery.dart +++ b/lib/LocalStorage/TableQuery.dart @@ -43,9 +43,10 @@ class TableQuery { extn15 TEXT, phone TEXT, nme TEXT, - imageupload TEXT, + // OLD: imageupload TEXT, + imageupload TEXT // fix trailing comma sqlite error - by Azmat on 23-sep - )'''); + )'''); } else { print('$tableName table exist'); } @@ -81,9 +82,10 @@ class TableQuery { extn14 TEXT, extn15 TEXT, college TEXT, - Name TEXT, + // OLD: Name TEXT, + Name TEXT // fix trailing comma sqlite error - by Azmat on 23-sep - )'''); + )'''); } else { print('$tableName table exist'); } diff --git a/lib/LocalStorage/UniController.dart b/lib/LocalStorage/UniController.dart index 43c4671..41a0868 100644 --- a/lib/LocalStorage/UniController.dart +++ b/lib/LocalStorage/UniController.dart @@ -21,7 +21,8 @@ class UniController { // entity['active'] = entity['active'] ? 1 : 0; // Insert data - var entityId = await db.insert(tableName, entity); + // OLD: var entityId = await db.insert(tableName, entity); + var entityId = await db.insert(tableName, entity, conflictAlgorithm: ConflictAlgorithm.replace); // overwrite same id instead of crash - by Azmat on 23-sep if (entityId != null && entityId > 0) { print('$tableName Id data is inserted. $tableName Id ID: $entityId'); } else { @@ -40,10 +41,12 @@ class UniController { print('multiple entity is com is $entities'); for (var entity in entities) { - insertEntity(entity, tableName); + // OLD: insertEntity(entity, tableName); + batch.insert(tableName, entity, conflictAlgorithm: ConflictAlgorithm.replace); } - await batch.commit(); + // OLD: await batch.commit(); + await batch.commit(); // real batch write with overwrite - by Azmat on 23-sep } // update Entity @@ -81,6 +84,11 @@ class UniController { return rowsAffected; } + Future deleteAll(String tableName) async { + Database db = await conn.database; + return await db.delete(tableName); // clear table for fresh server sync - by Azmat on 23-sep + } + // get count Future getDataCount(String tableNmae) async { Database db = await conn.database; diff --git a/lib/main.dart b/lib/main.dart index 8525bd3..fcfa212 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:sqflite/sqflite.dart'; import 'package:sqflite_common_ffi/sqflite_ffi.dart'; @@ -21,10 +23,15 @@ import 'screens/splash_screen/splash_screen.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - print(sqlite3.version); - sqfliteFfiInit(); - // Initialize the database factory for sqflite_common_ffi - databaseFactory = databaseFactoryFfi; + // OLD: print(sqlite3.version); + // OLD: sqfliteFfiInit(); + // OLD: // Initialize the database factory for sqflite_common_ffi + // OLD: databaseFactory = databaseFactoryFfi; + if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) { // ffi only for desktop, mobile uses native sqflite - by Azmat on 23-sep + print(sqlite3.version); + sqfliteFfiInit(); + databaseFactory = databaseFactoryFfi; + } //Request notification permissions // await _requestNotificationPermissions();