Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
signInButton(
context,
() {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const HomeScreen(),
));
},
child: const Text("Toast Message"),
),
],
)
Same Example in here
I made almost the same code as seen in the link. The only difference is that I defined the button as a separate widget and gave the values inside the widget. But when I go to HomeScreen, I can’t see the Toast message. Do I need to define this in the widget too?
Container signInButton(BuildContext context, Function onTap, {required Text child}) {
return Container(
width: 250,
height: 50,
margin: const EdgeInsets.fromLTRB(0, 30, 0, 20),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 221, 144, 56)),
onPressed: () {
onTap();
},
child: Text('Giriş Yap',
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500,
)),
),
);
These are the codes of the widget I defined.
When I press the button, the application stops and shows this line of code.
>Solution :
You have to use use showtoast on press of the button
Container signInButton(BuildContext context, Function onTap, {required Text child}) {
return Container(
width: 250,
height: 50,
margin: const EdgeInsets.fromLTRB(0, 30, 0, 20),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 221, 144, 56)),
onPressed: () {
Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
},
child: Text('Giriş Yap',
style: GoogleFonts.poppins(
fontWeight: FontWeight.w500,
)),
),
);
