Hi i dont know what i did wrong here i converted a button to a class on it own and it stopped working it keep returning null and i dont know why. I have adjusted the code and the button class does not give any errors. Take a look at the code below
HERE IS MY BUTTON CLASS
class BottomButtonIcon extends StatelessWidget {
const BottomButtonIcon({required this.buttonText, required this.ontap});
final String buttonText;
final Void Function() ontap;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: ontap,
child: Container(
child: Center(
child: Text(buttonText),
),
padding: const EdgeInsets.only(bottom: 20),
margin: kbuttomContainerMargin,
color: kbuttomContainerColor,
height: kbuttomContainerHeight,
width: double.infinity,
));
}
}
CALL BUTTON CLASS AND PASSING SETSTATE AND THEN NAVIGATOR.PUSH
BottomButtonIcon(
buttonText: 'CALCULATE',
ontap: () {
setState(() {
Navigator.push(context,
MaterialPageRoute(builder: (context) => const ResultPage()));
});
},
),
ERROR MESSAGE IS: The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. Try adding either a return or a throw statement at the end.
final void Function() ontap;and deleted these linesmargin: kbuttomContainerMargin, color: kbuttomContainerColor, height: kbuttomContainerHeight,