feat: Enhance UiAppBar and UiIconButton with customizable shapes and border radius

This commit is contained in:
Achintha Isuru
2026-02-21 18:27:59 -05:00
parent f3eb33a303
commit 216076f753
2 changed files with 34 additions and 14 deletions

View File

@@ -1,13 +1,14 @@
import 'package:design_system/design_system.dart';
import 'package:design_system/src/ui_typography.dart'; import 'package:design_system/src/ui_typography.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../ui_icons.dart'; import '../ui_icons.dart';
import 'ui_icon_button.dart';
/// A custom AppBar for the Krow UI design system. /// A custom AppBar for the Krow UI design system.
/// ///
/// This widget provides a consistent look and feel for top app bars across the application. /// This widget provides a consistent look and feel for top app bars across the application.
class UiAppBar extends StatelessWidget implements PreferredSizeWidget { class UiAppBar extends StatelessWidget implements PreferredSizeWidget {
const UiAppBar({ const UiAppBar({
super.key, super.key,
this.title, this.title,
@@ -20,6 +21,7 @@ class UiAppBar extends StatelessWidget implements PreferredSizeWidget {
this.showBackButton = true, this.showBackButton = true,
this.bottom, this.bottom,
}); });
/// The title text to display in the app bar. /// The title text to display in the app bar.
final String? title; final String? title;
@@ -53,18 +55,19 @@ class UiAppBar extends StatelessWidget implements PreferredSizeWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AppBar( return AppBar(
title: titleWidget ?? title:
(title != null titleWidget ??
? Text( (title != null ? Text(title!, style: UiTypography.headline4b) : null),
title!, leading:
style: UiTypography.headline4b, leading ??
)
: null),
leading: leading ??
(showBackButton (showBackButton
? IconButton( ? UiIconButton(
icon: const Icon(UiIcons.chevronLeft, size: 20), icon: UiIcons.chevronLeft,
onPressed: onLeadingPressed ?? () => Navigator.of(context).pop(), onTap: onLeadingPressed ?? () => Navigator.of(context).pop(),
backgroundColor: UiColors.transparent,
iconColor: UiColors.iconThird,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(UiConstants.radiusBase),
) )
: null), : null),
actions: actions, actions: actions,
@@ -74,5 +77,6 @@ class UiAppBar extends StatelessWidget implements PreferredSizeWidget {
} }
@override @override
Size get preferredSize => Size.fromHeight(height + (bottom?.preferredSize.height ?? 0.0)); Size get preferredSize =>
Size.fromHeight(height + (bottom?.preferredSize.height ?? 0.0));
} }

View File

@@ -16,6 +16,8 @@ class UiIconButton extends StatelessWidget {
required this.iconColor, required this.iconColor,
this.useBlur = false, this.useBlur = false,
this.onTap, this.onTap,
this.shape = BoxShape.circle,
this.borderRadius,
}); });
/// Creates a primary variant icon button with solid background. /// Creates a primary variant icon button with solid background.
@@ -25,6 +27,8 @@ class UiIconButton extends StatelessWidget {
this.size = 40, this.size = 40,
this.iconSize = 20, this.iconSize = 20,
this.onTap, this.onTap,
this.shape = BoxShape.circle,
this.borderRadius,
}) : backgroundColor = UiColors.primary, }) : backgroundColor = UiColors.primary,
iconColor = UiColors.white, iconColor = UiColors.white,
useBlur = false; useBlur = false;
@@ -36,6 +40,8 @@ class UiIconButton extends StatelessWidget {
this.size = 40, this.size = 40,
this.iconSize = 20, this.iconSize = 20,
this.onTap, this.onTap,
this.shape = BoxShape.circle,
this.borderRadius,
}) : backgroundColor = UiColors.primary.withAlpha(96), }) : backgroundColor = UiColors.primary.withAlpha(96),
iconColor = UiColors.primary, iconColor = UiColors.primary,
useBlur = true; useBlur = true;
@@ -60,13 +66,23 @@ class UiIconButton extends StatelessWidget {
/// Callback when the button is tapped. /// Callback when the button is tapped.
final VoidCallback? onTap; final VoidCallback? onTap;
/// The shape of the button (circle or rectangle).
final BoxShape shape;
/// The border radius for rectangle shape.
final BorderRadius? borderRadius;
@override @override
/// Builds the icon button UI. /// Builds the icon button UI.
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget button = Container( final Widget button = Container(
width: size, width: size,
height: size, height: size,
decoration: BoxDecoration(color: backgroundColor, shape: BoxShape.circle), decoration: BoxDecoration(
color: backgroundColor,
shape: shape,
borderRadius: shape == BoxShape.rectangle ? borderRadius : null,
),
child: Icon(icon, color: iconColor, size: iconSize), child: Icon(icon, color: iconColor, size: iconSize),
); );