// Paint the separator to the right of the given child.
        void _paintSeparator(PaintingContext context, Offset offset, RenderBox child)
        {
            D.assert(child != null);
            _SlidingSegmentedControlContainerBoxParentData childParentData =
                child.parentData as _SlidingSegmentedControlContainerBoxParentData;

            Paint paint = new Paint();

            _ChildAnimationManifest manifest = _childAnimations == null ? null : _childAnimations[child];
            float opacity = manifest?.separatorTween?.evaluate(state.separatorOpacityController) ?? 1;

            if (manifest != null)
            {
                manifest.separatorOpacity = opacity;
            }
            paint.color = CupertinoSlidingSegmentedControlsUtils._kSeparatorColor.withOpacity(CupertinoSlidingSegmentedControlsUtils._kSeparatorColor.opacity * opacity);

            Rect childRect     = (childParentData.offset + offset) & child.size;
            Rect separatorRect = CupertinoSlidingSegmentedControlsUtils._kSeparatorInset.deflateRect(
                childRect.topRight & new Size(CupertinoSlidingSegmentedControlsUtils._kSeparatorInset.horizontal + CupertinoSlidingSegmentedControlsUtils._kSeparatorWidth,
                                              child.size.height)
                );

            context.canvas.drawRRect(
                RRect.fromRectAndRadius(separatorRect, CupertinoSlidingSegmentedControlsUtils._kSeparatorRadius),
                paint
                );
        }
 public override void insert(RenderBox child, RenderBox after = null)
 {
     base.insert(child, after: after);
     if (_childAnimations == null)
     {
         return;
     }
     D.assert(_childAnimations.getOrDefault(child) == null);
     _childAnimations[child] = new _ChildAnimationManifest(separatorOpacity: 1);
 }
        public override void paint(PaintingContext context, Offset offset)
        {
            List <RenderBox> children = getChildrenAsList();

            // Paint thumb if highlightedIndex is not null.
            if (highlightedIndex != null)
            {
                if (_childAnimations == null)
                {
                    _childAnimations = new Dictionary <RenderBox, _ChildAnimationManifest>();//<RenderBox, _ChildAnimationManifest> { };
                    for (int i = 0; i < childCount - 1; i += 1)
                    {
                        bool      shouldFadeOut = i == highlightedIndex || i == highlightedIndex - 1;
                        RenderBox child         = children[i];
                        _childAnimations[child] = new _ChildAnimationManifest(separatorOpacity: shouldFadeOut ? 0 : 1);
                    }
                }

                RenderBox selectedChild = children[highlightedIndex ?? 0];

                _SlidingSegmentedControlContainerBoxParentData childParentData =
                    selectedChild.parentData as _SlidingSegmentedControlContainerBoxParentData;
                Rect unscaledThumbTargetRect = CupertinoSlidingSegmentedControlsUtils._kThumbInsets.inflateRect(childParentData.offset & selectedChild.size);

                // Update related Tweens before animation update phase.
                if (_needsThumbAnimationUpdate)
                {
                    // Needs to ensure _currentThumbRect is valid.
                    _currentThumbTween = new RectTween(begin: currentThumbRect ?? unscaledThumbTargetRect, end: unscaledThumbTargetRect);

                    for (int i = 0; i < childCount - 1; i += 1)
                    {
                        bool      shouldFadeOut          = i == highlightedIndex || i == highlightedIndex - 1;
                        RenderBox child                  = children[i];
                        _ChildAnimationManifest manifest = _childAnimations[child];
                        D.assert(manifest != null);
                        manifest.separatorTween = new FloatTween(
                            begin: manifest.separatorOpacity,
                            end: shouldFadeOut ? 0 : 1
                            );
                    }

                    _needsThumbAnimationUpdate = false;
                }
                else if (_currentThumbTween != null && unscaledThumbTargetRect != _currentThumbTween.begin)
                {
                    _currentThumbTween = new RectTween(begin: _currentThumbTween.begin, end: unscaledThumbTargetRect);
                }

                for (int index = 0; index < childCount - 1; index += 1)
                {
                    _paintSeparator(context, offset, children[index]);
                }

                currentThumbRect = _currentThumbTween?.evaluate(state.thumbController)
                                   ?? unscaledThumbTargetRect;

                currentThumbScale = _thumbScaleTween.evaluate(state.thumbScaleController);

                Rect thumbRect = Rect.fromCenter(
                    center: currentThumbRect.center,
                    width: currentThumbRect.width * currentThumbScale,
                    height: currentThumbRect.height * currentThumbScale
                    );

                _paintThumb(context, offset, thumbRect);
            }
            else
            {
                // Reset all animations when there"s no thumb.
                currentThumbRect = null;
                _childAnimations = null;

                for (int index = 0; index < childCount - 1; index += 1)
                {
                    _paintSeparator(context, offset, children[index]);
                }
            }

            for (int index = 0; index < children.Count; index++)
            {
                _paintChild(context, offset, children[index], index);
            }
        }