import 'package:clean/utils/expand.dart';
import 'package:flutter/Material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class ToastUtil {
  ToastUtil._();

  static void show(String? msg,
      {Duration? displayTime,
        SmartToastType? displayType = SmartToastType.normal,
        bool? addPostFrame}) {
    if (msg != null) {
      if (addPostFrame == true) {
        WidgetsBinding.instance.addPostFrameCallback((_) {
          SmartDialog.showToast("",
              displayType: displayType, displayTime: displayTime, builder: (_ ) => CustomToast(msg));
        });
      } else {
        SmartDialog.showToast("",
            displayType: displayType, displayTime: displayTime, builder: (_ ) => CustomToast(msg));
      }
    }
  }
}

class CustomToast extends StatelessWidget {
  const CustomToast(this.msg, {super.key});

  final String msg;

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: Alignment.bottomCenter,
      child: Container(
        margin: EdgeInsets.only(bottom: 30),
        padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12),
        decoration: BoxDecoration(
          color: "#383A3E".color,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(mainAxisSize: MainAxisSize.min, children: [
          Text(msg, style: TextStyle(color: Colors.white)),
        ]),
      ),
    );
  }

}

