Home > OS >  I can't show my toast message with Flutter
I can't show my toast message with Flutter

Time:07-21

Column(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    signInButton(
      context,
      () {
        Navigator.of(context).push(MaterialPageRoute(
          builder: (context) => const HomeScreen(),
        ));
      },
      child: const Text("Toast Message"),
    ),
  ],
)

enter image description here

When I press the button, the application stops and shows this line of code.

CodePudding user response:

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

  • Related