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
var options = dataObject['options'];
var result = dataObject['result'];
Map<String, double> dataMap = {};
options.forEach((key, value) {
int optNo = int.parse(key.replaceAll('opt', ''));
double vote = (result['opt$optNo'] as int).toDouble();
dataMap[value] = vote;
});
Get.dialog(
OrientationBuilder(
builder: (context, orientation) {
final isPortrait = orientation == Orientation.portrait;
return Center(
child: Material(
type: MaterialType.transparency,
child: Container(
width: MediaQuery.of(context).size.width * (isPortrait ? 0.9 : 0.7),
height: MediaQuery.of(context).size.height * (isPortrait ? 0.65 : 0.99),
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(15.0),
),
child: Column(
children: [
Align(
alignment: Alignment.topRight,
child: IconButton(
icon: const Icon(Icons.close),
color: Colors.white,
onPressed: () {
Get.back();
},
),
),
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
dataObject['question'] ?? 'Poll Results',
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
PieChart(
dataMap: dataMap,
chartRadius: MediaQuery.of(context).size.width / (isPortrait ? 2 : 5),
chartValuesOptions: const ChartValuesOptions(
showChartValueBackground: true,
showChartValues: true,
showChartValuesInPercentage: true,
showChartValuesOutside: false,
decimalPlaces: 0,
),
legendOptions: const LegendOptions(
showLegendsInRow: true,
legendPosition: LegendPosition.bottom,
showLegends: true,
legendTextStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white70,
),
),
),
],
),
),
),
],
),
),
),
);
},
),
barrierDismissible: false,
barrierColor: Colors.black54,
);
}