Bacancy Technology
Bacancy Technology represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.
12+
Countries where we have happy customers
1050+
Agile enabled employees
06
World wide offices
12+
Years of Experience
05
Agile Coaches
14
Certified Scrum Masters
1000+
Clients projects
1458
Happy customers
Artificial Intelligence
Machine Learning
Salesforce
Microsoft
SAP
August 24, 2023
An issue in the below code is that the code produces a black screen because the splash screen is removed with the FlutterNativeSplash.remove() command before the app is ready to be built. In this case, the reason the app is not ready to be built is because if the await Future. Delayed, but in another app, the same effect could be caused by waiting for resources to load, waiting for a server response, etc.
void main() { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); HttpOverrides.global = new MyHttpOverrides(); runApp(const MyApp()); }
Solution
It is important to remove the splash screen only when the screen is ready to be built. The example app in this package shows a good way to implement this. For the simplistic example above, the black screen can be removed simply by moving the FlutterNativeSplash.remove() after the delay to the point where the app is ready to be built:
Future<void> main() async { WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized(); FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); await Future.delayed(const Duration(milliseconds: 3000), () {}); FlutterNativeSplash.remove(); runApp(const MyApp()); }
Github Closed issue mentioned the solution for the same issue by the owner of this library.