RtCommonWidget class
A comprehensive utility class providing reusable UI widgets and components for Flutter applications.
RtCommonWidget implements the singleton pattern to ensure a single instance throughout
the application lifecycle. It offers a wide range of pre-configured widgets including:
- Spacing utilities (vertical and horizontal)
- Elevated containers and cards with customizable styling
- Text widgets with various formatting options
- Search bars and input fields
- Empty state and error views
- Image viewers and galleries
- Bottom sheets and dialogs
- Permission request flows
This class leverages GetX for navigation and state management, and integrates with the application's theming system through Utils constants.
Example:
// Access the singleton instance
final widget = RtCommonWidget.instance;
// Add vertical spacing
widget.addVerticalSpace(0.02);
// Create an elevated box
widget.getBoxWithElevation(
child: Text('Content'),
elevation: 4.0,
);
See also:
- Utils for application-wide constants and utilities
- DefaultTextField for text input components
- GlobalBottomSheet for bottom sheet presentations
Constructors
- RtCommonWidget()
-
Factory constructor that returns the singleton instance.
factory
Properties
Methods
-
addHorizontalSpace(
double width) → Widget - Creates a horizontal spacing widget with responsive width.
-
addVerticalSpace(
double height) → Widget - Creates a vertical spacing widget with responsive height.
-
askPermissionBottomSheet(
{required String title, required String description, required String pathDetail, required VoidCallback openSettingsAction, required VoidCallback cancelAction, required VoidCallback closeAction, Color titleColor = Colors.black, Color subTitleColor = Colors.black}) → void - Displays a bottom sheet requesting app permission with navigation to settings.
-
emptyRecordsView(
{String title = "No results found", String description = "", Color titleTextColor = Colors.black, Color descriptionTextColor = Colors.black}) → Widget - Displays an empty state view when no records are found.
-
followWidget(
{required String count, required String label, MaterialColor countColor = Colors.blue, MaterialColor labelColor = Colors.blue, String? countFontFamily, FontWeight? countFontWeight, FontWeight? labelFontWeight, String? labelFontFamily, double? countFontSize, double? labelFontSize}) → Widget - Creates a follower/following widget with count and label.
-
getBottomSheetLayoutForCameraGallery(
{String title = "Choose option", String camTitle = "Camera", String galleryTitle = "Gallery", String cancelTitle = "Cancel", String? titleFontFamily, String? camTitleFontFamily, String? galleryTitleFontFamily, String? cancelTitleFontFamily, double? titleFontSize, double? camTitleFontSize, double? galleryTitleFontSize, double? cancelTitleFontSize, double titlePadding = 16, double? cancelHorizontalPadding, double? cancelVerticalPadding, IconData? camIcon, IconData? galleryIcon, bool isTitleCenter = true, bool isGalleryTitleCenter = true, bool isCamTitleCenter = true, Color titleColor = Colors.black, Color camTitleColor = Colors.black, Color galleryTitleColor = Colors.black, Color cancelTitleColor = Colors.black, Color galleryColor = Colors.black, Color camColor = Colors.black}) → Widget - Creates a bottom sheet layout for camera/gallery selection.
-
getBottomSheetsHeader(
{required String title, required String warningText, int maxLines = 2, String? titleFontFamily, String? warningTextFontFamily, double? titleFontSize, double? warningTextFontSize, double warningTextLetterSpacing = 0.5, double warningTextHeight = 1.5, IconData? icon, Color iconColor = Colors.black, VoidCallback? onPressed, Color titleColor = Colors.black, Color warningTextColor = Colors.black}) → Widget - Creates a header widget for bottom sheets with title, warning text, and close button.
-
getBoxWithElevation(
{required Widget child, double elevation = 4, double? padding, double? borderRadius, double verticalMargin = 8.0, Color color = Colors.white}) → Widget - Creates an elevated card container with customizable styling.
-
getBoxWithElevationWithPadding(
Widget childWidget, {double margin = 8.0, double elevation = 4.0, double borderRadius = 4.0, Color color = Colors.white, double padding = 8.0, double hPadding = 0.0}) → Widget - Creates an elevated card with symmetric horizontal and vertical padding.
-
getCommonSearchTextField(
BuildContext context, TextEditingController txtController, String hintText, dynamic onSubmitted(String), {Color theme = Colors.grey, Color focusColor = Colors.black, Color borderColor = Colors.black, double? width, double height = 47, double? imgSearchSizeHeight, double? imgSearchSizeWidth, double? searchTextFieldPadding, TextInputAction? textInputAction, InputBorder? inputBorder, TextStyle? txtSearchTextStyle, BorderRadiusGeometry? searchIconContainerBorderRadius, Icon? imgSearch, TextStyle? labelTxtSearchTextStyle}) → Widget - Creates a common search text field with dynamic focus styling.
-
getDualTableCheckListRows(
Widget item, Widget secondItem, {double firstItemPadding = 1.0, double secondItemPadding = 1.0, double secondItemLeftPadding = 5.0}) → TableRow - Creates a table row with two items in a dual-column layout.
-
getDualTableRows(
Map< dynamic, Map< item, Map<String, String> >dynamic, Map< ? secondItem, {double firstItemPadding = 4.0, double secondItemPadding = 4.0, double secondItemLeftPadding = 15.0, Color firstItemIconColor = Colors.black, Color firstItemTitleColor = Colors.black, Color secondItemTitleColor = Colors.black, Color firstItemValueColor = Colors.black, Color secondItemValueColor = Colors.black, Color secondItemIconColor = Colors.black}) → TableRowString, String> > - Creates a table row with two complex items containing icons/images and text.
-
getEmptyView(
{required String title, required String msg, String? titleFontFamily, String? valueFontFamily, double? titleFontSize, double? valueFontSize, double? verticalSpace, double? iconSize, double? width, Color iconColor = Colors.blue, bool isTitleCenter = true, bool isValueCenter = true, Color titleTextColor = Colors.black, Color valueTextColor = Colors.black}) → Widget - Creates an empty state view with title, icon, and message.
-
getErrorView(
{required String title, required String msg, double? iconSize, double? width, Color iconColor = Colors.red, double? verticalSpace, String? titleFontFamily, String? valueFontFamily, double? titleFontSize, double? valueFontSize, Color titleTextColor = Colors.black, Color valueTextColor = Colors.black}) → Widget - Creates an error view with title, error icon, and message.
-
getHeaderForLoginRegisterDesign(
{required String heading, required String subHeading, Color headingTextColor = Colors.black, Color subHeadingTextColor = Colors.black}) → Widget - Creates a header widget for login/register screens.
-
getLoadingWidget(
{String? loadingMsg, Color textColor = Colors.black}) → Widget - Creates a loading indicator widget with optional text.
-
getRoundBoxWithElevation(
{required Widget child, double elevation = 4, double? padding, double borderRadius = 20, double verticalMargin = 8.0, Color color = Colors.white}) → Widget - Creates a rounded elevated card container with highly customizable corner radius.
-
getRoundedBackground(
Widget child, Color backgroundColor, {double? width}) → Widget - Creates a rounded container with a colored background.
-
getRoundedNetworkImage(
Map< dynamic, Map< item, {double borderRadius = 5.0, Color borderColor = Colors.black, Color iconColor = Colors.black, double borderWidth = 1, IconData? errorIcon}) → WidgetString, String> > - Displays a network image with rounded border and loading/error states.
-
getRowWithBlackAndPrimaryColor(
{required String title, required String value, String? titleFontFamily, String? valueFontFamily, double? titleFontSize, double? valueFontSize, Color titleTextColor = Colors.black, Color valueTextColor = Colors.black}) → Widget - Creates a horizontal row with two text elements (title and value).
-
getRowWithBoldAndNormalText(
{required String title, required String value, required Color color, double fontSize = 15.0, String fontFamily = "mainFontBold", String valueFontFamily = "mainFontRegular", int titleMaxLines = 1, int valueMaxLines = 1}) → Widget - Creates a row with bold title and regular value text using SelectableText.
-
getRtBoxWithElevation(
Widget childWidget, {double margin = 8.0, double elevation = 4.0, double borderRadius = 4.0, Color color = Colors.white, double padding = 8.0}) → Widget - Creates an elevated card container (alias method).
-
getRtBoxWithElevationDynamicMargin(
Widget childWidget, {double margin = 8.0, double elevation = 4.0, double borderRadius = 4.0, Color color = Colors.white, double padding = 8.0}) → Widget - Creates an elevated card with both horizontal and vertical margins.
-
getSearchbar(
{FocusNode? focusNode, TextEditingController? textEditorController, String searchHint = "", int maxLines = 1, double leftPadding = 0, double rightPadding = 0, bool isShowPrefixIcon = true, TextInputType textInputType = TextInputType.text, required dynamic onChangeMethod(String), required dynamic onSubmitMethod(String)}) → Widget - Creates a customizable search bar widget.
-
getVerticalBar(
Color barColor, double thickness, {EdgeInsetsGeometry? getVerticalBarPadding}) → Widget - Creates a vertical divider bar with customizable color and thickness.
-
horizontalListView(
List attachments, {double maxWidth = 200, double maxHeight = 300, double horizontalMargin = 5, double borderRadius = 15, dynamic onItemTap(dynamic)?, bool? isDeleteShow = false}) → Widget - Creates a horizontal scrolling list view for image attachments.
-
noItemFoundUI(
{required String msg, Alignment? containerAlignment, double? containerWidth, double? containerHeight, double? vwNoItemFoundBorderWidth, double? vwNoItemFoundBorderRadius, EdgeInsets? containerPadding, Color? vwNoItemFoundBgColor, Color? vwNoItemFoundBorderColor, Icon? noItemIcon, TextStyle? txtNoFollowingFoundStyle, TextAlign? textAlign}) → Widget - Creates a "no items found" empty state UI with icon and message.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
selectDate(
dynamic selectedDateCallback(DateTime? selectedDate)) → Future< void> - Opens a date picker dialog and returns the selected date.
-
setHorizontalSizeBox(
double width) → Widget - Creates a horizontal spacing widget with fixed width.
-
setIconButton(
String icon, VoidCallback voidCallBack, {double? height = 25, double? width = 25, Color? iconColor}) → IconButton - Creates an icon button from an asset image.
-
setIconWithText(
{required String label, String? email, String? icon, String? fontFamily, double iconSize = 20, double? fontSize, double? horizontalSpace, Color iconColor = Colors.black, Color textColor = Colors.black, int maxLines = 2}) → Widget - Creates an icon-text combination widget with horizontal layout.
-
setImageAssetsIcon(
{required String name, Color color = Colors.black, BoxFit? boxFit, double width = 20, double height = 20, double padding = 8.0}) → Widget - Creates a padded image widget from assets with customizable styling.
-
setTabBar(
int key, TabController tabController, List< Tab> tabList, {Color indicatorColor = Colors.black, Color unselectedLabelColor = Colors.white, Color selectedLabelTextColor = Colors.blue, Color unselectedLabelTextColor = Colors.white, Color labelColor = Colors.blue}) → TabBar - Creates a customizable TabBar widget with styling options.
-
setText(
String name, String txtFontFamily, Color txtColor, double txtSize, {bool? isCenter = false, bool isMultiLine = false, int maxLine = 1}) → Widget - Creates a customizable text widget with font styling options.
-
setVerticalSizeBox(
double height) → Widget - Creates a vertical spacing widget with fixed height.
-
showBigHeading(
{required String name, int maxLines = 2, bool softWrap = true, double? fontSize, double height = 1, FontWeight? fontWeight, String? fontFamily, TextAlign? textAlign, Color color = Colors.grey}) → Widget - Creates a large heading text widget with bold styling.
-
showDeletedDialog(
{String title = "Deleted", String middleText = "This item is deleted!", String textCancel = "Ok", Color backgroundColor = Colors.white, TextStyle? middleTextStyle, TextStyle? textStyle}) → void - Shows a deletion confirmation dialog.
-
showDescriptionHeader(
String description, {String? title, Color descriptionValueColor = Colors.black}) → Widget - Displays a description header in an elevated card.
-
showHeading(
{required String name, int maxLines = 2, bool softWrap = true, double? fontSize, double height = 1, FontWeight? fontWeight, String? fontFamily, TextAlign? textAlign, Color color = Colors.grey}) → Widget - Creates a heading text widget with customizable styling.
-
textFieldDecoration(
{required String labelText, Color borderSideColor = Colors.black}) → InputDecoration - Creates a standard text field input decoration with label and border.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → RtCommonWidget
-
Returns the singleton instance of RtCommonWidget.
no setter