import 'package:agora_rtc_engine/rtc_engine.dart'; import 'package:flutter/material.dart'; import 'package:async/async.dart'; import 'dart:developer'; import 'package:permission_handler/permission_handler.dart'; import './call.dart'; import 'package:flutter/material.dart' hide Size; import 'dart:ui' as ui; class IndexPage extends StatefulWidget { const IndexPage({Key? key}) : super(key: key); @override State createState() => _IndexPageState(); } class _IndexPageState extends State { TextEditingController _channelController = TextEditingController(text: 'call'); bool _validateError=false; ClientRole? _role= ClientRole.Broadcaster; @override void dispose() { _channelController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("VideoCall"), centerTitle: true, ), body: SingleChildScrollView( child: Container( padding: const EdgeInsets.symmetric(horizontal: 20), child: Column( children: [ const SizedBox(height: 20), const SizedBox(height: 20), TextField( controller: _channelController, decoration: InputDecoration( errorText: _validateError ? 'Chanel Name is Mondatory' : null, border: UnderlineInputBorder(borderSide: BorderSide(width: 1),), hintText: 'channel name', ), ), RadioListTile( title: const Text('Broadcaster'), onChanged: (ClientRole? value) { setState(() { _role=value; }); }, value: ClientRole.Broadcaster, groupValue: _role, ), RadioListTile( title: const Text('Audience'), onChanged: (ClientRole? value) { setState(() { _role=value; }); }, value: ClientRole.Audience, groupValue: _role, ), ElevatedButton( onPressed: onjoin, child: const Text('Join'), style: ElevatedButton.styleFrom( minimumSize: const ui.Size(double.infinity, 40), ), ) ], ), ), ), ); } Future onjoin() async { setState(() { _channelController.text.isEmpty ? _validateError=true: _validateError=false; // This line doesn't actually update any state }); if(_channelController.text.isNotEmpty) { await _handlecameraAndMic(Permission.camera); await _handlecameraAndMic(Permission.microphone); await Navigator.push( context, MaterialPageRoute( builder: (__) => CallPage( channelName: _channelController.text, // Passes the text from _channelController as channelName role: _role, // Passes the value of _role as role ), ), ); } } Future _handlecameraAndMic(Permission permission) async { final status=await permission.request(); log(status.toString()); } }