Good afternoon everyone. I have a button inside a bottom sheet component that should work on a single click. But it does not. It only works after I click it a second time. I keep hearing it must be my actions. But I have gone over them and can't seem to figure it out. I created a flowchart to hopefully give you some context to what the button does. Any thoughts would be greatly appreciated! https://www.canva.com/design/DAGKqv95EWw/4XFjl7Gys5yhZg8ZvU8imQ/edit?utm_content=DAGKqv95EWw&utm_campaign=designshare&utm_medium=link2&utm_source=sharebutton
Here is the code for the button as well.
FFButtonWidget(
onPressed: () async {
// Turn Confettie off.
FFAppState().Confetti = false;
_model.updatePage(() {});
if (FFAppState().usedList.length >=
FFAppState().totalSongCount) {
// Clear list Used Song List
FFAppState().usedList = [];
} else {
await Future.delayed(const Duration(milliseconds: 1000));
}
while (FFAppState()
.usedList
.contains(FFAppState().randomNumber) ==
true) {
// Update App State with random #
FFAppState().randomNumber = valueOrDefault<int>(
random_data.randomInteger(
0, FFAppState().totalSongCount - 1),
0,
);
setState(() {});
}
// AddSelectedSongToUsedList
FFAppState().addToUsedList(FFAppState().randomNumber);
setState(() {});
// GetSelectedSong
_model.currentSong = await queryStarterRecordOnce(
queryBuilder: (starterRecord) => starterRecord.where(
'itemKey',
isEqualTo: FFAppState().randomNumber,
),
singleRecord: true,
).then((s) => s.firstOrNull);
FFAppState().selectedSong = _model.currentSong!.song;
FFAppState().selectedArtist = _model.currentSong!.artist;
FFAppState().selectedLyric1 = _model.currentSong!.lyric1;
FFAppState().selectedLyric2 = _model.currentSong!.lyric2;
FFAppState().selectedLyric3 = _model.currentSong!.lyric3;
FFAppState().selectedYear =
_model.currentSong!.year.toString();
FFAppState().selectedGenre = _model.currentSong!.genre;
_model.updatePage(() {});
if (FFAppState().isPageVisible == true) {
Navigator.pop(context);
} else {
context.goNamed(
'PartyMode',
extra: <String, dynamic>{
kTransitionInfoKey: TransitionInfo(
hasTransition: true,
transitionType: PageTransitionType.leftToRight,
),
},
);
}
setState(() {});
},