|
|
|
@ -18,7 +18,7 @@ class AppToast {
|
|
|
|
// change this single value to retune it everywhere that uses it.
|
|
|
|
// change this single value to retune it everywhere that uses it.
|
|
|
|
static const int plainSeconds = 3;
|
|
|
|
static const int plainSeconds = 3;
|
|
|
|
|
|
|
|
|
|
|
|
static void show(String message, {int seconds = 5, VoidCallback? onComplete, bool showIcon = true, bool showCountdownText = true}) {
|
|
|
|
static void show(String message, {int seconds = 5, VoidCallback? onComplete, bool showIcon = true, bool showCountdownText = true, Color? bgColor, Color? textColor}) {
|
|
|
|
OverlayState? overlay = AppRoutes.navigatorKey.currentState?.overlay;
|
|
|
|
OverlayState? overlay = AppRoutes.navigatorKey.currentState?.overlay;
|
|
|
|
if (overlay == null) return;
|
|
|
|
if (overlay == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,11 +30,14 @@ class AppToast {
|
|
|
|
|
|
|
|
|
|
|
|
late OverlayEntry entry;
|
|
|
|
late OverlayEntry entry;
|
|
|
|
entry = OverlayEntry(
|
|
|
|
entry = OverlayEntry(
|
|
|
|
builder: (BuildContext context) => _CountdownToast(
|
|
|
|
builder:
|
|
|
|
|
|
|
|
(BuildContext context) => _CountdownToast(
|
|
|
|
message: message,
|
|
|
|
message: message,
|
|
|
|
seconds: seconds,
|
|
|
|
seconds: seconds,
|
|
|
|
showIcon: showIcon,
|
|
|
|
showIcon: showIcon,
|
|
|
|
showCountdownText: showCountdownText,
|
|
|
|
showCountdownText: showCountdownText,
|
|
|
|
|
|
|
|
bgColor: bgColor,
|
|
|
|
|
|
|
|
textColor: textColor,
|
|
|
|
onDismiss: () => _dismiss(entry, onComplete),
|
|
|
|
onDismiss: () => _dismiss(entry, onComplete),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -60,14 +63,10 @@ class _CountdownToast extends StatefulWidget {
|
|
|
|
final VoidCallback onDismiss;
|
|
|
|
final VoidCallback onDismiss;
|
|
|
|
final bool showIcon;
|
|
|
|
final bool showIcon;
|
|
|
|
final bool showCountdownText;
|
|
|
|
final bool showCountdownText;
|
|
|
|
|
|
|
|
final Color? bgColor;
|
|
|
|
|
|
|
|
final Color? textColor;
|
|
|
|
|
|
|
|
|
|
|
|
const _CountdownToast({
|
|
|
|
const _CountdownToast({required this.message, required this.seconds, required this.onDismiss, this.showIcon = true, this.showCountdownText = true, this.bgColor, this.textColor});
|
|
|
|
required this.message,
|
|
|
|
|
|
|
|
required this.seconds,
|
|
|
|
|
|
|
|
required this.onDismiss,
|
|
|
|
|
|
|
|
this.showIcon = true,
|
|
|
|
|
|
|
|
this.showCountdownText = true,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
State<_CountdownToast> createState() => _CountdownToastState();
|
|
|
|
State<_CountdownToast> createState() => _CountdownToastState();
|
|
|
|
@ -97,6 +96,9 @@ class _CountdownToastState extends State<_CountdownToast> {
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
Color bgColor = widget.bgColor ?? MyColors.darkTextColor;
|
|
|
|
|
|
|
|
Color textColor = widget.textColor ?? Colors.white;
|
|
|
|
|
|
|
|
|
|
|
|
return Positioned(
|
|
|
|
return Positioned(
|
|
|
|
left: 16,
|
|
|
|
left: 16,
|
|
|
|
right: 16,
|
|
|
|
right: 16,
|
|
|
|
@ -110,23 +112,23 @@ class _CountdownToastState extends State<_CountdownToast> {
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: MyColors.darkTextColor,
|
|
|
|
color: bgColor,
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
boxShadow: const <BoxShadow>[BoxShadow(color: Color(0x33000000), blurRadius: 12, offset: Offset(0, 4))],
|
|
|
|
boxShadow: const <BoxShadow>[BoxShadow(color: Color(0x33000000), blurRadius: 12, offset: Offset(0, 4))],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
children: <Widget>[
|
|
|
|
if (widget.showIcon) ...<Widget>[const Icon(Icons.error_outline, color: Colors.white, size: 20), const SizedBox(width: 10)],
|
|
|
|
if (widget.showIcon) ...<Widget>[Icon(Icons.error_outline, color: textColor, size: 20), const SizedBox(width: 10)],
|
|
|
|
Expanded(
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
children: <Widget>[
|
|
|
|
Text(widget.message, style: const TextStyle(color: Colors.white, fontSize: 14, height: 1.3)),
|
|
|
|
Text(widget.message, style: TextStyle(color: textColor, fontSize: 14, height: 1.3, fontWeight: FontWeight.w600)),
|
|
|
|
if (widget.showCountdownText) ...<Widget>[
|
|
|
|
if (widget.showCountdownText) ...<Widget>[
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
Text("Dismissing in ${_remaining}s", style: const TextStyle(color: Colors.white70, fontSize: 11)),
|
|
|
|
Text("Dismissing in ${_remaining}s", style: TextStyle(color: textColor.withOpacity(0.7), fontSize: 12, fontWeight: FontWeight.w500)),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|