Skip to content

Commit

Permalink
Refactored badge to match the new design (#78)
Browse files Browse the repository at this point in the history
* refactored badge
  • Loading branch information
Ibrahimhass authored May 14, 2024
1 parent 5011cf5 commit 6ab7b78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
12 changes: 3 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,30 +316,24 @@ class _HomePageState extends State<HomePage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TUIBadge(
isNumbered: true,
content: "1",
content: "400",
badgeSize: TUIBadgeSize.l,
),
TUIBadge(
isNumbered: true,
content: "1",
content: "4",
badgeSize: TUIBadgeSize.s,
),
TUIBadge(
isNumbered: true,
content: "1",
content: "400",
badgeSize: TUIBadgeSize.xs,
),
TUIBadge(
isNumbered: false,
badgeSize: TUIBadgeSize.l,
),
TUIBadge(
isNumbered: false,
badgeSize: TUIBadgeSize.s,
),
TUIBadge(
isNumbered: false,
badgeSize: TUIBadgeSize.xs,
),
],
Expand Down
26 changes: 11 additions & 15 deletions lib/components/badge/badge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ enum TUIBadgeSize {
EdgeInsets _getEdgeInsets() {
switch (this) {
case xs:
return const EdgeInsets.fromLTRB(3, 0, 3, 0);
return const EdgeInsets.all(0);
case s:
return const EdgeInsets.symmetric(horizontal: 5, vertical: 1);
return const EdgeInsets.symmetric(horizontal: 4);
case l:
return const EdgeInsets.symmetric(horizontal: 8, vertical: 4);
return const EdgeInsets.symmetric(horizontal: 8);
}
}

Expand Down Expand Up @@ -72,26 +72,22 @@ enum TUIBadgeSize {
class TUIBadge extends StatelessWidget {
final TUIBadgeSize badgeSize;
final String? content;
final bool isNumbered;
final Color? badgeColor;

const TUIBadge({
super.key,
required this.badgeSize,
this.content,
this.isNumbered = false,
});
const TUIBadge(
{super.key, required this.badgeSize, this.content, this.badgeColor});

@override
Widget build(BuildContext context) {
TUIThemeData theme = TUITheme.of(context);
if (content != null && isNumbered) {

if (content != null && badgeSize != TUIBadgeSize.xs) {
return Container(
height: badgeSize._getBadgeSize(),
alignment: Alignment.center,
constraints: BoxConstraints(
minHeight: badgeSize._getBadgeSize(), //minimum height
minWidth: badgeSize._getBadgeSize(), // minimum width
maxHeight: badgeSize._getBadgeSize(),
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
color: theme.colors.error,
Expand All @@ -109,8 +105,8 @@ class TUIBadge extends StatelessWidget {
width: badgeSize._getBadgeSize(),
padding: badgeSize._getEdgeInsets(),
decoration: BoxDecoration(
color: theme.colors.error,
borderRadius: const BorderRadius.all(Radius.circular(20))),
color: badgeColor ?? theme.colors.error,
borderRadius: BorderRadius.all(badgeSize._getBorderRadius())),
);
}
}
Expand Down

0 comments on commit 6ab7b78

Please sign in to comment.