You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:my_flutter_puzzle/utils/toast.dart';
class Utils { Utils.privateConstructor();
static final Utils instance = Utils.privateConstructor();
factory Utils() { return instance; }
void showToast(BuildContext? context, String? txt, {bool isError = true, ToastGravity gravity = ToastGravity.top}) { try { if (context == null) return; if (txt == null || txt.isEmpty) { if (isError == false) { return; } txt = 'Error'; } FToast fToast = FToast(); fToast.init(context); Widget toast = Container( padding: const EdgeInsetsDirectional.all(16), decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), color: isError ? Colors.red : Colors.lightBlue, ), child: Text( txt, style: const TextStyle( color: Colors.white, fontWeight: FontWeight.bold, ), ), ); fToast.showToast(child: toast, gravity: gravity, toastDuration: const Duration(milliseconds: 1500)); } catch (e) { assert(() { if (kDebugMode) { print(e); } return true; }()); } } }
|