feat(video_calls): first impl for main video calls screen

This commit is contained in:
misha
2026-05-05 08:09:24 +03:00
parent 50aefde842
commit 91ad51d340
49 changed files with 2179 additions and 6 deletions

View File

@@ -0,0 +1,147 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
typedef VideoCallControlLabels = ({String chat, String sound, String video, String leave});
class VideoCallControlColumn extends StatelessWidget {
const VideoCallControlColumn({
super.key,
required this.micEnabled,
required this.videoEnabled,
required this.onChat,
required this.onToggleMic,
required this.onToggleVideo,
required this.onHangUp,
required this.labels,
required this.controlLabelStyle,
});
final bool micEnabled;
final bool videoEnabled;
final VoidCallback onChat;
final VoidCallback onToggleMic;
final VoidCallback onToggleVideo;
final VoidCallback onHangUp;
final VideoCallControlLabels labels;
final TextStyle controlLabelStyle;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
VideoCallControlTile(
label: labels.chat,
labelStyle: controlLabelStyle,
onTap: onChat,
face: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Image.asset('assets/icons/video_call/vc_control_chat.png', width: 48, height: 48, fit: BoxFit.cover),
),
),
const SizedBox(height: 22),
VideoCallControlTile(
label: labels.sound,
labelStyle: controlLabelStyle,
onTap: onToggleMic,
face: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 48,
height: 48,
child: micEnabled
? ColoredBox(
color: appTheme.blueA400,
child: Center(child: SvgPicture.asset('assets/icons/video_call/vc_mic_on.svg', width: 28, height: 28)),
)
: ColoredBox(
color: appTheme.videoCallControlOffBackground,
child: Center(child: SvgPicture.asset('assets/icons/video_call/vc_mic_off.svg', width: 28, height: 28)),
),
),
),
),
const SizedBox(height: 22),
VideoCallControlTile(
label: labels.video,
labelStyle: controlLabelStyle,
onTap: onToggleVideo,
face: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 48,
height: 48,
child: videoEnabled
? Image.asset('assets/icons/video_call/vc_control_video.png', fit: BoxFit.cover)
: ColoredBox(
color: appTheme.videoCallControlOffBackground,
child: Center(child: SvgPicture.asset('assets/icons/video_call/vc_cam_off.svg', width: 28, height: 28)),
),
),
),
),
const SizedBox(height: 22),
VideoCallControlTile(
label: labels.leave,
labelStyle: controlLabelStyle,
onTap: onHangUp,
face: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: SizedBox(
width: 48,
height: 48,
child: Image.asset('assets/icons/video_call/vc_control_leave.png', fit: BoxFit.cover, alignment: const Alignment(0, -0.82)),
),
),
),
],
);
}
}
class VideoCallControlTile extends StatelessWidget {
const VideoCallControlTile({super.key, required this.label, required this.labelStyle, required this.onTap, required this.face});
final String label;
final TextStyle labelStyle;
final VoidCallback onTap;
final Widget face;
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(width: 48, height: 48, child: face),
const SizedBox(height: 6),
Text(label, style: labelStyle),
],
),
);
}
}
class VideoCallPipStyleIconButton extends StatelessWidget {
const VideoCallPipStyleIconButton({super.key, required this.onPressed, required this.child});
final VoidCallback onPressed;
final Widget child;
@override
Widget build(BuildContext context) {
return Material(
color: appTheme.videoCallPipIconBackground,
borderRadius: BorderRadius.circular(8),
child: InkWell(
borderRadius: BorderRadius.circular(8),
onTap: onPressed,
child: Padding(padding: const EdgeInsets.all(8), child: child),
),
);
}
}

View File

@@ -0,0 +1,40 @@
import 'package:livekit_client/livekit_client.dart' as lk;
abstract final class VideoCallLiveKitTrackUtils {
static lk.VideoTrack? asVideoTrack(lk.Track? track) {
if (track == null) return null;
return track is lk.VideoTrack ? track : null;
}
static lk.VideoTrack? visibleVideoFromPublication(lk.TrackPublication? pub) {
if (pub == null || pub.muted) return null;
final v = asVideoTrack(pub.track);
if (v == null || v.muted) return null;
return v;
}
static lk.VideoTrack? remoteCameraVideoTrack(lk.Room room) {
for (final participant in room.remoteParticipants.values) {
final fromCameraPub = visibleVideoFromPublication(
participant.getTrackPublicationBySource(lk.TrackSource.camera),
);
if (fromCameraPub != null) return fromCameraPub;
for (final pub in participant.videoTrackPublications) {
if (pub.source == lk.TrackSource.screenShareVideo ||
pub.source == lk.TrackSource.screenShareAudio) {
continue;
}
final v = visibleVideoFromPublication(pub);
if (v != null) return v;
}
}
return null;
}
static lk.VideoTrack? localCameraVideoTrack(lk.Room room) {
return visibleVideoFromPublication(
room.localParticipant?.getTrackPublicationBySource(lk.TrackSource.camera),
);
}
}

View File

@@ -0,0 +1,43 @@
import 'dart:ui';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
class VideoCallParticipantNameLabel extends StatelessWidget {
const VideoCallParticipantNameLabel({super.key, required this.name});
final String name;
@override
Widget build(BuildContext context) {
return Positioned(
left: 12,
bottom: 12,
right: 12,
child: Align(
alignment: Alignment.bottomLeft,
child: ClipRRect(
borderRadius: BorderRadius.circular(60),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.5, sigmaY: 5.5),
child: Container(
constraints: const BoxConstraints(maxWidth: 240),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
decoration: BoxDecoration(
color: appTheme.transparentBlack,
borderRadius: BorderRadius.circular(60),
),
child: Text(
name,
style: TextStyles.textMMedium.copyWith(color: appTheme.whiteA700),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,23 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
class VideoCallNoVideoBackground extends StatelessWidget {
const VideoCallNoVideoBackground({super.key, this.logoSize = 96});
final double logoSize;
@override
Widget build(BuildContext context) {
return ColoredBox(
color: appTheme.gray100,
child: Center(
child: Image.asset(
'assets/icons/video_call/eatvio_c.png',
width: logoSize,
height: logoSize,
fit: BoxFit.contain,
),
),
);
}
}

View File

@@ -0,0 +1,58 @@
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_livekit_track_utils.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_no_video_background.dart';
import 'package:flutter/material.dart';
import 'package:livekit_client/livekit_client.dart' as lk;
class VideoCallRemoteVideoStage extends StatelessWidget {
const VideoCallRemoteVideoStage({
super.key,
required this.room,
required this.connectError,
});
final lk.Room room;
final String? connectError;
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: room,
builder: (context, _) {
final remote = VideoCallLiveKitTrackUtils.remoteCameraVideoTrack(room);
if (remote != null) {
return lk.VideoTrackRenderer(remote, fit: lk.VideoViewFit.cover);
}
return Stack(
fit: StackFit.expand,
children: [
const VideoCallNoVideoBackground(),
if (connectError != null)
Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Text(
connectError!,
textAlign: TextAlign.center,
style: TextStyles.textSMedium.copyWith(color: appTheme.red),
),
),
)
else if (room.connectionState != lk.ConnectionState.connected)
Center(
child: SizedBox(
width: 36,
height: 36,
child: CircularProgressIndicator(
strokeWidth: 3,
color: appTheme.blueA400,
),
),
),
],
);
},
);
}
}

View File

@@ -0,0 +1,489 @@
import 'dart:math' as math;
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_controls.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_livekit_track_utils.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_name_chips.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_no_video_background.dart';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_remote_video_stage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:livekit_client/livekit_client.dart' as lk;
const _kExpandShrinkOuterPadding = EdgeInsets.all(6);
abstract final class _VideoCallStageAssets {
static const String shrink = 'assets/icons/video_call/vc_shrink.svg';
static const String expand = 'assets/icons/video_call/vc_expand.svg';
static const String cameraSwitch = 'assets/icons/video_call/vc_camera_switch.png';
}
class VideoCallStageLayout extends StatefulWidget {
const VideoCallStageLayout({
super.key,
required this.room,
required this.connectError,
required this.localDisplayName,
required this.remoteDisplayName,
required this.micEnabled,
required this.videoEnabled,
required this.splitParticipantView,
required this.mainStageShowsLocalVideo,
required this.useFrontCamera,
required this.onExpandLocal,
required this.onExpandRemote,
required this.onShrinkFromFullscreen,
required this.onToggleStageSwap,
required this.onChat,
required this.onToggleMic,
required this.onToggleVideo,
required this.onHangUp,
required this.onSwitchCamera,
required this.controlLabelStyle,
required this.labels,
required this.topInset,
this.bottomInset = 0,
});
final lk.Room room;
final String? connectError;
final String localDisplayName;
final String remoteDisplayName;
final bool micEnabled;
final bool videoEnabled;
final bool splitParticipantView;
final bool mainStageShowsLocalVideo;
final bool useFrontCamera;
final VoidCallback onExpandLocal;
final VoidCallback onExpandRemote;
final VoidCallback onShrinkFromFullscreen;
final VoidCallback onToggleStageSwap;
final VoidCallback onChat;
final VoidCallback onToggleMic;
final VoidCallback onToggleVideo;
final VoidCallback onHangUp;
final VoidCallback onSwitchCamera;
final TextStyle controlLabelStyle;
final VideoCallControlLabels labels;
final double topInset;
final double bottomInset;
@override
State<VideoCallStageLayout> createState() => _VideoCallStageLayoutState();
}
class _VideoCallStageLayoutState extends State<VideoCallStageLayout> {
static const double _pipW = 142;
static const double _pipH = 201;
static const double _mainStageCornerRadius = 24;
static const double _edgeInset = 8;
static const double _controlsHorizontalInset = 22;
static const double _shrinkExpandExtraTop = 12;
static const double _pipInitialExtraLeft = 28;
static const double _pipInitialExtraDown = 16;
static const double _bottomGradientHeight = 140;
static const double _splitExpandButtonTop = 8 + _shrinkExpandExtraTop;
double? _pipLeft;
double? _pipTop;
Offset? _pipPanPointerGlobal;
double? _pipPanOriginLeft;
double? _pipPanOriginTop;
bool _pipHasVisibleVideo() {
if (widget.mainStageShowsLocalVideo) {
return VideoCallLiveKitTrackUtils.remoteCameraVideoTrack(widget.room) != null;
}
return widget.videoEnabled && VideoCallLiveKitTrackUtils.localCameraVideoTrack(widget.room) != null;
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (widget.splitParticipantView) {
return _buildSplitLayout(constraints);
}
return _buildFullscreenLayout(constraints);
},
);
}
Widget _buildSplitLayout(BoxConstraints constraints) {
return Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child: Padding(
padding: EdgeInsets.fromLTRB(_edgeInset, widget.topInset + _edgeInset, _edgeInset, _edgeInset),
child: Column(
children: [
Expanded(
child: _SplitParticipantPane(
room: widget.room,
displayName: widget.localDisplayName,
isLocal: true,
connectError: null,
videoEnabled: widget.videoEnabled,
useFrontCamera: widget.useFrontCamera,
onExpand: widget.onExpandLocal,
onSwitchCamera: widget.onSwitchCamera,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(_mainStageCornerRadius),
topRight: Radius.circular(_mainStageCornerRadius),
bottomLeft: Radius.zero,
bottomRight: Radius.zero,
),
),
),
const SizedBox(height: _edgeInset),
Expanded(
child: _SplitParticipantPane(
room: widget.room,
displayName: widget.remoteDisplayName,
isLocal: false,
connectError: widget.connectError,
videoEnabled: widget.videoEnabled,
useFrontCamera: widget.useFrontCamera,
onExpand: widget.onExpandRemote,
onSwitchCamera: widget.onSwitchCamera,
borderRadius: const BorderRadius.only(
topLeft: Radius.zero,
topRight: Radius.zero,
bottomLeft: Radius.circular(_mainStageCornerRadius),
bottomRight: Radius.circular(_mainStageCornerRadius),
),
),
),
],
),
),
),
..._bottomBarGradient(),
..._bottomControlsRow(),
],
);
}
Widget _buildFullscreenLayout(BoxConstraints constraints) {
final maxW = constraints.maxWidth;
final maxH = constraints.maxHeight;
final defaultPipLeft = maxW - _pipW - _edgeInset - _pipInitialExtraLeft;
final minPipTop = widget.topInset + _edgeInset;
final defaultPipTop = minPipTop + _pipInitialExtraDown;
final maxPipLeft = math.max(_edgeInset, maxW - _pipW - _edgeInset);
final maxPipTop = math.max(minPipTop, maxH - _pipH - _edgeInset - widget.bottomInset);
final pipLeft = ((_pipLeft ?? defaultPipLeft).clamp(_edgeInset, maxPipLeft) as num).toDouble();
final pipTop = ((_pipTop ?? defaultPipTop).clamp(minPipTop, maxPipTop) as num).toDouble();
return Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child: Padding(
padding: EdgeInsets.fromLTRB(_edgeInset, widget.topInset + _edgeInset, _edgeInset, _edgeInset),
child: Material(
type: MaterialType.transparency,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(_mainStageCornerRadius)),
child: Stack(
fit: StackFit.expand,
children: [
_VideoCallMainStage(
room: widget.room,
connectError: widget.connectError,
mainShowsLocal: widget.mainStageShowsLocalVideo,
videoEnabled: widget.videoEnabled,
),
VideoCallParticipantNameLabel(name: widget.mainStageShowsLocalVideo ? widget.localDisplayName : widget.remoteDisplayName),
],
),
),
),
),
..._bottomBarGradient(),
..._bottomControlsRow(),
Positioned(
top: widget.topInset + _edgeInset + _shrinkExpandExtraTop,
left: _controlsHorizontalInset,
child: Padding(
padding: _kExpandShrinkOuterPadding,
child: VideoCallPipStyleIconButton(
onPressed: widget.onShrinkFromFullscreen,
child: SvgPicture.asset(_VideoCallStageAssets.shrink, width: 20, height: 20, fit: BoxFit.contain),
),
),
),
ListenableBuilder(
listenable: widget.room,
builder: (context, _) {
if (!_pipHasVisibleVideo()) {
return const SizedBox.shrink();
}
return Positioned(
left: pipLeft,
top: pipTop,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onToggleStageSwap,
onPanStart: (details) {
_pipPanPointerGlobal = details.globalPosition;
_pipPanOriginLeft = pipLeft;
_pipPanOriginTop = pipTop;
},
onPanUpdate: (details) {
if (_pipPanPointerGlobal == null || _pipPanOriginLeft == null || _pipPanOriginTop == null) {
return;
}
final delta = details.globalPosition - _pipPanPointerGlobal!;
setState(() {
final nx = (_pipPanOriginLeft! + delta.dx).clamp(_edgeInset, maxPipLeft);
final ny = (_pipPanOriginTop! + delta.dy).clamp(minPipTop, maxPipTop);
_pipLeft = (nx as num).toDouble();
_pipTop = (ny as num).toDouble();
});
},
onPanEnd: (_) {
_resetPipPanState();
},
onPanCancel: _resetPipPanState,
child: AnimatedContainer(
duration: const Duration(milliseconds: 220),
curve: Curves.easeOutCubic,
width: _pipW,
height: _pipH,
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: widget.mainStageShowsLocalVideo
? _VideoCallPipRemoteContent(room: widget.room)
: _VideoCallPipLocalContent(
room: widget.room,
videoEnabled: widget.videoEnabled,
useFrontCamera: widget.useFrontCamera,
onSwitchCamera: widget.onSwitchCamera,
),
),
),
),
);
},
),
],
);
}
List<Widget> _bottomBarGradient() {
return [
Positioned(
left: 0,
right: 0,
bottom: 0,
height: _bottomGradientHeight + widget.bottomInset,
child: IgnorePointer(
child: DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [Colors.black.withValues(alpha: 0.55), Colors.black.withValues(alpha: 0)],
),
),
),
),
),
];
}
void _resetPipPanState() {
_pipPanPointerGlobal = null;
_pipPanOriginLeft = null;
_pipPanOriginTop = null;
}
List<Widget> _bottomControlsRow() {
return [
Positioned(
left: _controlsHorizontalInset,
right: _controlsHorizontalInset,
bottom: _edgeInset + 4 + widget.bottomInset,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
const Expanded(child: SizedBox.shrink()),
const SizedBox(width: 14),
VideoCallControlColumn(
micEnabled: widget.micEnabled,
videoEnabled: widget.videoEnabled,
onChat: widget.onChat,
onToggleMic: widget.onToggleMic,
onToggleVideo: widget.onToggleVideo,
onHangUp: widget.onHangUp,
labels: widget.labels,
controlLabelStyle: widget.controlLabelStyle,
),
],
),
),
];
}
}
class _SplitParticipantPane extends StatelessWidget {
const _SplitParticipantPane({
required this.room,
required this.displayName,
required this.isLocal,
required this.connectError,
required this.videoEnabled,
required this.useFrontCamera,
required this.onExpand,
required this.onSwitchCamera,
required this.borderRadius,
});
final lk.Room room;
final String displayName;
final bool isLocal;
final String? connectError;
final bool videoEnabled;
final bool useFrontCamera;
final VoidCallback onExpand;
final VoidCallback onSwitchCamera;
final BorderRadius borderRadius;
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: borderRadius),
child: Stack(
fit: StackFit.expand,
children: [
Positioned.fill(
child: ListenableBuilder(
listenable: room,
builder: (context, _) {
if (isLocal) {
if (!videoEnabled) {
return const VideoCallNoVideoBackground();
}
final local = VideoCallLiveKitTrackUtils.localCameraVideoTrack(room);
if (local != null) {
return IgnorePointer(
child: lk.VideoTrackRenderer(local, fit: lk.VideoViewFit.cover, mirrorMode: lk.VideoViewMirrorMode.auto),
);
}
return const VideoCallNoVideoBackground();
}
return VideoCallRemoteVideoStage(room: room, connectError: connectError);
},
),
),
VideoCallParticipantNameLabel(name: displayName),
Positioned(
left: 0,
top: _VideoCallStageLayoutState._splitExpandButtonTop,
child: Padding(
padding: _kExpandShrinkOuterPadding,
child: VideoCallPipStyleIconButton(
onPressed: onExpand,
child: SvgPicture.asset(_VideoCallStageAssets.expand, width: 20, height: 20, fit: BoxFit.contain),
),
),
),
if (isLocal && videoEnabled)
Positioned(
right: 10,
top: 10,
child: Padding(
padding: _kExpandShrinkOuterPadding,
child: VideoCallPipStyleIconButton(
onPressed: onSwitchCamera,
child: Image.asset(_VideoCallStageAssets.cameraSwitch, width: 20, height: 20, fit: BoxFit.contain, key: ValueKey(useFrontCamera)),
),
),
),
],
),
);
}
}
class _VideoCallMainStage extends StatelessWidget {
const _VideoCallMainStage({required this.room, required this.connectError, required this.mainShowsLocal, required this.videoEnabled});
final lk.Room room;
final String? connectError;
final bool mainShowsLocal;
final bool videoEnabled;
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: room,
builder: (context, _) {
if (mainShowsLocal) {
if (!videoEnabled) {
return const VideoCallNoVideoBackground();
}
final local = VideoCallLiveKitTrackUtils.localCameraVideoTrack(room);
if (local != null) {
return IgnorePointer(
child: lk.VideoTrackRenderer(local, fit: lk.VideoViewFit.cover, mirrorMode: lk.VideoViewMirrorMode.auto),
);
}
return const VideoCallNoVideoBackground();
}
return VideoCallRemoteVideoStage(room: room, connectError: connectError);
},
);
}
}
class _VideoCallPipRemoteContent extends StatelessWidget {
const _VideoCallPipRemoteContent({required this.room});
final lk.Room room;
@override
Widget build(BuildContext context) {
return IgnorePointer(child: VideoCallRemoteVideoStage(room: room, connectError: null));
}
}
class _VideoCallPipLocalContent extends StatelessWidget {
const _VideoCallPipLocalContent({required this.room, required this.videoEnabled, required this.useFrontCamera, required this.onSwitchCamera});
final lk.Room room;
final bool videoEnabled;
final bool useFrontCamera;
final VoidCallback onSwitchCamera;
@override
Widget build(BuildContext context) {
final local = VideoCallLiveKitTrackUtils.localCameraVideoTrack(room);
return Stack(
fit: StackFit.expand,
children: [
if (!videoEnabled)
const VideoCallNoVideoBackground(logoSize: 56)
else if (local != null)
IgnorePointer(
child: lk.VideoTrackRenderer(local, fit: lk.VideoViewFit.cover, mirrorMode: lk.VideoViewMirrorMode.auto),
)
else
const VideoCallNoVideoBackground(logoSize: 56),
if (videoEnabled)
Positioned(
right: 10,
top: 10,
child: VideoCallPipStyleIconButton(
onPressed: onSwitchCamera,
child: Image.asset(_VideoCallStageAssets.cameraSwitch, width: 20, height: 20, fit: BoxFit.contain, key: ValueKey(useFrontCamera)),
),
),
],
);
}
}

View File

@@ -0,0 +1,63 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
abstract final class VideoCallTopOverlay {
static const String poorConnectionSvg = 'assets/icons/video_call/poor_connection.svg';
static const String warningSvg = 'assets/icons/video_call/warning.svg';
static OverlayEntry insertBanner(
BuildContext context, {
required String message,
required Color backgroundColor,
required String svgAsset,
Duration? autoRemoveAfter,
}) {
final overlayState = Overlay.of(context, rootOverlay: true);
late OverlayEntry entry;
entry = OverlayEntry(
builder: (ctx) => Positioned(
left: 16,
right: 16,
top: MediaQuery.viewPaddingOf(ctx).top + 8,
child: Material(
color: backgroundColor,
borderRadius: BorderRadius.circular(12),
elevation: 6,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SvgPicture.asset(svgAsset, width: 22, height: 22),
const SizedBox(width: 10),
Expanded(
child: Text(
message,
style: TextStyle(
color: appTheme.whiteA700,
fontSize: 14,
height: 1.25,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
),
),
);
overlayState.insert(entry);
if (autoRemoveAfter != null) {
Future<void>.delayed(autoRemoveAfter, () {
if (entry.mounted) {
entry.remove();
}
});
}
return entry;
}
}