From bf8e13aa09c93e500e9b73571e14d3734d7b2f63 Mon Sep 17 00:00:00 2001 From: Florian Griffon Date: Sun, 15 Dec 2024 19:51:46 +0100 Subject: [PATCH] Rebase --- dialer/lib/features/call/call.dart | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 dialer/lib/features/call/call.dart diff --git a/dialer/lib/features/call/call.dart b/dialer/lib/features/call/call.dart new file mode 100644 index 0000000..6aa312e --- /dev/null +++ b/dialer/lib/features/call/call.dart @@ -0,0 +1,86 @@ +import 'package:flutter/material.dart'; +import 'dart:async'; + +class CallPage extends StatefulWidget { + final String phoneNumber; + + const CallPage({Key? key, required this.phoneNumber}) : super(key: key); + + @override + _CallPageState createState() => _CallPageState(); +} + +class _CallPageState extends State { + bool isCalling = true; + int callDuration = 0; + late final Timer _timer; + + @override + void initState() { + super.initState(); + _startCallTimer(); + } + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + void _startCallTimer() { + _timer = Timer.periodic(Duration(seconds: 1), (timer) { + if (isCalling) { + setState(() { + callDuration++; + }); + } + }); + } + + void _endCall() { + setState(() { + isCalling = false; + }); + Navigator.pop(context); + } + + String _formatDuration(int seconds) { + final minutes = seconds ~/ 60; + final remainingSeconds = seconds % 60; + return '${minutes.toString().padLeft(2, '0')}:${remainingSeconds.toString().padLeft(2, '0')}'; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.black, + body: Center( // Center widget to center all the content vertically and horizontally + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, // Ensure the text and button are centered horizontally + children: [ + Text( + "Calling ${widget.phoneNumber}", + style: TextStyle(color: Colors.white, fontSize: 24), + ), + const SizedBox(height: 20), + Text( + isCalling ? _formatDuration(callDuration) : "Call Ended", + style: TextStyle(color: Colors.greenAccent, fontSize: 20), + ), + const SizedBox(height: 40), + ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + shape: CircleBorder(), + padding: const EdgeInsets.all(20), + ), + onPressed: _endCall, + child: Icon(Icons.call_end, color: Colors.white), + ), + ], + ), + ), + ); + } +}