I have created a tab bar for my own app, I want when I click on an image tab, the image will change to active image, everything is fine, but after running the app, I try to click on it and the image will change. is blinking, and the error only appears once, the next time it is pressed, it will not happen again. Hope everyone help me.
class TopTabBar extends StatefulWidget {
const TopTabBar({super.key});
@override
State<TopTabBar> createState() => _TopTabBarState();
}
class _TopTabBarState extends State<TopTabBar> {
int selectedTab = 0;
@override
Widget build(BuildContext context) {
return Row(
children: [
GestureDetector(
onTap: () {
if (selectedTab != 0) {
setState(() {
selectedTab = 0;
});
}
},
child: Image.asset(
(selectedTab == 0)
? AppImages.newgameSingleActive
: AppImages.newgameSingle,
fit: BoxFit.fill,
height: 80,
width: Utils.deviceWidth(context) / 3,
),
),
GestureDetector(
onTap: () {
if (selectedTab != 1) {
setState(() {
selectedTab = 1;
});
}
},
child: Image.asset(
(selectedTab == 1)
? AppImages.newgameMultiActive
: AppImages.newgameMulti,
fit: BoxFit.fill,
height: 80,
width: Utils.deviceWidth(context) / 3,
),
),
GestureDetector(
onTap: () {
if (selectedTab != 2) {
setState(() {
selectedTab = 2;
});
}
},
child: Image.asset(
(selectedTab == 2)
? AppImages.newgameComVsComActive
: AppImages.newgameComVsCom,
fit: BoxFit.fill,
height: 80,
width: Utils.deviceWidth(context) / 3,
),
),
],
);
}
}