non_uniform_border 1.0.2
non_uniform_border: ^1.0.2 copied to clipboard
Provides a border class for Flutter that allows different widths for each side with a single color.
Non-Uniform Border for Flutter #
A lightweight ShapeBorder for Flutter that supports independent side widths, mixed BorderRadius corners, strokeAlign, and smooth lerp() animations with a single color — avoiding Flutter's runtime Border crash when non-uniform border widths are combined with borderRadius.
Why not Flutter's
Border?BoxDecoration(border: Border(...), borderRadius: ...)asserts at runtime unless every side has the same width and color.NonUniformBorderis a drop-inShapeBorderforShapeDecoration(andContainer/AnimatedContainer) with zero crashes.
Getting Started #
Add non_uniform_border to your pubspec.yaml:
dependencies:
non_uniform_border: ^1.0.2
Usage #
Import package:non_uniform_border/non_uniform_border.dart and pass NonUniformBorder to any ShapeDecoration:
import 'package:flutter/widgets.dart';
import 'package:non_uniform_border/non_uniform_border.dart';
// Independent side widths + asymmetric BorderRadius
const shapeBorder = NonUniformBorder(
leftWidth: 4,
topWidth: 12,
rightWidth: 8,
bottomWidth: 16,
color: Color(0xFFFBBF24),
strokeAlign: BorderSide.strokeAlignCenter,
borderRadius: BorderRadius.horizontal(
left: Radius.circular(24),
right: Radius.circular(48),
),
);
Widget example = DecoratedBox(
decoration: const ShapeDecoration(
color: Color(0xFFFEF3C7),
shape: shapeBorder,
),
child: const SizedBox(width: 240, height: 120),
);
Constructors & Helpers #
NonUniformBorder(...)— setleftWidth,topWidth,rightWidth,bottomWidth,color,strokeAlign(BorderSide.strokeAlignInside,strokeAlignCenter,strokeAlignOutside), andborderRadius.NonUniformBorder.symmetric(verticalWidth: ..., horizontalWidth: ...)— mirror top/bottom and left/right widths cleanly.NonUniformBorder.all(width: ...)— uniform border on all sides.NonUniformBorder.fromBorderSide(side)— build directly from a FlutterBorderSide.copyWith(...)— derive variations cleanly (for example, animating a 3D button press withbottomWidth).- Smooth Animations —
ShapeBorder.lerp,AnimatedContainer, andShapeBorderTweensmoothly interpolate side widths,borderRadius,strokeAlign, andcolor.
Properties in Motion #