import 'dart:math'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_scatter/flutter_scatter.dart'; import 'package:konectar_events/model/affiliationsmodel.dart'; import 'package:konectar_events/model/eventsdetailmodel.dart'; import 'package:konectar_events/model/neweventsmodel.dart'; import 'package:konectar_events/model/specialtymodel.dart'; import 'package:konectar_events/utils/constants.dart'; import 'package:konectar_events/utils/util.dart'; import 'package:konectar_events/viewmodel/eventsprovider.dart'; import 'package:konectar_events/viewmodel/hcpprofprovider.dart'; import 'package:konectar_events/widgets/chartline.dart'; import 'package:konectar_events/widgets/customappbar.dart'; import 'package:konectar_events/widgets/customeventsappbar.dart'; import 'package:konectar_events/widgets/flutter_hashtags.dart'; import 'package:konectar_events/widgets/piechart.dart'; import 'package:konectar_events/widgets/word_cloud.dart'; import 'package:provider/provider.dart'; import 'package:word_cloud/word_cloud_data.dart'; import 'package:word_cloud/word_cloud_view.dart'; class EventsInsights extends StatefulWidget { //EventsList eventsdetail; String eventid; List kFlutterHashtags = []; List specialtyList = []; Affiliations affiliations; EventsInsights( {super.key, required this.eventid, required this.kFlutterHashtags, required this.affiliations, required this.specialtyList}); @override State createState() => _EventsInsightsState(); } class _EventsInsightsState extends State { String _value = 'My Events Insights'; int count = 0; String wordstring = ''; @override void initState() { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { init(); }); super.initState(); } init() async { await Provider.of(context, listen: false) .getAllSessionNotesList(widget.eventid); setState(() {}); } @override Widget build(BuildContext context) { final screenSize = MediaQuery.of(context).size; final ratio = screenSize.width / (screenSize.height / 2); List affCountList = []; for (var obj in widget.affiliations.affiliationCount) { affCountList.add(int.parse(obj)); } int maximum = affCountList.reduce(max); return Consumer( builder: (BuildContext context, provider, Widget? child) { List widgets = []; for (var i = 0; i < widget.kFlutterHashtags.length; i++) { widgets.add(ScatterItem(widget.kFlutterHashtags[i], i)); } return Scaffold( backgroundColor: Constants.bgcolor, body: Padding( padding: const EdgeInsets.symmetric(horizontal: 12.0), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Text( // '2024 Hematology/Oncology Pharmacy Association Annual Conference (HOPA)', // style: TextStyle( // color: Colors.blue, // fontWeight: FontWeight.bold, // fontSize: 17, // ), // maxLines: 2, // softWrap: true, // overflow: TextOverflow.ellipsis, // ), // Container( // decoration: BoxDecoration( // // color: Colors.white, // border: Border.all(color: Colors.blueAccent)), // width: 180, // child: DropdownButton( // items: ["All Events Insights", "My Events Insights"] // .map((String value) { // return DropdownMenuItem( // value: value, // child: Text(value), // ); // }).toList(), // value: _value, // onChanged: (value) { // setState(() { // _value = value!; // }); // }, // ), // ), // SizedBox( // height: 20, // ), labelWidget("Topics Discussed"), Card( surfaceTintColor: Colors.white, child: Container( padding: EdgeInsets.all(2.0), margin: EdgeInsets.all(2.0), height: screenSize.height / 2, width: screenSize.width, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20))), child: Center( child: FittedBox( child: Scatter( fillGaps: true, delegate: ArchimedeanSpiralScatterDelegate(ratio: ratio), children: widgets, ), ), ), ), ), SizedBox( height: 20, ), labelWidget("Specialty of speakers"), Card( surfaceTintColor: Colors.white, child: Container( padding: EdgeInsets.all(2.0), margin: EdgeInsets.all(5.0), height: screenSize.height / 2, width: screenSize.width, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(20)), color: Colors.white, ), child: CustomPieChart( specialtyList: widget.specialtyList, ), // child: PieChartWidget([ // Sector( // value: 35.0, // color: Colors.purple, // title: "35% Engineering"), // Sector( // value: 40, color: Colors.amber, title: "40% Development"), // Sector(value: 55, color: Colors.green, title: "55% Social"), // Sector(value: 70, color: Colors.orange, title: "70% Live"), // ]), ), ), SizedBox( height: 20, ), labelWidget("Speaker counts by providers"), Card( surfaceTintColor: Colors.white, child: Container( padding: EdgeInsets.all(12.0), // margin: EdgeInsets.all(10.0), // height: screenSize.height / 3, width: screenSize.width, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(20)), color: Colors.white, ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: List.generate( widget.affiliations.affiliationCount.length, (index) { return ChartLine( title: widget.affiliations.affiliationNames[index], number: int.parse( widget.affiliations.affiliationCount[index]), rate: int.parse(widget.affiliations .affiliationCount[index]) == maximum ? 1 : int.parse(widget.affiliations .affiliationCount[index]) / maximum); }), )), ), SizedBox( height: 20, ), labelWidget("Session Notes"), Card( surfaceTintColor: Colors.white, child: Container( padding: EdgeInsets.all(4.0), margin: EdgeInsets.all(4.0), // height: screenSize.height / 3, width: screenSize.width, constraints: BoxConstraints( maxHeight: provider.allSessionNotesList.length > 3 ? screenSize.height : 400, minHeight: 400), // height: double.minPositive, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(20)), color: Colors.white, ), child: provider.allSessionNotesList.isNotEmpty ? ListView.separated( padding: EdgeInsets.zero, itemCount: provider.allSessionNotesList.length, itemBuilder: (context, index) { return ExpansionTile( initiallyExpanded: true, shape: Border(), expandedCrossAxisAlignment: CrossAxisAlignment.start, expandedAlignment: Alignment.topLeft, childrenPadding: EdgeInsets.all(8.0), title: Text( "\"${provider.allSessionNotesList[index].notes}\"", style: TextStyle( fontSize: 15, fontStyle: FontStyle.italic)), subtitle: Padding( padding: const EdgeInsets.symmetric( vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( "Added by: ${provider.allSessionNotesList[index].addedBy}", style: TextStyle( color: Colors.grey[900], fontSize: 12), ), Text( "On: ${provider.allSessionNotesList[index].addedDate}", style: TextStyle( color: Colors.grey[900], fontSize: 12), ), ], ), ), children: [ Container( padding: EdgeInsets.all(8.0), // width: isTablet // ? MediaQuery.of(context).size.width * 0.25 // : MediaQuery.of(context).size.width * 0.5, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Session: ${provider.allSessionNotesList[index].selectedSession}", maxLines: 3, style: TextStyle( // decoration: TextDecoration.underline, // decorationColor: Colors.blue, //fontFamily: "SourceSerif", color: Colors.grey[700], //fontStyle: FontStyle.italic, fontSize: 14), ), SizedBox( height: 5, ), Text( "Speaker: ${provider.allSessionNotesList[index].hcpname}", maxLines: 3, style: TextStyle( // decoration: TextDecoration.underline, // decorationColor: Colors.blue, //fontFamily: "SourceSerif", color: Colors.grey[700], //fontStyle: FontStyle.italic, fontSize: 14), ), ], ), ), // Text( // "Notes : ${sessionNotesList[index]}", // maxLines: 3, // style: TextStyle( // // decoration: TextDecoration.underline, // // decorationColor: Colors.blue, // fontFamily: "SourceSerif", // color: Colors.grey[700], // //fontStyle: FontStyle.italic, // fontSize: 14), // ), ], ); }, separatorBuilder: (BuildContext context, int index) { return Divider(); }, // separatorBuilder: (context, index) { // return Divider(); // }, ) : Center(child: Text("No added session notes"))), ), ], ), ), ), ); }); } Widget labelWidget(String title) { return Text( title, style: TextStyle( color: Colors.black, fontWeight: FontWeight.bold, fontSize: 17, ), maxLines: 2, softWrap: true, overflow: TextOverflow.ellipsis, ); } Widget bargraph() { return BarChart(BarChartData( borderData: FlBorderData( border: const Border( top: BorderSide(width: 1), right: BorderSide(width: 1), left: BorderSide.none, bottom: BorderSide.none, )), groupsSpace: 10, barGroups: [ BarChartGroupData( x: 1, barRods: [ BarChartRodData( fromY: 0, toY: 10, width: 15, color: Colors.amber), ], groupVertically: false), BarChartGroupData(x: 2, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 10, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 3, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 15, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 4, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 10, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 5, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 11, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 6, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 10, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 7, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 10, width: 15, color: Colors.amber), ]), BarChartGroupData(x: 8, groupVertically: false, barRods: [ BarChartRodData(fromY: 0, toY: 10, width: 15, color: Colors.amber), ]), ])); } } class PieChartWidget extends StatelessWidget { final List sectors; const PieChartWidget(this.sectors, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { return AspectRatio( aspectRatio: 1.0, child: PieChart(PieChartData( sections: _chartSections(sectors), centerSpaceRadius: 58.0, ))); } List _chartSections(List sectors) { final List list = []; for (var sector in sectors) { const double radius = 40.0; final data = PieChartSectionData( color: sector.color, value: sector.value, radius: radius, title: sector.title, ); list.add(data); } return list; } } class SmallPieChartWidget extends StatelessWidget { final List sectors; const SmallPieChartWidget(this.sectors, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { return AspectRatio( aspectRatio: 2.0, child: PieChart(PieChartData( sections: _chartSections(sectors), centerSpaceRadius: 2.0, ))); } List _chartSections(List sectors) { final List list = []; for (var sector in sectors) { const double radius = 100.0; final data = PieChartSectionData( color: sector.color, value: sector.value, radius: radius, title: sector.title, ); list.add(data); } return list; } } class Sector { final Color color; final double value; final String title; Sector({required this.color, required this.value, required this.title}); }