I just started learning Flutter and during the development, the app got stuck at Performing hot-reload.
I tried flutter clean
, flutter pub get
and reboot of the android emulator and then re-run the app. Now the app is stuck at Connecting to VM service.
After undoing my changes, it got resolved. So I traced my changes line by line and found that my incomplete code that returned an empty Container from ListView builder’s callback is causing it. I could reproduce it in a clean project as follow:
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Padding(
padding: EdgeInsets.all(1),
child: ListView.builder(itemBuilder: (context, index) {
return Container();
}))),
);
}
}
Why does this happen? My guess is that it needs to return a Widget or a tree of Widgets that finally resolves to a Render Widget. But then, shouldn’t it be somehow warned or errored if I cannot return Widgets that don’t resolve to a Render Widget?
I have tried searching the existing Flutter issues and didn’t find it.