diff --git a/lib/common/constant/app_constant.dart b/lib/common/constant/app_constant.dart index 44eacb7..1d05cfc 100644 --- a/lib/common/constant/app_constant.dart +++ b/lib/common/constant/app_constant.dart @@ -1,5 +1,8 @@ +import '../../env.dart'; +import '../../injection.dart'; + class AppConstant { static const String appName = "Apskel POS"; - static const String dbName = "apskel_pos.db"; + static String dbName = getIt().dbName; static const int cacheExpire = 10; // in minutes } diff --git a/lib/common/database/database_helper.dart b/lib/common/database/database_helper.dart index 480468c..6842641 100644 --- a/lib/common/database/database_helper.dart +++ b/lib/common/database/database_helper.dart @@ -17,7 +17,7 @@ class DatabaseHelper { return await openDatabase( path, - version: 2, // Updated version for categories table + version: 1, // Updated version for categories table onCreate: _onCreate, onUpgrade: _onUpgrade, ); @@ -68,6 +68,7 @@ class DatabaseHelper { name TEXT NOT NULL, description TEXT, business_type TEXT, + sort_order INTEGER DEFAULT 0, metadata TEXT, is_active INTEGER DEFAULT 1, created_at TEXT, @@ -106,13 +107,7 @@ class DatabaseHelper { await db.execute('CREATE INDEX idx_printers_type ON printers(type)'); } - Future _onUpgrade(Database db, int oldVersion, int newVersion) async { - if (oldVersion < 2) { - await db.execute( - 'ALTER TABLE categories ADD COLUMN "order" INTEGER DEFAULT 0', - ); - } - } + Future _onUpgrade(Database db, int oldVersion, int newVersion) async {} Future close() async { final db = await database; diff --git a/lib/env.dart b/lib/env.dart index ddc3051..4e188b8 100644 --- a/lib/env.dart +++ b/lib/env.dart @@ -2,6 +2,7 @@ import 'package:injectable/injectable.dart'; abstract class Env { String get baseUrl; + String get dbName; // add getter here... } @@ -9,7 +10,10 @@ abstract class Env { @dev class DevEnv implements Env { @override - String get baseUrl => 'https://api-pos.apskel.id'; // example value + String get baseUrl => 'https://api-pos.apskel.id'; + + @override + String get dbName => "apskel_pos_dev.db"; // example value } @Injectable(as: Env) @@ -17,4 +21,7 @@ class DevEnv implements Env { class ProdEnv implements Env { @override String get baseUrl => 'https://api-pos.apskel.id'; + + @override + String get dbName => "apskel_pos_dev.db"; } diff --git a/lib/infrastructure/auth/datasources/local_data_provider.dart b/lib/infrastructure/auth/datasources/local_data_provider.dart index 26c460c..79c7398 100644 --- a/lib/infrastructure/auth/datasources/local_data_provider.dart +++ b/lib/infrastructure/auth/datasources/local_data_provider.dart @@ -53,6 +53,7 @@ class AuthLocalDataProvider { try { await _sharedPreferences.remove(LocalStorageKey.token); await _sharedPreferences.remove(LocalStorageKey.user); + await _sharedPreferences.remove(LocalStorageKey.outlet); } catch (e) { log('deleteAllAuthError', name: _logName, error: e); } diff --git a/lib/infrastructure/category/dtos/category_dto.dart b/lib/infrastructure/category/dtos/category_dto.dart index c5585c7..7f8dfe1 100644 --- a/lib/infrastructure/category/dtos/category_dto.dart +++ b/lib/infrastructure/category/dtos/category_dto.dart @@ -63,7 +63,7 @@ class CategoryDto with _$CategoryDto { 'name': name, 'description': description, 'business_type': businessType, - 'order': order, + 'sort_order': order, 'metadata': metadata != null ? jsonEncode(metadata) : null, 'created_at': createdAt, 'updated_at': updatedAt, diff --git a/lib/infrastructure/printer/repositories/printer_repository.dart b/lib/infrastructure/printer/repositories/printer_repository.dart index 76f5354..0d09995 100644 --- a/lib/infrastructure/printer/repositories/printer_repository.dart +++ b/lib/infrastructure/printer/repositories/printer_repository.dart @@ -247,6 +247,11 @@ class PrinterRepository implements IPrinterRepository { ); } + log( + 'Printer connected to bluetooth: ${printer.name}, ${printer.address}', + name: _logName, + ); + bool printResult = await _printBluetooth(printData); if (!printResult) { FirebaseCrashlytics.instance.recordError( diff --git a/lib/presentation/pages/main/main_page.dart b/lib/presentation/pages/main/main_page.dart index 6d15d68..2bcdade 100644 --- a/lib/presentation/pages/main/main_page.dart +++ b/lib/presentation/pages/main/main_page.dart @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../application/auth/auth_bloc.dart'; import '../../../application/auth/logout/logout_bloc.dart'; import '../../../common/theme/theme.dart'; import '../../components/assets/assets.gen.dart'; @@ -10,9 +11,20 @@ import '../../components/toast/flushbar.dart'; import '../../router/app_router.gr.dart'; @RoutePage() -class MainPage extends StatelessWidget { +class MainPage extends StatefulWidget { const MainPage({super.key}); + @override + State createState() => _MainPageState(); +} + +class _MainPageState extends State { + @override + void initState() { + context.read().add(const AuthEvent.fetchCurrentUser()); + super.initState(); + } + @override Widget build(BuildContext context) { return BlocListener(