class LocationAttachment extends StatelessWidget {
const LocationAttachment({
super.key,
required this.sharedLocation,
this.onLocationTap,
this.onStopLiveLocation,
});
final Location sharedLocation;
final ValueSetter<Location>? onLocationTap;
final ValueSetter<Location>? onStopLiveLocation;
@override
Widget build(BuildContext context) {
final currentUser = StreamChat.of(context).currentUser;
final isFromCurrentUser = sharedLocation.userId == currentUser?.id;
return GestureDetector(
onTap: onLocationTap,
child: Container(
width: 270,
height: 180,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
color: Colors.grey[200],
),
child: Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
isLive ? Icons.near_me : Icons.pin_drop,
size: 48,
color: Colors.blue,
),
const SizedBox(height: 8),
Text(
isLive ? 'Live Location' : 'Shared Location',
style: const TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
Text(
'${sharedLocation.coordinates.latitude.toStringAsFixed(4)}, ${sharedLocation.coordinates.longitude.toStringAsFixed(4)}',
style: const TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
],
),
),
if (sharedLocation.isLive && isFromCurrentUser)
Positioned(
top: 8,
right: 8,
child: GestureDetector(
onTap: switch (onStopLiveLocation) {
final onStop? => () => onStop(sharedLocation),
_ => null,
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(12),
),
child: const Text(
'Stop Sharing',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
);
}
}