2026-10-01 01:43:22 +07:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
2025-08-27 12:43:25 +07:00
|
|
|
import 'package:flutter/material.dart';
|
2025-09-18 10:39:54 +07:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
|
|
import '../../injection.dart';
|
|
|
|
|
import '../constant/local_storage_key.dart';
|
2025-08-27 12:43:25 +07:00
|
|
|
|
|
|
|
|
void dismissKeyboard(BuildContext context) {
|
|
|
|
|
final currentFocus = FocusScope.of(context);
|
|
|
|
|
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
|
|
|
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-18 08:01:49 +07:00
|
|
|
|
|
|
|
|
String getNormalizePhone(String phoneNumber) {
|
|
|
|
|
final normalizedPhone = phoneNumber.startsWith('08')
|
|
|
|
|
? phoneNumber.replaceFirst('0', '')
|
|
|
|
|
: phoneNumber;
|
|
|
|
|
return '62$normalizedPhone';
|
|
|
|
|
}
|
2025-09-18 10:39:54 +07:00
|
|
|
|
2026-10-01 01:43:22 +07:00
|
|
|
/// UUID v4 acak dari [Random.secure], dipakai sebagai `Idempotency-Key`
|
|
|
|
|
/// dan `device_id`.
|
|
|
|
|
String generateUuidV4() {
|
|
|
|
|
final random = Random.secure();
|
|
|
|
|
final bytes = List<int>.generate(16, (_) => random.nextInt(256));
|
|
|
|
|
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
|
|
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
|
|
|
final hex = bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
|
|
|
|
|
return '${hex.substring(0, 8)}-${hex.substring(8, 12)}-'
|
|
|
|
|
'${hex.substring(12, 16)}-${hex.substring(16, 20)}-${hex.substring(20)}';
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 10:39:54 +07:00
|
|
|
Map<String, dynamic> getAuthorizationHeader() {
|
|
|
|
|
return {
|
|
|
|
|
'Authorization':
|
|
|
|
|
'Bearer ${getIt<SharedPreferences>().getString(LocalStorageKey.token)}',
|
|
|
|
|
};
|
|
|
|
|
}
|