@@ -433,6 +433,7 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
433433  ) {
434434    final  data =  holder.data;
435435    final  sectionsAngle =  calculateSectionsAngle (data.sections, data.sumValue);
436+     final  centerRadius =  calculateCenterRadius (viewSize, holder);
436437
437438    final  center =  Offset (viewSize.width /  2 , viewSize.height /  2 );
438439
@@ -448,33 +449,34 @@ class PieChartPainter extends BaseChartPainter<PieChartData> {
448449    PieChartSectionData ?  foundSectionData;
449450    var  foundSectionDataPosition =  - 1 ;
450451
451-     /// Find the nearest section base on the touch spot 
452- final  relativeTouchAngle =  (touchAngle -  data.startDegreeOffset) %  360 ;
453-     var  tempAngle =  0.0 ;
452+     var  tempAngle =  data.startDegreeOffset;
454453    for  (var  i =  0 ; i <  data.sections.length; i++ ) {
455454      final  section =  data.sections[i];
456-       var  sectionAngle =  sectionsAngle[i];
455+       final  sectionAngle =  sectionsAngle[i];
457456
458-       tempAngle %=  360 ;
459-       if  (data.sections.length ==  1 ) {
460-         sectionAngle =  360 ;
461-       } else  {
462-         sectionAngle %=  360 ;
457+       if  (sectionAngle ==  360 ) {
458+         final  distance =  math.sqrt (
459+           math.pow (localPosition.dx -  center.dx, 2 ) + 
460+               math.pow (localPosition.dy -  center.dy, 2 ),
461+         );
462+         if  (distance >=  centerRadius && 
463+             distance <=  section.radius +  centerRadius) {
464+           foundSectionData =  section;
465+           foundSectionDataPosition =  i;
466+         }
467+         break ;
463468      }
464469
465-       /// degree criteria 
466- final  space =  data.sectionsSpace /  2 ;
467-       final  fromDegree =  tempAngle +  space;
468-       final  toDegree =  sectionAngle +  tempAngle -  space;
469-       final  isInDegree = 
470-           relativeTouchAngle >=  fromDegree &&  relativeTouchAngle <=  toDegree;
471- 
472-       /// radius criteria 
473- final  centerRadius =  calculateCenterRadius (viewSize, holder);
474-       final  sectionRadius =  centerRadius +  section.radius;
475-       final  isInRadius =  touchR >  centerRadius &&  touchR <=  sectionRadius;
470+       final  sectionPath =  generateSectionPath (
471+         section,
472+         data.sectionsSpace,
473+         tempAngle,
474+         sectionAngle,
475+         center,
476+         centerRadius,
477+       );
476478
477-       if  (isInDegree  &&  isInRadius ) {
479+       if  (sectionPath. contains (localPosition) ) {
478480        foundSectionData =  section;
479481        foundSectionDataPosition =  i;
480482        break ;
0 commit comments