createOverlayEntry static method

OverlayEntry createOverlayEntry(
  1. BuildContext context,
  2. String title,
  3. String message,
  4. Color color,
  5. Color bgColor,
)

Implementation

static OverlayEntry createOverlayEntry(BuildContext context, String title,
    String message, Color color, Color bgColor) {
  return OverlayEntry(
    builder: (context) => Positioned(
      bottom: 16,
      left: 16,
      right: 16,
      child: Container(
        padding: const EdgeInsets.all(16.0),
        decoration: BoxDecoration(
            color: bgColor,
            border: Border.all(width: 1.0, color: color),
            borderRadius: BorderRadius.circular(10)),
        child: Align(
          alignment: Alignment.bottomCenter,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      title,
                      textAlign: TextAlign.start,
                      softWrap: true,
                      style: _customTextStyle(16, fontColor: color),
                    ),
                    Text(
                      message,
                      textAlign: TextAlign.start,
                      softWrap: true,
                      style: _customTextStyle(14, fontColor: Colors.black),
                    )
                  ],
                ),
              ),
              Center(
                child: ClipOval(
                  child: Container(
                    height: 20,
                    width: 20,
                    color: Colors.white,
                    child: GestureDetector(
                      onTap: () {
                        if (_overlayEntry != null) {
                          toastTimer?.cancel();
                          toastTimer = null;
                          _overlayEntry!.remove();
                        }
                      },
                      child: Icon(
                        Icons.close,
                        size: 16,
                        color: color,
                      ),
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    ),
  );
}