showPollingResultDialog function
Implementation
void showPollingResultDialog(BuildContext context, EnxController obj,Map<dynamic, dynamic> map) {
print("Result Data :-${jsonEncode(map)}");
var dataObject = map['message']['data'];
// Extract options and result from dataObject
// Extract options and result from dataObject
var options = dataObject['options'];
var result = dataObject['result'];
Map<String, double> dataMap = {};
options.forEach((key, value) {
// Extract the option number from the key (e.g., 'opt1' -> 1)
int optNo = int.parse(key.replaceAll('opt', ''));
// Get the corresponding vote count for this option number
double vote = (result['opt$optNo'] as int).toDouble();
// Add the option name (value) as the key and the vote count as the value
dataMap[value] = vote;
});
Get.dialog(
Center(
child: Material(
type: MaterialType.transparency,
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
height: MediaQuery.of(context).size.height * 0.7, // 90% of screen width
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.black87, // Replace with your desired background color
borderRadius: BorderRadius.circular(15.0), // Rounded corners
),
child:Column(children: [
Align(
alignment: Alignment.topRight,
child: IconButton(
icon: Icon(Icons.close),
color: Colors.white,
onPressed: () {
// obj.isAnswerDialogOpen.value = false;
//.cancelTimer(); // Cancel the timer
Get.back(); // Close the dialog
},
),
),
PieChart(dataMap: dataMap,
chartRadius: MediaQuery.of(context).size.width / 2 ,
chartValuesOptions: ChartValuesOptions(
showChartValueBackground: true,
showChartValues: true,
showChartValuesInPercentage: true,
showChartValuesOutside: false,
decimalPlaces: 0,
),
legendOptions: LegendOptions(
showLegendsInRow: true,
legendPosition: LegendPosition.bottom,
showLegends: true,
legendTextStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white70
),
),),
],)
),
),
),
barrierDismissible: false,
barrierColor: Colors.black54, // Semi-transparent background
);
}