Commits (2)
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import '../model/student.dart';
class DatabaseHelper {
static final DatabaseHelper instance = DatabaseHelper._instance();
static Database? _database;
DatabaseHelper._instance();
Future<Database> get db async {
_database ??= await initDb();
return _database!;
}
Future<Database> initDb() async {
String databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'student_university.db');
return await openDatabase(path, version: 1, onCreate: _onCreate);
}
Future _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE student (
studentNFCCardId TEXT PRIMARY KEY,
firstName TEXT,
name TEXT,
promotion TEXT,
studentId TEXT
)
''');
}
Future<int> insertUser(Student student) async {
Database db = await instance.db;
return await db.insert('student', student.toMap());
}
Future<List<Map<String, dynamic>>> queryAllUsers() async {
Database db = await instance.db;
return await db.query('student');
}
Future<int> updateUser(Student student) async {
Database db = await instance.db;
return await db.update('student', student.toMap(), where: 'studentNFCCardId = ?', whereArgs: [student.studentNFCCardId]);
}
Future<int> deleteUser(String studentNFCCardId) async {
Database db = await instance.db;
return await db.delete('student', where: 'studentNFCCardId = ?', whereArgs: [studentNFCCardId]);
}
}
\ No newline at end of file
class Student {
final String studentNFCCardId;
final String firstName;
final String name;
final String promotion;
final String studentId;
Student({
required this.studentNFCCardId,
required this.firstName,
required this.name,
required this.promotion,
required this.studentId
});
Map<String, dynamic> toMap() {
return {
'studentNFCCardId': studentNFCCardId,
'firstName': firstName,
'name': name,
'promotion': promotion,
'studentId': studentId
};
}
factory Student.fromMap(Map<String, dynamic> map) {
return Student(
studentNFCCardId: map['studentNFCCardId'],
firstName: map['firstName'],
name: map['name'],
promotion: map['promotion'],
studentId: map['studentId']
);
}
}
\ No newline at end of file
......@@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation
import sqflite_darwin
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
}
......@@ -132,13 +132,29 @@ packages:
source: hosted
version: "1.16.0"
path:
dependency: transitive
dependency: "direct main"
description:
name: path
sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
sky_engine:
dependency: transitive
description: flutter
......@@ -152,6 +168,46 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.1"
sqflite:
dependency: "direct main"
description:
name: sqflite
sha256: e2297b1da52f127bc7a3da11439985d9b536f75070f3325e62ada69a5c585d03
url: "https://pub.dev"
source: hosted
version: "2.4.2"
sqflite_android:
dependency: transitive
description:
name: sqflite_android
sha256: ecd684501ebc2ae9a83536e8b15731642b9570dc8623e0073d227d0ee2bfea88
url: "https://pub.dev"
source: hosted
version: "2.4.2+2"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
sha256: "6ef422a4525ecc601db6c0a2233ff448c731307906e92cabc9ba292afaae16a6"
url: "https://pub.dev"
source: hosted
version: "2.5.6"
sqflite_darwin:
dependency: transitive
description:
name: sqflite_darwin
sha256: "279832e5cde3fe99e8571879498c9211f3ca6391b0d818df4e17d9fff5c6ccb3"
url: "https://pub.dev"
source: hosted
version: "2.4.2"
sqflite_platform_interface:
dependency: transitive
description:
name: sqflite_platform_interface
sha256: "8dd4515c7bdcae0a785b0062859336de775e8c65db81ae33dd5445f35be61920"
url: "https://pub.dev"
source: hosted
version: "2.4.0"
stack_trace:
dependency: transitive
description:
......@@ -176,6 +232,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.1"
synchronized:
dependency: transitive
description:
name: synchronized
sha256: c254ade258ec8282947a0acbbc90b9575b4f19673533ee46f2f6e9b3aeefd7c0
url: "https://pub.dev"
source: hosted
version: "3.4.0"
term_glyph:
dependency: transitive
description:
......@@ -210,4 +274,4 @@ packages:
version: "15.0.2"
sdks:
dart: ">=3.9.2 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.24.0"
......@@ -30,6 +30,8 @@ environment:
dependencies:
flutter:
sdk: flutter
sqflite: ^2.4.2
path: ^1.9.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
......