@@ -3,6 +3,14 @@ import 'dart:async';
33import 'package:flutter/material.dart' ;
44import 'package:flutter/services.dart' ;
55
6+ /// Signature for a function that defines custom position mapping for a toast
7+ ///
8+ /// [child] is the toast widget to be positioned.
9+ /// [gravity] is the gravity option for the toast which can be used to determine the position.
10+ /// The function should return a [Widget] that defines the position of the toast.
11+ /// If the position is not handled by the custom logic, return `null` to fall back to default logic.
12+ typedef ToastPositionMapping = Widget ? Function (Widget child, ToastGravity ? gravity);
13+
614/// Toast Length
715/// Only for Android Platform
816enum Toast {
@@ -233,6 +241,7 @@ class FToast {
233241 Duration fadeDuration = const Duration (milliseconds: 350 ),
234242 bool ignorePointer = false ,
235243 bool isDismissable = false ,
244+ ToastPositionMapping ? customPositionMapping,
236245 }) {
237246 if (context == null )
238247 throw ("Error: Context is null, Please call init(context) before showing toast." );
@@ -258,6 +267,15 @@ class FToast {
258267 OverlayEntry newEntry = OverlayEntry (builder: (context) {
259268 if (positionedToastBuilder != null )
260269 return positionedToastBuilder (context, newChild);
270+ // Use custom mapping logic to fall back to the default mapping if it is not defined or returns null
271+ if (customPositionMapping != null ) {
272+ Widget ? customPosition = customPositionMapping (newChild, gravity);
273+ if (customPosition != null ) {
274+ return customPosition;
275+ }
276+ }
277+
278+ // Use the default mapping logic
261279 return _getPostionWidgetBasedOnGravity (newChild, gravity);
262280 });
263281 _overlayQueue.add (_ToastEntry (
0 commit comments