import 'package:flutter/cupertino.dart'; import 'dart:async'; import 'package:hum/core/constants/app_theme.dart'; void showCupertinoToast( BuildContext context, String message, ) { final overlay = Overlay.of( context, ); // Animation controller lives inside an OverlayEntry widget late OverlayEntry entry; final animationController = AnimationController( vsync: Navigator.of( context, ), duration: const Duration( milliseconds: 250, ), ); entry = OverlayEntry( builder: ( ctx, ) { return Positioned( bottom: 30, left: 24, right: 24, child: FadeTransition( opacity: CurvedAnimation( parent: animationController, curve: Curves.easeInOut, ), child: CupertinoPopupSurface( isSurfacePainted: true, child: Container( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 12, ), decoration: BoxDecoration( // color: CupertinoColors.black.withValues( // alpha: .8, // ), color: CupertinoDynamicColor.resolve( colorBackground, context, ), borderRadius: BorderRadius.circular( 12, ), ), child: Center( child: Text( message, style: const TextStyle( color: CupertinoColors.white, fontSize: 16, ), textAlign: TextAlign.center, ), ), ), ), ), ); }, ); overlay.insert( entry, ); // Animate fade-in animationController.forward(); // Wait, then fade out and remove Future.delayed( const Duration( seconds: 2, ), ).then( ( _, ) async { await animationController.reverse(); entry.remove(); animationController.dispose(); }, ); } // void // showCupertinoToast( // BuildContext context, // String message, // ) { // final overlay = Overlay.of( // context, // ); // final overlayEntry = OverlayEntry( // builder: // ( // _, // ) => Positioned( // bottom: 100, // distance from bottom // left: 24, // right: 24, // child: CupertinoPopupSurface( // isSurfacePainted: true, // child: Container( // padding: const EdgeInsets.symmetric( // horizontal: 16, // vertical: 12, // ), // decoration: BoxDecoration( // color: CupertinoColors.black.withValues( // alpha: 0.8, // ), // borderRadius: BorderRadius.circular( // 12, // ), // ), // child: Center( // child: Text( // message, // style: const TextStyle( // color: CupertinoColors.white, // ), // textAlign: TextAlign.center, // ), // ), // ), // ), // ), // ); // overlay.insert( // overlayEntry, // ); // Future.delayed( // const Duration( // seconds: 2, // ), // overlayEntry.remove, // ); // }