my Post Cards added with get api and more changes

This commit is contained in:
mystery012728
2026-02-05 12:07:33 +05:30
parent 082bb9b74a
commit c2ffc9d9a7
69 changed files with 5658 additions and 2168 deletions

View File

@@ -67,10 +67,29 @@ class LocalDatabase {
full_name TEXT NOT NULL,
email_address TEXT NOT NULL,
role TEXT NOT NULL,
role_id INTEGER NOT NULL
role_id INTEGER NOT NULL,
profile_image TEXT
)
''');
/// PASS CART TABLE
await db.execute('''
CREATE TABLE pass_cart (
id INTEGER PRIMARY KEY,
city_name TEXT NOT NULL,
hero_image TEXT NOT NULL,
card_type_name TEXT NOT NULL,
card_display_name TEXT NOT NULL,
theme_color INTEGER NOT NULL,
adult_count INTEGER NOT NULL,
child_count INTEGER NOT NULL,
adult_price REAL NOT NULL,
child_price REAL NOT NULL,
validity_duration INTEGER NOT NULL,
total_price REAL NOT NULL,
description TEXT
)
''');
},
);

View File

@@ -1,4 +1,5 @@
import 'package:sqflite/sqflite.dart';
import 'package:flutter/foundation.dart';
import 'local_database.dart';
class LocalPreference {
@@ -121,6 +122,18 @@ class LocalPreference {
return false;
}
static Future<void> clearLogin() async {
final db = await LocalDatabase().database;
await db.update(
'login_state',
{'is_logged_in': 0},
where: 'id = ?',
whereArgs: [1],
);
}
/// Set user tokens
static Future<void> setTokens({
required String accessToken,
@@ -205,6 +218,7 @@ class LocalPreference {
required String emailAddress,
required String role,
required int roleId,
String? profileImage, // Added optional profileImage parameter
}) async {
final db = await LocalDatabase().database;
@@ -219,6 +233,7 @@ class LocalPreference {
'email_address': emailAddress,
'role': role,
'role_id': roleId,
'profile_image': profileImage, // Include profile image
},
conflictAlgorithm: ConflictAlgorithm.replace,
);
@@ -240,5 +255,218 @@ class LocalPreference {
return null;
}
/// Set profile image with error handling
static Future<void> setProfileImage(String imageUrl) async {
try {
final db = await LocalDatabase().database;
final result = await db.update(
'user_details',
{'profile_image': imageUrl},
where: 'id = ?',
whereArgs: [1],
);
if (kDebugMode) {
print('✅ [LOCAL_PREF] Profile image saved: $imageUrl');
print('📊 [LOCAL_PREF] Rows affected: $result');
}
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error saving profile image: $e');
}
rethrow;
}
}
/// Get profile image
static Future<String?> getProfileImage() async {
try {
final db = await LocalDatabase().database;
final result = await db.query(
'user_details',
columns: ['profile_image'],
where: 'id = ?',
whereArgs: [1],
);
if (result.isNotEmpty) {
final imageUrl = result.first['profile_image'] as String?;
if (kDebugMode && imageUrl != null) {
print('✅ [LOCAL_PREF] Retrieved profile image: $imageUrl');
}
return imageUrl;
}
return null;
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error getting profile image: $e');
}
return null;
}
}
/// Set pass cart data
static Future<void> setPassCart({
required String cityName,
required String heroImage,
required String cardTypeName,
required String cardDisplayName,
required int themeColor,
required int adultCount,
required int childCount,
required double adultPrice,
required double childPrice,
required int validityDuration,
required double totalPrice,
String? description,
}) async {
final db = await LocalDatabase().database;
await db.insert(
'pass_cart',
{
'id': 1,
'city_name': cityName,
'hero_image': heroImage,
'card_type_name': cardTypeName,
'card_display_name': cardDisplayName,
'theme_color': themeColor,
'adult_count': adultCount,
'child_count': childCount,
'adult_price': adultPrice,
'child_price': childPrice,
'validity_duration': validityDuration,
'total_price': totalPrice,
'description': description,
},
conflictAlgorithm: ConflictAlgorithm.replace,
);
if (kDebugMode) {
print('✅ [LOCAL_PREF] Pass cart saved: $cardDisplayName for $cityName');
}
}
/// Get pass cart data
static Future<Map<String, dynamic>?> getPassCart() async {
try {
final db = await LocalDatabase().database;
final result = await db.query(
'pass_cart',
where: 'id = ?',
whereArgs: [1],
);
if (result.isNotEmpty) {
if (kDebugMode) {
print('✅ [LOCAL_PREF] Retrieved pass cart data');
}
return result.first;
}
return null;
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error getting pass cart: $e');
}
return null;
}
}
static Future<void> clearPassCart() async {
try {
final db = await LocalDatabase().database;
await db.delete(
'pass_cart',
where: 'id = ?',
whereArgs: [1],
);
if (kDebugMode) {
print('✅ [LOCAL_PREF] Pass cart cleared');
}
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error clearing pass cart: $e');
}
}
}
static Future<void> clearUserDetails() async {
final db = await LocalDatabase().database;
await db.update(
'user_details',
{
'user_id': null,
'first_name': '',
'last_name': '',
'full_name': '',
'email_address': '',
'role': '',
'role_id': 0,
'profile_image': null,
},
where: 'id = ?',
whereArgs: [1],
);
}
static Future<void> clearProfileImage() async {
try {
final db = await LocalDatabase().database;
final result = await db.update(
'user_details',
{'profile_image': null},
where: 'id = ?',
whereArgs: [1],
);
if (kDebugMode) {
print('🧹 [LOCAL_PREF] Profile image cleared');
print('📊 [LOCAL_PREF] Rows affected: $result');
}
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error clearing profile image: $e');
}
rethrow;
}
}
static Future<void> resetAppData() async {
await clearLogin();
await clearTokens();
await clearUserDetails();
await clearPassCart();// optional
await clearProfileImage();// optional
}
static Future<void> clearAllData() async {
try {
final db = await LocalDatabase().database;
// Clear all tables
await db.delete('selected_city');
await db.delete('login_state');
await db.delete('user_tokens');
await db.delete('user_details');
await db.delete('pass_cart');
if (kDebugMode) {
print('🧹 [LOCAL_PREF] All local data cleared successfully');
}
} catch (e) {
if (kDebugMode) {
print('❌ [LOCAL_PREF] Error clearing all local data: $e');
}
rethrow;
}
}
}