78 lines
2.4 KiB
Dart
Raw Normal View History

2025-11-04 14:58:51 +07:00
import 'dart:developer';
2025-11-04 22:13:15 +07:00
import 'dart:math' hide log;
2025-11-04 14:58:51 +07:00
2025-10-23 22:16:53 +07:00
import 'package:flutter/material.dart';
2025-11-04 14:58:51 +07:00
import 'package:permission_handler/permission_handler.dart';
2025-10-24 13:55:00 +07:00
import 'package:shared_preferences/shared_preferences.dart';
import '../../injection.dart';
import '../constant/local_storage_key.dart';
2025-10-23 22:16:53 +07:00
void dismissKeyboard(BuildContext context) {
final currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
FocusManager.instance.primaryFocus?.unfocus();
}
}
2025-10-24 13:55:00 +07:00
Map<String, dynamic> getAuthorizationHeader() {
return {
'Authorization':
'Bearer ${getIt<SharedPreferences>().getString(LocalStorageKey.token)}',
};
}
2025-10-26 16:09:56 +07:00
Map<String, int> getChairDistribution(int capacity) {
if (capacity == 1) {
return {'top': 0, 'bottom': 0, 'left': 1, 'right': 0};
} else if (capacity == 2) {
return {'top': 0, 'bottom': 0, 'left': 1, 'right': 1};
} else if (capacity == 3) {
return {'top': 1, 'bottom': 0, 'left': 1, 'right': 1};
} else if (capacity == 4) {
return {'top': 1, 'bottom': 1, 'left': 1, 'right': 1};
} else if (capacity == 5) {
return {'top': 2, 'bottom': 1, 'left': 1, 'right': 1};
} else if (capacity == 6) {
return {'top': 2, 'bottom': 2, 'left': 1, 'right': 1};
} else if (capacity == 7) {
return {'top': 3, 'bottom': 2, 'left': 1, 'right': 1};
} else if (capacity == 8) {
return {'top': 3, 'bottom': 3, 'left': 1, 'right': 1};
} else if (capacity == 9) {
return {'top': 4, 'bottom': 3, 'left': 1, 'right': 1};
} else if (capacity == 10) {
return {'top': 4, 'bottom': 4, 'left': 1, 'right': 1};
} else {
int side = ((capacity - 2) / 2).floor();
return {'top': side, 'bottom': side, 'left': 1, 'right': 1};
}
}
2025-11-03 21:28:36 +07:00
double safeDouble(double value) {
if (value.isNaN || value.isInfinite) return 0.0;
return value;
}
int safeRound(double value) {
if (value.isNaN || value.isInfinite) return 0;
return value.round();
}
2025-11-04 14:58:51 +07:00
Future<void> loadPermissionBluetooth() async {
var status2 = await Permission.bluetoothScan.status;
log("Permission: $status2");
if (status2.isDenied) {
await Permission.bluetoothScan.request();
}
var status = await Permission.bluetoothConnect.status;
if (status.isDenied) {
await Permission.bluetoothConnect.request();
}
}
2025-11-04 22:13:15 +07:00
int generateRandomNumber() {
final random = Random();
return 1 + random.nextInt(10000);
}