Chepuhagram/lib/presentation/screens/call_screen.dart

90 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
class CallScreen extends StatefulWidget {
final String callId;
final bool isIncoming;
final String callerName;
final VoidCallback onAccept;
final VoidCallback onHangup;
const CallScreen({
super.key,
required this.callId,
required this.isIncoming,
required this.callerName,
required this.onAccept,
required this.onHangup,
});
@override
State<CallScreen> createState() => _CallScreenState();
}
class _CallScreenState extends State<CallScreen> {
// Рендереры для видеопотока
final RTCVideoRenderer _localRenderer = RTCVideoRenderer();
final RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
bool _isAccepted = false;
@override
void initState() {
super.initState();
_localRenderer.initialize();
_remoteRenderer.initialize();
}
@override
void dispose() {
_localRenderer.dispose();
_remoteRenderer.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Stack(
children: [
// Основной контент (Видео или Аватар)
Positioned.fill(
child: _isAccepted
? RTCVideoView(_remoteRenderer, objectFit: RTCVideoViewObjectFit.RTCVideoViewObjectFitCover)
: Center(child: Text(widget.callerName, style: const TextStyle(color: Colors.white, fontSize: 24))),
),
// Панель управления
Positioned(
bottom: 50,
left: 0,
right: 0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
FloatingActionButton(
backgroundColor: Colors.red,
onPressed: () {
widget.onHangup();
Navigator.of(context).pop();
},
child: const Icon(Icons.call_end, color: Colors.white),
),
if (widget.isIncoming && !_isAccepted)
FloatingActionButton(
backgroundColor: Colors.green,
onPressed: () {
setState(() => _isAccepted = true);
widget.onAccept();
},
child: const Icon(Icons.call, color: Colors.white),
),
],
),
),
],
),
);
}
}