|  | 
|  | 1 | +import 'package:fl_chart/src/chart/stacked_pie_chart/stacked_pie_chart_data.dart'; | 
|  | 2 | +import 'package:fl_chart/src/chart/stacked_pie_chart/stacked_pie_chart_renderer.dart'; | 
|  | 3 | +import 'package:flutter/material.dart'; | 
|  | 4 | + | 
|  | 5 | +/// Renders a stacked pie chart as a widget, using provided [StackedPieChartData]. | 
|  | 6 | +class StackedPieChart extends ImplicitlyAnimatedWidget { | 
|  | 7 | +  /// [data] defines the look of [StackedPieChart]. | 
|  | 8 | +  /// When you make any change in the [StackedPieChartData], it updates | 
|  | 9 | +  /// new values with animation, and duration is [duration]. | 
|  | 10 | +  /// also you can change the [curve] | 
|  | 11 | +  /// which default is [Curves.linear]. | 
|  | 12 | +  const StackedPieChart( | 
|  | 13 | +    this.data, { | 
|  | 14 | +    super.key, | 
|  | 15 | +    super.duration = const Duration(milliseconds: 150), | 
|  | 16 | +    super.curve = Curves.linear, | 
|  | 17 | +  }); | 
|  | 18 | + | 
|  | 19 | +  /// Default duration to reuse externally. | 
|  | 20 | +  static const defaultDuration = Duration(milliseconds: 150); | 
|  | 21 | + | 
|  | 22 | +  /// Determines how the [StackedPieChart] should be look like. | 
|  | 23 | +  final StackedPieChartData data; | 
|  | 24 | + | 
|  | 25 | +  /// Creates a [_StackedPieChartState] | 
|  | 26 | +  @override | 
|  | 27 | +  _StackedPieChartState createState() => _StackedPieChartState(); | 
|  | 28 | +} | 
|  | 29 | + | 
|  | 30 | +class _StackedPieChartState extends AnimatedWidgetBaseState<StackedPieChart> { | 
|  | 31 | +  StackedPieChartDataTween? _stackedPieChartDataTween; | 
|  | 32 | + | 
|  | 33 | +  @override | 
|  | 34 | +  void initState() { | 
|  | 35 | +    /// Make sure that [_widgetsPositionHandler] is updated. | 
|  | 36 | +    WidgetsBinding.instance.addPostFrameCallback((timeStamp) { | 
|  | 37 | +      if (mounted) { | 
|  | 38 | +        setState(() {}); | 
|  | 39 | +      } | 
|  | 40 | +    }); | 
|  | 41 | + | 
|  | 42 | +    super.initState(); | 
|  | 43 | +  } | 
|  | 44 | + | 
|  | 45 | +  @override | 
|  | 46 | +  Widget build(BuildContext context) { | 
|  | 47 | +    final showingData = _getData(); | 
|  | 48 | + | 
|  | 49 | +    return StackedPieChartLeaf( | 
|  | 50 | +      data: _stackedPieChartDataTween!.evaluate(animation), | 
|  | 51 | +      targetData: showingData, | 
|  | 52 | +    ); | 
|  | 53 | +  } | 
|  | 54 | + | 
|  | 55 | +  /// if builtIn touches are enabled, we should recreate our [pieChartData] | 
|  | 56 | +  /// to handle built in touches | 
|  | 57 | +  StackedPieChartData _getData() { | 
|  | 58 | +    return widget.data; | 
|  | 59 | +  } | 
|  | 60 | + | 
|  | 61 | +  @override | 
|  | 62 | +  void forEachTween(TweenVisitor<dynamic> visitor) { | 
|  | 63 | +    _stackedPieChartDataTween = visitor( | 
|  | 64 | +      _stackedPieChartDataTween, | 
|  | 65 | +      widget.data, | 
|  | 66 | +      (dynamic value) => StackedPieChartDataTween( | 
|  | 67 | +          begin: value as StackedPieChartData, end: widget.data), | 
|  | 68 | +    ) as StackedPieChartDataTween?; | 
|  | 69 | +  } | 
|  | 70 | +} | 
|  | 71 | + | 
|  | 72 | +// TODO: implement BadgeWidgetsDelegate? | 
0 commit comments