I want to change my button text when the pageview gets to the last page from "Next" to "Get Started", Using get so I don’t have to use stateful widgets. Please I’d love any help
class OnBoardingButton extends StatelessWidget {
const OnBoardingButton({
super.key,
});
@override
Widget build(BuildContext context) {
final dark = MHelperFunctions.isDarkMode(context);
final currentPageIndex = 0.obs;
return Positioned(
bottom: MDeviceUtils.getBottomNavBarHeight(),
right: MSizes.lg,
child: ElevatedButton(
onPressed: () => OnBoardingController.instance.nextPage(),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.fromLTRB(12, 8, 12, 8),
backgroundColor: dark ? MColors.white : MColors.primary,
),
child: Row(
children: [
Text(
currentPageIndex.value == 2 ? 'Get Started' : 'Next',
style: TextStyle(
color: dark ? MColors.primary : MColors.light,
fontSize: MSizes.fontSizeSm),
),
SizedBox(width: MSizes.xs),
Icon(
Icons.arrow_forward_ios_rounded,
size: MSizes.iconSm,
color: dark ? MColors.primary : MColors.light,
),
],
)));
}
}
2
Answers
Solved it, all I needed to do was add wrap the text widget so it handles the state for me.
It can be possible to use the callback function to dynamically update the button text.
Like that:-