xwidgets library
XWidgets
A small collection of reusable, customizable Flutter widgets intended to speed up common UI tasks and provide a consistent look & feel across apps.
Overview
- Purpose: Provide lightweight, well-documented, and configurable widgets that are easy to drop into any Flutter project.
- Scope: Visual building blocks such as app bars, buttons, cards, text helpers, dashed/divider widgets, snackbars, spacers and enhanced text-fields with validation helpers.
Widgets exported by this library
XAppBar— flexible AppBar replacement with built-in title, actions, and optional leading/content customization.XAsyncView— state-management agnostic asynchronous state renderer.XBottomSheet— typed modal and action-sheet helpers.XButton— configurable button with idle/loading/success/error states, icons, and styles.XCard— a simple card wrapper with padding, elevation and shape props.XCollectionView— paginated list/grid collection.XDebouncedSearchField— search field with debounce and loading state.XDiagonalStrikethroughText— draws a diagonal strikethrough over text (useful for sale/discount UI or decorative effects).XDialog— alert, confirmation, custom, and loading dialog helpers.XDoubleDashedLine— renders two parallel dashed lines, useful as a decorative divider.XResponsiveLayout— responsive mobile/tablet/desktop layout selector.XScreen— scaffold with safe area and loading/error overlays.XSingleDashedLine— renders a single dashed line divider.XSnackbar— a thin wrapper for showing stylable snackbars with convenience options for duration and actions.XScrollView— a state-management agnostic list with initial loading, pull-to-refresh, pagination, empty state, and retry handling.XSpacer— shorthand for flexible spacing between widgets.XTextField— enhanced text field with built-in validator hooks and styling options.XText— lightweight text helper that consolidates common text styles.
Usage Add the package import and use widgets directly:
import 'package:xwidgets/xwidgets.dart';
Example: simple button
XButton(
label: 'Send',
onPressed: () => print('sent'),
);
Contributing
- See the repository
README.mdfor contribution guidelines, code style, and how to run code generation or tests.
Compatibility
- Built for Flutter stable channel. Check
pubspec.yamlfor environment SDK constraints and dependency versions.
Classes
- XAppBar
- A highly configurable wrapper around Flutter's built-in AppBar, providing extended flexibility for common UI requirements.
-
XAsyncState<
T> - An immutable, state-management agnostic representation of asynchronous data.
-
XAsyncView<
T> - Renders initial, loading, data, empty, and error states consistently.
- XBottomSheet
- Consistent helpers for custom modal sheets and action sheets.
-
XBottomSheetAction<
T> - One selectable action displayed by XBottomSheet.actions.
- XBreakpoints
- Width thresholds used to select a responsive layout.
- XButton
- A customizable button supporting idle, loading, success, and error states, icons, custom content, rounded style, and native button configuration.
- XCard
- A customizable card container widget with padding, margin, background color, rounded corners, and shadow.
-
XCollectionView<
T> - A list or grid with the same fetch, refresh, pagination, and state API.
- XDebouncedSearchField
- A search text field with built-in debounce, clear, submit, and loading UI.
- XDiagonalStrikethroughText
- A text widget with a diagonal strikethrough line drawn across it.
- XDialog
- Consistent helpers for custom, alert, confirmation, and loading dialogs.
- XDoubleDashedLine
- A horizontal double-dashed divider line drawn using a custom painter.
- XHeight
- XResponsiveLayout
- Chooses mobile, tablet, or desktop content from the available width.
- XScreen
- A page scaffold with safe-area, keyboard dismissal, responsive padding, loading overlay, and error overlay support.
-
XScrollPage<
T> - A page returned by an XScrollFetcher.
- XScrollRequest
- Describes one data request made by XScrollView.
-
XScrollView<
T> - A reusable, paginated scroll view with first-load, refresh, and retry handling.
- XSingleDashedLine
- A horizontal single dashed line divider drawn using a custom painter.
- XSnackbar
-
A utility class for displaying styled snackbars at the top or bottom of the
screen. Works with
Overlayfor top-positioned snackbars and uses the native FlutterSnackBarfor bottom-positioned snackbars. - XSnackbarType
- Defines the color of the snackbar. Used internally by XSnackbar.
- XSpacer
- A simple spacer widget that provides vertical or horizontal spacing.
- XText
- A customizable text widget that supports an optional leading icon, underline decoration, tap handling, width limitation, and overflow control.
- XTextField
- A flexible text field widget supporting:
- XWidth
Enums
- XAsyncStatus
- Describes the lifecycle state rendered by XAsyncView.
- XButtonState
- Visual states supported directly by XButton.
- XCollectionLayout
- Collection layouts supported by XCollectionView.
- XDiagonalStrikethroughType
- Type of diagonal strikethrough line rendered over the text.
- XResponsiveSize
- Device-size categories used by XResponsiveLayout.
- XSnackbarPosition
- Determines where the snackbar will be displayed.
- XTextFieldType
- Defines supported field types for XTextField.
Functions
-
styleButtonRounded(
{double radius = 10, Color? background, Color? foreground, Color? borderColor, bool? isEnable = true, double elevation = 1, double paddingHorizontal = 12, double paddingVertical = 5, double borderWidth = 0}) → ButtonStyle - Creates a rounded ButtonStyle used by XButton.
Typedefs
-
XAsyncDataBuilder<
T> = Widget Function(BuildContext context, T data) - XAsyncErrorBuilder = Widget Function(BuildContext context, Object error, VoidCallback? retry)
- XResponsiveBuilder = Widget Function(BuildContext context, BoxConstraints constraints)
- XScreenErrorBuilder = Widget Function(BuildContext context, Object error, VoidCallback? retry)
- XScrollErrorBuilder = Widget Function(BuildContext context, Object error, VoidCallback retry)
-
XScrollFetcher<
T> = FutureOr< XScrollPage< Function(XScrollRequest request)T> > -
XScrollItemBuilder<
T> = Widget Function(BuildContext context, T item, int index) -
XScrollItemTap<
T> = void Function(T item, int index) - XScrollRefreshIndicatorBuilder = Widget Function(BuildContext context, double progress, bool isRefreshing)
-
XSearchCallback
= FutureOr<
void> Function(String query) - XSearchErrorCallback = void Function(Object error, StackTrace stackTrace)