I am displaying a popup survey in my app so after completing the survey and clicking done, the popup appears again. I do not want that to open.
I get this error setState() or markNeedsBuild() called during build which makes the widget show time and time again without completing.
I tried different solution but I cannot just get to the solution. Can I please get assistance where I am getting it wrong.
My code of my method:
void showGenexPopup() {
final GenexViewModel genexViewModel =
Provider.of<GenexViewModel>(context, listen: false);
if (!genexViewModel.videoTrigger) {
genexViewModel.showSurvey(
context: context,
pageId: GenexPageId.SearchPage,
duration: const Duration(seconds: 5),
);
}
}
Where I am calling the method:
Widget buildSearchResults(GlobalSearchViewModel globalSearchViewModel) {
if (globalSearchViewModel.loadingStatus == LoadingStatus.busy) {
return getLoader();
} else {
switch (categorizedResults.length) {
case 0:
{
return buildNoDataFound();
}
case 1:
{
return buildList(categorizedResults[0].categorizedResults);
}
default:
{
for (final CategorizedResults list in categorizedResults) {
if (list.categorizedResults.isNotEmpty) {
dynamicTabHeaders.add(list.categoryTitle);
if (list.categoryTitle == 'News' ||
list.categoryTitle == 'Videos') {
dynamicContent.add(
Scaffold(
body: ArticleVideoListViewWidget(list.categorizedResults),
),
);
} else if (list.categoryTitle == 'Teams') {
for (final CategorizedTeams team in categorizedTeams) {
if (team.categorizedTeams.isNotEmpty) {
dynamicTeamTabHeaders.add(team.categoryTitle);
dynamicTeamContent.add(
Scaffold(
body: PlainListViewWidget(
searchValues: team.categorizedTeams),
),
);
}
}
dynamicContent.add(
Scaffold(
body: PillTabBar(
tabHeadings: dynamicTeamTabHeaders,
tabBodies: dynamicTeamContent,
initialIndex: 0,
scrollViewScroll: false,
),
),
);
} else {
dynamicContent.add(
Scaffold(
body: PlainListViewWidget(
searchValues: list.categorizedResults),
),
);
}
}
}
showGenexPopup();
return sliverController.singleRowSearchTabSliverWithoutHeader(
dynamicTabHeaders,
dynamicContent,
0,
screenWidth(context),
dynamicTabHeaders.length > 3,
tabCallBack: this,
);
}
}
}
}
Help will be appreciated.