loadShader method
Load the background shader
Implementation
Future<bool> loadShader() async {
if (_program != null) return true;
if (_isLoading) return false;
if (_loadFailed && _loadAttempts >= _maxLoadAttempts) return false;
_isLoading = true;
_loadAttempts++;
try {
// Try loading from package path first (for when library is used as dependency)
try {
_program = await ui.FragmentProgram.fromAsset(
'packages/flutter_earth_globe/shaders/background.frag');
} catch (e) {
// Fall back to direct path (for when running within the library itself)
_program =
await ui.FragmentProgram.fromAsset('shaders/background.frag');
}
// Verify we can create a shader instance
final testShader = _program!.fragmentShader();
// ignore: unnecessary_null_comparison
if (testShader == null) throw Exception('Failed to create test shader');
_isLoading = false;
_loadFailed = false;
return true;
} catch (e) {
_loadFailed = true;
_loadError = e.toString();
_isLoading = false;
_program = null;
debugPrint(
'Failed to load background shader (attempt $_loadAttempts/$_maxLoadAttempts): $e');
return false;
}
}