Voice Call Screen
Loading preview
Starting the Flutter app
Audio-only call UI with mute, speaker, and hold controls
import 'package:flutter/material.dart';
class VoiceCallScreen extends StatefulWidget {
const VoiceCallScreen({super.key});
@override
State<VoiceCallScreen> createState() => _VoiceCallScreenState();
}
class _VoiceCallScreenState extends State<VoiceCallScreen>
with SingleTickerProviderStateMixin {
bool _isMuted = false;
bool _isSpeakerOn = false;
bool _isOnHold = false;
late AnimationController _pulseController;
late Animation<double> _pulseAnimation;
@override
void initState() {
super.initState();
_pulseController = AnimationController(
duration: const Duration(milliseconds: 1500),
vsync: this,
)..repeat(reverse: true);
_pulseAnimation = Tween<double>(begin: 1.0, end: 1.15).animate(
CurvedAnimation(parent: _pulseController, curve: Curves.easeInOut),
);
}
@override
void dispose() {
_pulseController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: isDark ? Colors.grey[900] : Colors.blue[900],
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
tooltip: 'Back',
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
actions: [
IconButton(
tooltip: 'Contacts',
icon: const Icon(Icons.contacts, color: Colors.white),
onPressed: () => _showDemo(context, 'Contacts (demo)'),
),
],
),
body: SafeArea(
child: Column(
children: [
const Spacer(),
AnimatedBuilder(
animation: _pulseAnimation,
builder: (context, child) {
return Transform.scale(
scale: _pulseAnimation.value,
child: Container(
width: 180,
height: 180,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white.withValues(alpha: 0.1),
border: Border.all(
color: Colors.white.withValues(alpha: 0.3),
width: 3,
),
),
child: const Center(
child: CircleAvatar(
radius: 70,
backgroundColor: Colors.white24,
child: Icon(
Icons.person,
size: 70,
color: Colors.white,
),
),
),
),
);
},
),
const SizedBox(height: 30),
const Text(
'Sarah Johnson',
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const SizedBox(width: 8),
Text(
'00:45:32',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.8),
fontSize: 16,
),
),
],
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildActionButton(
icon: _isMuted ? Icons.mic_off : Icons.mic,
label: _isMuted ? 'Unmute' : 'Mute',
isActive: _isMuted,
onTap: () => setState(() => _isMuted = !_isMuted),
),
_buildActionButton(
icon: Icons.call_end,
label: 'End',
color: Colors.red,
size: 72,
onTap: () => Navigator.pop(context),
),
_buildActionButton(
icon: _isSpeakerOn ? Icons.volume_up : Icons.volume_off,
label: 'Speaker',
isActive: _isSpeakerOn,
onTap: () => setState(() => _isSpeakerOn = !_isSpeakerOn),
),
],
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildSmallButton(
icon: _isOnHold ? Icons.play_arrow : Icons.pause,
onTap: () => setState(() => _isOnHold = !_isOnHold),
),
const SizedBox(width: 20),
_buildSmallButton(icon: Icons.add, onTap: () => _showDemo(context, 'Add call (demo)')),
],
),
const SizedBox(height: 40),
],
),
),
);
}
Widget _buildActionButton({
required IconData icon,
required String label,
bool isActive = false,
Color? color,
double size = 60,
required VoidCallback onTap,
}) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: onTap,
child: Container(
width: size,
height: size,
decoration: BoxDecoration(
color: isActive
? Colors.white.withValues(alpha: 0.3)
: Colors.white.withValues(alpha: 0.2),
shape: BoxShape.circle,
),
child: Icon(icon, color: color ?? Colors.white, size: size * 0.4),
),
),
const SizedBox(height: 8),
Text(
label,
style: TextStyle(
color: Colors.white.withValues(alpha: 0.8),
fontSize: 12,
),
),
],
);
}
Widget _buildSmallButton({
required IconData icon,
required VoidCallback onTap,
}) {
return GestureDetector(
onTap: onTap,
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.2),
shape: BoxShape.circle,
),
child: Icon(icon, color: Colors.white, size: 24),
),
);
}
}
void _showDemo(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
The one live element is the pulse: _pulseController scales the avatar ring between 1.0 and 1.15 through _pulseAnimation, whatever the call state. Mute, speaker and hold all update their icons, with hold showing Icons.pause until the call is held and Icons.play_arrow to resume. No audio connection exists, and ‘00:45:32’ and ‘Sarah Johnson’ are literals.
Adapting it
- Stop
_pulseControllerwhile_isOnHoldis true. - Call your VoIP SDK where
_isMuted,_isSpeakerOnand_isOnHoldflip insetState. - Hang up in the End
_buildActionButtonbeforeNavigator.pop.