Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Avoid using private types in public APIs" Warning in Flutter

Tags:

flutter

dart

I have been working on a flutter project and I have noticed Avoid using private types in public APIs. Is there a way to fix this warning?

 class SubCategoriesPage extends StatefulWidget {
  final MainModel mainModel;

  // final Ads ad;

  const SubCategoriesPage(this.mainModel, {Key? key}) : super(key: key);

  @override
  _SubCategoriesPage createState() { // Avoid using private types in public APIs.
    return _SubCategoriesPage();
  }
}
like image 811
Ankit Kumar Avatar asked Sep 05 '25 17:09

Ankit Kumar


1 Answers

Because createState method return State<Example> so it's preventing returning any private State.

You need to update your code like this.

class SubCategoriesPage extends StatefulWidget {
  final MainModel mainModel;

  // final Ads ad;

  const SubCategoriesPage(this.mainModel, {super.key});

  @override
  State<SubCategoriesPage> createState() { // Avoid using private types in public APIs.
    return _SubCategoriesPage();
  }
}
like image 142
Harish Sharma Avatar answered Sep 07 '25 08:09

Harish Sharma