getUserDetails static method
Implementation
static Future<User?> getUserDetails() async {
// if (_database == null) {
// await initializeDatabase();
// }
List<Map<String, Object?>>? userMaps = await _database?.query(
userTableName,
where: 'slno = ?',
whereArgs: [1], // Assuming slno is always 1
);
if (userMaps != null && userMaps.isNotEmpty) {
final propsJsonString = userMaps.first['props'] as String?;
if (propsJsonString != null && propsJsonString.isNotEmpty) {
final props = Props.fromJson(jsonDecode(propsJsonString));
final user = User(
uid: userMaps.first['uid'] as String,
extId: userMaps.first['ext_id'] as String,
name: userMaps.first['name'] as String?,
email: userMaps.first['email'] as String?,
phone: userMaps.first['phone'] as String?,
props: props,
);
_userController.add(user);
// return User(
// uid: userMaps.first['uid'] as String,
// ext_id: userMaps.first['ext_id'] as String,
// name: userMaps.first['name'] as String?,
// email: userMaps.first['email'] as String?,
// phone: userMaps.first['phone'] as String?,
// props: props,
// );
return user;
} else {
final user = User(
uid: userMaps.first['uid'] as String,
extId: userMaps.first['ext_id'] as String,
name: userMaps.first['name'] as String?,
email: userMaps.first['email'] as String?,
phone: userMaps.first['phone'] as String?,
props: null,
);
_userController.add(user);
return user;
// return User(
// uid: userMaps.first['uid'] as String,
// ext_id: userMaps.first['ext_id'] as String,
// name: userMaps.first['name'] as String?,
// email: userMaps.first['email'] as String?,
// phone: userMaps.first['phone'] as String?,
// props: null, // Set props to null if JSON string is empty or null
// );
}
} else {
return null;
}
}