Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter run stuck on white screen

Tags:

flutter

dart

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).

like image 545
UTKARSH Sharma Avatar asked Aug 06 '20 16:08

UTKARSH Sharma


People also ask

How do I get rid of the Start white screen on flutter?

On the right in the properties, there is the background attribute. Clicking on this and choosing custom will allow you to define the RGB value you'd like the colour of the white screen to now appear as. Running your app on Android and iOS will now no longer show the annoying white screen.

How do I run the Flutter app in launch mode?

To compile in release mode, we just need to add the --release flag to the flutter run command and have a physical device connected. Although we can do so, we typically do not use the flutter run command with the --release flag.


Video Answer


1 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
      ),
    );
  }
}

like image 140
hisam Avatar answered Oct 05 '22 08:10

hisam