liveStreamingUi function
Implementation
Future liveStreamingUi(context, EnxController obj){
final _formKey = GlobalKey<FormState>();
return
showGeneralDialog(
context: context,
barrierDismissible: true, // Allows closing the dialog by tapping outside
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black54, // Background color behind the dialog
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) {
return Scaffold(
backgroundColor: Colors.white, // Set the background color to white
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
// Close Button
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: EdgeInsets.only(left: MediaQuery.of(context).size.width / 20 ),
child: Text(
'Live Streaming',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
IconButton(
icon: Icon(Icons.close, color: Colors.black),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Text(
'Start New Stream',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
// Streaming Server Name
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 10.0, 12.0, 0.0),
child: TextFormField(
controller: obj.serverNameTextController,
decoration: InputDecoration(
hintText: 'Streaming Server Name',
hintStyle: TextStyle(color: Colors.grey),
filled: true,
fillColor: Colors.white,
contentPadding: EdgeInsets.all(12.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(
color: Colors.black54,
width: 1,
),
),
),
style: TextStyle(color: Colors.black),
),
),
// RTMP End Point URL
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 10.0, 12.0, 0.0),
child: TextFormField(
controller: obj.rtmpUrlTextController,
decoration: InputDecoration(
hintText: 'RTMP End Point URL *',
hintStyle: TextStyle(color: Colors.grey),
filled: true,
fillColor: Colors.white,
contentPadding: EdgeInsets.all(12.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(
color: Colors.black54,
width: 1,
),
),
),
style: TextStyle(color: Colors.black),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Enter valid RTMP url end point';
}
// Regular expression for basic URL validation
const urlPattern = r'^(https?|rtmp):\/\/[^\s/$.?#].[^\s]*$';
final result = RegExp(urlPattern).hasMatch(value.trim());
if (!result) {
return 'Kindly enter the valid RTMP url';
}
return null;
},
),
),
// RTMP Access Key
Padding(
padding: const EdgeInsets.fromLTRB(15.0, 10.0, 12.0, 0.0),
child: TextFormField(
controller: obj.rtmpKeyTextController,
decoration: InputDecoration(
hintText: 'RTMP Access key *',
hintStyle: TextStyle(color: Colors.grey),
filled: true,
fillColor: Colors.white,
contentPadding: EdgeInsets.all(12.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: const BorderSide(
color: Colors.black54,
width: 1,
),
),
),
style: TextStyle(color: Colors.black),
validator: (value) =>
value!.trim().isEmpty ? 'Enter valid RTMP access key' : null,
),
),
// Start Now Button
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height / 10),
child: Center(
child: DecoratedBox(
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Colors.pinkAccent,
Colors.pink,
CustomColors.themeColor,
],
),
borderRadius: BorderRadius.circular(15),
),
child: ElevatedButton(
child: Text(
"Start Now",
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w400,
fontSize: 15),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
disabledForegroundColor:
Colors.transparent.withOpacity(0.38),
disabledBackgroundColor:
Colors.transparent.withOpacity(0.12),
shadowColor: Colors.transparent,
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(15.0),
),
fixedSize: Size(
MediaQuery.of(context).size.width / 2,
50),
),
onPressed: () {
if (_formKey.currentState!.validate()) {
// Create rtmpDetails JSON object
Map<String, String> rtmpDetails = {
"rtmpUrl": "${obj.rtmpUrlTextController}/${obj.rtmpKeyTextController}",
};
// Create urlDetails JSON object
Map<String, String> urlInfo = {
"url": EnxSetting.instance.urlDetails,
};
// Combine both JSON objects into liveStreamInfo
Map<String, dynamic> liveStreamInfo = {
"rtmpDetails": rtmpDetails,
"urlDetails": urlInfo,
};
// Pass the JSON map to the liveStreamingInformation method
EnxSetting.instance.liveStreamingInformation(liveStreamInfo);
obj.startLiveStream();
Navigator.of(context).pop();
}
},
),
),
),
),
],
),
),
),
),
),
);
},
);
}