Created
March 6, 2023 22:43
-
-
Save RahmiTufanoglu/ebbb1324808bf4e17e081fec293ac68d to your computer and use it in GitHub Desktop.
On app start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final firstEndpointProvider = Provider<String>((_) { | |
throw Exception('Provider "firstEndpointProvider" was not initialized.'); | |
}); | |
final secondEndpointProvider = Provider<String>((_) { | |
throw Exception('Provider "secondEndpointProvider" was not initialized.'); | |
}); | |
final sharedPrefsProvider = Provider<SharedPreferences>((_) { | |
throw Exception('Provider "sharedPrefsProvider" was not initialized.'); | |
}); | |
Future<void> main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
runApp( | |
const MaterialApp( | |
home: Scaffold( | |
backgroundColor: Colors.yellow, | |
body: Center( | |
child: CircularProgressIndicator(color: Colors.red), | |
), | |
), | |
), | |
); | |
final data1 = await Future.delayed(const Duration(milliseconds: 1500), () => 'first'); | |
final data2 = await Future.delayed(const Duration(milliseconds: 1500), () => 'second'); | |
final prefs = await SharedPreferences.getInstance(); | |
runApp( | |
ProviderScope( | |
overrides: [ | |
firstEndpointProvider.overrideWithValue(data1), | |
secondEndpointProvider.overrideWithValue(data2), | |
sharedPrefsProvider.overrideWithValue(prefs), | |
], | |
child: const App(), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment