flutter/lib/components/my_toast.dart

26 lines
777 B
Dart
Raw Normal View History

2025-08-21 10:50:38 +08:00
import 'package:flutter/material.dart';
import 'package:shirne_dialog/shirne_dialog.dart';
class MyToast {
///
void tip({
required String title,
String? type, // 默认失败
String? position, // 默认底部显示
}) {
final baseStyle = position == 'top'
? MyDialog.theme.toastStyle?.top()
: position == 'center'
? MyDialog.theme.toastStyle?.center()
: MyDialog.theme.toastStyle?.bottom();
MyDialog.toast(
title,
icon: type == 'success' ? const Icon(Icons.check_circle) : Icon(Icons.warning),
duration: Duration(milliseconds: 5000),
style: baseStyle?.copyWith(
backgroundColor: type == 'success' ? Colors.green.withAlpha(200) : Colors.red.withAlpha(200),
),
);
}
}