Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't show my toast message with Flutter

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.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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,
          )),
    ),
  );

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading