ERROR || FLUTTER || ‘owner!.\_debugCurrentBuildTarget == this’: is not true

Issue

enter image description here

I am new to Android Development. I created a flutter project and just returned a Text Widget using a stateless class but I am getting this error. I tried reading about it on the blogs regarding this error. I think its related to calling an instance of a stateless widget in the same class itself but I am not sure.

stack overflow post

Here’s my code:

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text('Hello'),
    );
  }
}

Getting this O/P: enter image description here

What to do ?

Solution

You must use MaterialApp Widget in the beginning. If you do this, the problem will be solved. But I recommend you to wrap the Text Widget with Scaffold too.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Text('Hello'),
    );
  }
}

Answered By – Hazar Belge

Leave a Comment