thumb_painter.dart 1.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/painting.dart';

final MaskFilter _kShadowMaskFilter = new MaskFilter.blur(BlurStyle.normal, BoxShadow.convertRadiusToSigma(1.0));

class CupertinoThumbPainter {
  CupertinoThumbPainter({
    this.color: const Color(0xFFFFFFFF),
    this.shadowColor: const Color(0x2C000000),
  });

  final Color color;
  final Color shadowColor;

  static const double radius = 14.0;
  static const double extension = 7.0;

  void paint(Canvas canvas, Rect rect) {
    final RRect rrect = new RRect.fromRectAndRadius(rect, new Radius.circular(rect.shortestSide / 2.0));

    Paint paint = new Paint()
      ..color = shadowColor
      ..maskFilter = _kShadowMaskFilter;
    canvas.drawRRect(rrect, paint);
    canvas.drawRRect(rrect.shift(const Offset(0.0, 3.0)), paint);

    paint
      ..color = color
      ..maskFilter = null;
    canvas.drawRRect(rrect, paint);
  }
}