Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom painter Widgets are incorrectly rendered #191

Closed
jenshor opened this issue May 23, 2022 · 1 comment · Fixed by #193
Closed

Custom painter Widgets are incorrectly rendered #191

jenshor opened this issue May 23, 2022 · 1 comment · Fixed by #193
Assignees
Labels
t: bug Something isn't working

Comments

@jenshor
Copy link
Member

jenshor commented May 23, 2022

Description
When custom painter is used, the rendered output might look wrong.

Widgetbook:
image

Simulator:
image

Code for repro:

class MacroDailyLogCard extends StatelessWidget {
  const MacroDailyLogCard({Key? key, required this.child, this.height = 350}) : super(key: key);

  final Widget child;
  final double height;

  @override
  Widget build(BuildContext context) {
    final CmColorScheme scheme = CmTheme.of(context).colorScheme;

    return Container(
      height: height,
      width: 325,
      decoration: ShapeDecoration(
        shadows: <BoxShadow>[
          BoxShadow(
            offset: const Offset(0, 5),
            blurRadius: 15,
            color: CmColors.shadow.withOpacity(0.1),
          ),
        ],
        color: scheme.gray800,
        shape: CustomShape(),
      ),
      child: child,
    );
  }
}

class CustomShape extends ShapeBorder {
  @override
  EdgeInsetsGeometry get dimensions => EdgeInsetsDirectional.zero;

  @override
  Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
    return Path();
  }

  @override
  Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
    return Path()
      ..moveTo(rect.topLeft.dx, rect.topLeft.dy + 22)
      ..quadraticBezierTo(rect.topLeft.dx + 3, rect.topLeft.dy + 10, rect.topLeft.dx + 14, rect.top + 8)
      ..quadraticBezierTo(rect.width / 2, rect.top - 20, rect.topRight.dx - 14, rect.top + 8)
      ..quadraticBezierTo(rect.topRight.dx - 3, rect.topRight.dy + 10, rect.topRight.dx, rect.top + 22)
      ..lineTo(rect.bottomRight.dx, rect.bottomRight.dy - 22)
      ..quadraticBezierTo(rect.bottomRight.dx - 3, rect.bottomRight.dy - 10, rect.bottomRight.dx - 14, rect.bottom - 8)
      ..quadraticBezierTo(rect.width / 2, rect.bottom + 20, rect.bottomLeft.dx + 14, rect.bottom - 8)
      ..quadraticBezierTo(rect.bottomLeft.dx + 3, rect.bottomLeft.dy - 10, rect.bottomLeft.dx, rect.bottom - 22)
      ..close();
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}

  @override
  ShapeBorder scale(double t) {
    return this;
  }
}

Expected Behavior
Render looks like in the simulator.

@jenshor jenshor added the t: bug Something isn't working label May 23, 2022
@jenshor jenshor self-assigned this May 23, 2022
@jenshor
Copy link
Member Author

jenshor commented May 23, 2022

Might be related to #164.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant