Flutter run stuck on white screen

Viewed 8000

I have a Flutter issue I can't resolve. I tried all common things like flutter clean, restarting pc, wiping emulator data and few more things still getting stuck on white screen basically.

Launching lib\main.dart on Android SDK built for x86 in debug mode...
āœ“ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Connecting to VM Service at ws://127.0.0.1:55863/xq7cW6jF1O8=/ws    // this statement stays as its is 
void main() => MaterialApp(
      color: Colors.black,
      home: Scaffold(
        backgroundColor: Colors.black,
      ),
    );

Basically connection to VM is not happening.

Edit

My dartDeveloperTool says unable to connect to vm service, but it opens in chrome and doesn't show any widget just clean dartDebugger tool.

Call to OpenGL ES API with no current context (logged once per thread).

7 Answers

Of course, it won't work.

Because you need to wrap it in runApp method. Like this:

void main() { 
  runApp(
    MaterialApp(
      color: Colors.black,
      home: Scaffold(
        backgroundColor: Colors.black,
      ),
    ),
  );
}

But it's kinda bad practice to put your MaterialApp inside your main() function. Try to move it into a StatelessWidget or StatefulWidget.

Here's the example:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: null, // Change null with your own widgets
      ),
    );
  }
}

I just faced a similar issue today and removing the Dart/Flutter extensions and installing them back solved it for me.

I had faced the same issue. In my case culprit was corporate proxy. I have fixed it by setting Environment variables (User variables section) as I was using Windows machine.

HTTP_PROXY to http://proxy-ip:port
HTTPS_PROXY to http://proxy-ip:port
NO_PROXY to localhost,127.0.0.1

I also had the same issue while trying to run my app, I ran flutter clean, flutter doctor everything was green until I notice I was not connected to the internet.

If you are running the app for the first time, just restart your IDE and run your app with internet connection.

In my case, all of the following did not work: Reinstalling flutter, restarting and invalidating caches on Android Studio, reverting my code changes, cleaning the project or using a fresh example project, reinstalling Extensions on Android Studio.

What worked: restarting my computer.

Don't underestimate the importance of runApp() - If you don't use it - your app (which is one big widget) will result in an indefinite white screen because it has no constraints...

According to the documentation it:

/// Inflate the given widget and attach it to the screen. The widget is given constraints during layout that force it to fill the entire screen.

In my case, run app on debug mode working normal but I build file apk for release mode, app only show white screen. I finally found the solution. The problem was with my grade version. I downgrade version of grade in android/build.grade to 3.5.0, it works normally again.

dependencies {
   classpath 'com.android.tools.build:gradle:3.5.0'
}
Related