I'm new to flutter, I have a FlutterToast in my flutter app which is called on button press. My Question is

If it is possible to add a leading Icon inside to FlutterToast

Flutter Toast:

Fluttertoast.showToast(
   msg: "Press and hold to send Alert!",
   toastLength: Toast.LENGTH_LONG,
   gravity: ToastGravity.CENTER,
   timeInSecForIosWeb: 1,
   backgroundColor: Colors.white,
   textColor: Colors.black87,
   fontSize: 16.0
  );


Solution 1: Raudah Sandouk

Check this package https://pub.dev/packages/flutter_flexible_toast You can a set a leading icon in its constructer


Solution 2: Akif

Of course, you can customize the child widget as you wish.

EDIT:

As @Lulupointu emphasized, you need to use FToast from the same package.

   FToast fToast;

   fToast.showToast(
      // In here!
      child: customizedLeadingIconWidget,        
      gravity: ToastGravity.CENTER,
     );

And your customized widget will look like:

    Widget customizedLeadingIconWidget = Container(
        padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(25.0),
          color: Colors.greenAccent,
        ),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Icon(
              Icons.check, // Set your own leading icon!
              color: Colors.red,
            ),
            SizedBox(
              width: 12.0,
            ),
            Text("This is a Custom Toast"),
          ],
        ),
      );


Solution 3: Lulupointu

You can use FToast from the same package you are using. Instead of some text it requires a child widget, which I think is way more flexible.

Here is a quick implementation which does what you want:

import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FToast fToast;

  @override
  void initState() {
    super.initState();
    fToast = FToast();
    fToast.init(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          fToast.showToast(
            toastDuration: Duration(milliseconds: 500),
            child: Material(
              color: Colors.white,
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(Icons.face),
                  Text(
                    "Press and hold to send Alert!",
                    style: TextStyle(color: Colors.black87, fontSize: 16.0),
                  )
                ],
              ),
            ),
            gravity: ToastGravity.CENTER,
          );
        },
      ),
      body: Center(
        child: Text('Text'),
      ),
    );
  }
}