initialize static method
Initializes version detection by fetching and caching the OS version.
This should be called early in the app lifecycle, but can be called multiple times safely - it will only fetch once.
FIXED: Uses manual version detection instead of platform channel to avoid null check errors in release builds.
Implementation
static Future<void> initialize() async {
if (_isInitialized) return;
try {
if (Platform.isIOS) {
_cachedIOSVersion = _getIOSVersionManually();
debugPrint(
'✅ [cupertino_native_better] iOS version detected: $_cachedIOSVersion',
);
} else if (Platform.isMacOS) {
_cachedMacOSVersion = _getMacOSVersionManually();
debugPrint(
'✅ [cupertino_native_better] macOS version detected: $_cachedMacOSVersion',
);
}
} catch (e) {
debugPrint('⚠️ [cupertino_native_better] Failed to get OS version: $e');
// On error, assume recent version (iOS 26+ supports Liquid Glass)
if (Platform.isIOS) {
_cachedIOSVersion = 26; // Assume modern iOS
} else if (Platform.isMacOS) {
_cachedMacOSVersion = 26; // Assume modern macOS
}
}
_isInitialized = true;
}