The ! (bang) operator tells Dart 'trust me, this isn't null'. When it actually is null at runtime, you get this crash. The cure is to stop asserting and start handling.
The Error
Null check operator used on a null value
Cause: Overusing the Bang Operator
// ❌ Crashes if user is null
Text(user!.name);
// ✅ Handle the null case
Text(user?.name ?? "Guest");Async Data: Handle the Loading State
A FutureBuilder's snapshot.data is null until the future resolves. Check hasData before reading it:
FutureBuilder<User>(
future: _future,
builder: (context, snapshot) {
if (!snapshot.hasData) return const CircularProgressIndicator();
return Text(snapshot.data!.name); // safe here
},
)When late Bites
A late field that you read before assigning throws a similar error. Only use late when you can guarantee initialization happens first (e.g. in initState).
