Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created May 4, 2023 20:07
Show Gist options
  • Save lukepighetti/abf24b17f1061ba66d7a23e4e6ad2ede to your computer and use it in GitHub Desktop.
Save lukepighetti/abf24b17f1061ba66d7a23e4e6ad2ede to your computer and use it in GitHub Desktop.
Boring RoundedRectangle with platform aware superellipse corners
import 'dart:io';
import 'package:figma_squircle/figma_squircle.dart';
import 'package:flutter/widgets.dart';
class RoundedRectangle extends StatelessWidget {
const RoundedRectangle({
super.key,
this.radius = 10,
this.height,
this.width,
this.top = 0,
this.right = 0,
this.bottom = 0,
this.left = 0,
this.topLeft = 0,
this.topRight = 0,
this.bottomRight = 0,
this.bottomLeft = 0,
this.strokeColor,
this.strokeWidth,
this.child,
this.color,
this.gradient,
this.image,
});
final double? height;
final double? width;
final double radius;
final double top;
final double right;
final double bottom;
final double left;
final double topLeft;
final double topRight;
final double bottomRight;
final double bottomLeft;
final Color? strokeColor;
final double? strokeWidth;
final Widget? child;
final Color? color;
final Gradient? gradient;
final DecorationImage? image;
static final _smoothing = Platform.isIOS ? 0.6 : 0.0;
@override
Widget build(BuildContext context) {
return Container(
height: height,
width: width,
alignment: Alignment.center,
decoration: ShapeDecoration(
color: color,
gradient: gradient,
image: image,
shape: SmoothRectangleBorder(
side: strokeColor != null && strokeWidth != null
? BorderSide(
color: strokeColor!,
width: strokeWidth!,
strokeAlign: BorderSide.strokeAlignCenter,
)
: BorderSide.none,
borderRadius: SmoothBorderRadius.only(
topLeft: SmoothRadius(
cornerRadius: radius + top + left + topLeft,
cornerSmoothing: _smoothing,
),
topRight: SmoothRadius(
cornerRadius: radius + top + right + topRight,
cornerSmoothing: _smoothing,
),
bottomRight: SmoothRadius(
cornerRadius: radius + bottom + right + bottomRight,
cornerSmoothing: _smoothing,
),
bottomLeft: SmoothRadius(
cornerRadius: radius + bottom + left + bottomLeft,
cornerSmoothing: _smoothing,
),
),
),
),
child: child,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment