showToastInQueue static method
OverlayShower
showToastInQueue(
- String text, {
- String? key,
- TextStyle? textStyle,
- EdgeInsets? padding,
- Decoration? decoration,
- Color? backgroundColor,
- BorderRadius? radius,
- BoxShadow? shadow,
- Curve? curve,
- Duration? appearDuration,
- Duration? dismissDuration,
- Duration? onScreenDuration,
- Offset? slideBegin,
- double? opacityBegin,
- Widget appearAnimatedBuilder(
- OverlayShower shower,
- AnimationController controller,
- Widget widget
- Widget dismissAnimatedBuilder(
- OverlayShower shower,
- AnimationController controller,
- Widget widget
- EdgeInsets increaseOffset = const EdgeInsets.only(top: 45),
Implementation
static OverlayShower showToastInQueue(
String text, {
String? key,
TextStyle? textStyle,
// text in padding
EdgeInsets? padding,
// container decoration;
Decoration? decoration,
Color? backgroundColor,
BorderRadius? radius,
BoxShadow? shadow,
// animation
Curve? curve,
Duration? appearDuration,
Duration? dismissDuration,
Duration? onScreenDuration,
// animation settings
Offset? slideBegin,
double? opacityBegin,
Widget Function(OverlayShower shower, AnimationController controller, Widget widget)? appearAnimatedBuilder,
Widget Function(OverlayShower shower, AnimationController controller, Widget widget)? dismissAnimatedBuilder,
// queue increment offset
EdgeInsets increaseOffset = const EdgeInsets.only(top: 45),
// List? queue,
}) {
OverlayShower shower = showToast(
text,
key: key,
textStyle: textStyle,
padding: padding,
decoration: decoration,
backgroundColor: backgroundColor,
radius: radius,
shadow: shadow,
curve: curve,
appearDuration: appearDuration,
dismissDuration: dismissDuration,
onScreenDuration: onScreenDuration,
slideBegin: slideBegin,
opacityBegin: opacityBegin,
appearAnimatedBuilder: appearAnimatedBuilder,
dismissAnimatedBuilder: dismissAnimatedBuilder,
);
// Use micro, for the caller will modified properties(i.e margin, alignment) outside
// The appear animation controller will setState, don't worry
Future.microtask(() {
String keyInQueue = shower.alignment?.toString() ?? '__Shared_Key__';
List<OverlayShower?> queue = (sharedToastQueue[keyInQueue] ?? (sharedToastQueue[keyInQueue] = []));
// 1. get the empty index
int index = -1;
for (int i = 0; i < queue.length; i++) {
OverlayShower? obj = queue[i];
if (obj == null) {
index = i;
queue[i] = shower;
break;
}
}
if (index == -1) {
index = queue.length;
queue.add(shower);
}
// 2. calculate the position
EdgeInsets n = increaseOffset;
EdgeInsets? m = shower.margin;
shower.margin = EdgeInsets.only(
left: n.left * index + (m?.left ?? 0),
top: n.top * index + (m?.top ?? 0),
right: n.right * index + (m?.right ?? 0),
bottom: n.bottom * index + (m?.bottom ?? 0),
);
// 3. clear the queue when dismissed
shower.addDismissCallBack((shower) {
var index = queue.indexOf(shower);
if (index != -1) {
queue[index] = null;
}
// if all null
bool isNullALL = true;
for (OverlayShower? s in queue) {
if (s != null) {
isNullALL = false;
break;
}
}
if (isNullALL) {
queue.clear();
}
});
});
return shower;
}