brix_ui 1.2.1
brix_ui: ^1.2.1 copied to clipboard
Flutter widgets that follow your theme: buttons, text fields, select and search, cards, sheets, dialogs, toasts and a loader, in light and dark. Part of the brix family.
brix_ui #
Part of the brix family. Starting a new app?
brix create my_appfrom brix_cli sets this package up for you. Adding it to an app you already have? It brings the core, brix, with it.
Buttons, text fields, a select, cards, dialogs, sheets, toasts and a loader that look like your app. They take every colour, font and size from one theme, so switching to dark mode changes nothing in your screens.

What you get:
- Your look. Colours, font, corners, heights, texts and icons all come from
BrixTheme. Nothing is fixed in the widgets. - Light and dark from the start. Theme changes animate.
- The small logic is done. A loading button ignores extra taps, a dialog opens from a controller and tells you which button was tapped, a toast hides by itself.
- Dialogs you can read on any screen. They are a solid card on a dimmed background. If you like frosted glass, it is one setting.
- Any language. Every text the kit shows on its own can be replaced.
- Accessible. Touch targets are at least 44 points, labels are read with their fields and toasts are announced to screen readers.
- Light on dependencies. Only Flutter and brix, no state library and no font or sizing package.
Install #
flutter pub add brix_ui
Start #
import 'package:brix_ui/brix_ui.dart';
const brand = Color(0xFF1E7A4C);
MaterialApp(
navigatorKey: BrixUi.navigatorKey ??= GlobalKey(), // dialogs from anywhere
theme: BrixTheme.light(
colors: const BrixColors.light(primary: brand),
typography: BrixTypography(fontFamily: 'Inter'),
).toThemeData(),
darkTheme: BrixTheme.dark(
colors: const BrixColors.dark(primary: brand),
).toThemeData(),
themeMode: ThemeMode.system,
);
- Using GetX?
BrixUi.navigatorKey = Get.key; - Already have a
ThemeData? Add the tokens to it:ThemeData(extensions: [BrixTheme.light()]). - No theme at all? The widgets still work, with iOS-like defaults for the app's brightness.

Buttons #
BrixButton(label: 'Log in', isLoading: loading, onPressed: login)
BrixButton(label: 'Continue', gradient: true, onPressed: next)
BrixButton.outlined(label: 'Back', onPressed: back)
BrixButton.destructive(label: 'Delete account', icon: Icons.delete_outline, onPressed: delete)
- While loading it keeps its size and ignores taps, so a request is never sent twice.
onPressed: nulldisables it.- A light haptic and a small press scale (turn haptics off with
haptics: false). - Full width by default (forms);
expand: falsefits the label.

Text fields #
AutofillGroup(
child: Column(children: [
BrixTextField(
controller: email,
label: 'Email',
isRequired: true,
keyboardType: TextInputType.emailAddress,
autofillHints: const [AutofillHints.email],
textInputAction: TextInputAction.next,
),
BrixTextField(
controller: password,
label: 'Password',
isRequired: true,
isPassword: true,
autofillHints: const [AutofillHints.password],
onSubmitted: (_) => login(),
),
]),
)
- Required: a
*on the label; inside aForm, an empty check when you give novalidator. - Password: show / hide button, no autocorrect, the value is never trimmed.
- Keyboard: Next moves to the next field; Done or a tap outside closes the keyboard.
- Errors: your
validator, orerrorTextfrom outside (e.g. the backend's field error). - Read-only / disabled have their own look (a read-only field can open a picker on tap).

Dialogs #
BrixDialog.warning('Enter your email address.');
BrixDialog.error('No internet connection.');
final delete = await BrixDialog.show<bool>(
title: 'Delete this photo?',
message: 'This cannot be undone.',
icon: const BrixIcon(Icons.delete_outline),
buttons: const [
BrixDialogButton(label: 'Cancel', value: false),
BrixDialogButton.destructive(label: 'Delete', value: true),
],
);
warning/erroropen from anywhere (a controller too), stay on top while the screen underneath changes, and a new one replaces the open one.showreturns the tapped button's value. Two buttons sit side by side, more are stacked.- Long messages scroll; the screen below cannot be tapped.

Dialog, sheet or toast? #
- A dialog sits in the middle of the screen and asks one clear question: "Delete this photo?". The screen behind is dimmed until a button is tapped.
- A sheet slides up from the bottom and holds more: a list of choices, a short form, a few actions. People drag it down to close it.
- A toast is a short note that something worked. It hides by itself and never blocks the screen.
Sheets #
final folder = await BrixSheet.show<String>(
title: 'Move to',
builder: (context) => Column(children: [
ListTile(
title: const Text('Archive'),
onTap: () => BrixSheet.close(context, 'archive'),
),
ListTile(
title: const Text('Trash'),
onTap: () => BrixSheet.close(context, 'trash'),
),
]),
);
- It opens as tall as its content, or at half or full height with
height: BrixSheetHeight.half. - Drag it down or tap outside to close it;
dismissible: falsekeeps it open until your code closes it. showreturns the value you close it with, ornullwhen it was dragged away.

Select #
A dropdown that matches your text fields. Up to six options open in a menu under the field, more open in a sheet with a list.
BrixSelect<String>(
label: 'Country',
isRequired: true,
value: country,
options: const [
BrixOption(value: 'pk', label: 'Pakistan'),
BrixOption(value: 'gb', label: 'United Kingdom'),
],
onChanged: (value) => setState(() => country = value),
)
- It is typed:
BrixSelect<Country>gives you aCountryback. - Inside a
Form, a required select checks that something is chosen. mode: BrixSelectMode.menuor.sheetpicks the way it opens yourself.

Search #
Two ways to search, for short and long lists.
A select with a search box. searchable: true adds a search box on top of the options; the list narrows while typing. It always opens in a sheet.
BrixSelect<String>(label: 'Country', searchable: true, options: countries, onChanged: pick)
BrixSearchField: type and pick. A text field with suggestions under it. The options can be a list you have (filtered on the device) or come from your backend while typing:
BrixSearchField<City>(
label: 'City',
search: (text) => repository.searchCities(text), // or options: [...]
onSelected: (city) => setState(() => this.city = city),
onFreeText: (text) => setState(() => cityName = text),
)
- The backend is asked only after typing stops (300 ms,
debounce), a loader shows meanwhile, an older answer never replaces a newer one, and an error shows a short message instead of crashing. - With
onFreeText, text that matches no option can be used too: a Use "..." row appears, or the user presses done. What your app shows next (extra fields, a note) is up to you; brix shows nothing more. initialValuefills the field with a saved value (or pass your owncontroller). Required check, form validation,minLengthand the looks of the field (fieldStyle) and the list (style) work like the other widgets.- Works offline too when
searchreads throughBrixOfflineCachefrom brix_storage: the backend when online, the saved copy when not.

Cards #
A surface for your own content: the theme's colour, corners, a soft shadow and padding. What goes inside is yours.
BrixCard(child: Text('3 new orders today'))
BrixCard(
accentColor: context.brix.colors.success, // a strip on the leading edge, e.g. a status
onTap: () => open(order), // shrinks a little while held, light tap feel
child: OrderSummary(order),
)
- Like Flutter's
Cardit is as wide as its content. In aListViewor aColumn(crossAxisAlignment: CrossAxisAlignment.stretch)it takes the full width. - A tappable card is a button for screen readers;
semanticLabelgives it one short label. - Four levels to change it: the theme colours and
shape.radius, every card withBrixTheme(card: BrixCardStyle(...)), one card withstyle:, or a completely own card withcardBuilder(brix keeps the tap and the pressed state).

Toasts #
BrixToast.success('Profile saved');
BrixToast.success('We sent a code to ada@brix.dev', title: 'Check your email');
Slides in at the top, hides after 3 seconds (or on tap / swipe up), never blocks the screen, and screen readers announce it.

Text styles #
Every style your screens need, iOS sizes, from one theme. Colours come from the theme too, so they work in light and dark. Text grows with the user's text size setting, never with the screen width.
Text('Welcome', style: context.brix.typography.largeTitle)
Text('3 new orders', style: context.brix.typography.headline)
| Style | Size | Use |
|---|---|---|
largeTitle |
34 | the big title of a screen |
title1, title2, title3 |
28, 22, 20 | headings (title3 follows title) |
headline |
17, semibold | the main line of a row or card |
body, callout |
16 | running text, notes |
subheadline |
15 | the second line of a row |
footnote |
13 | small print |
caption, caption2 |
12, 11 | hints, time stamps |
label, button |
14, 16 | field labels and button text |
Change the font of all of them with BrixTypography(fontFamily: 'Inter'), or any one style: BrixTypography(headline: GoogleFonts.poppins(fontSize: 18)).

Responsive #
brix follows Flutter's adaptive layout advice: decide the layout from the room the window has, keep content readable, and never scale fonts with the screen.
final window = context.brixWindow; // compact, medium, expanded, large, extraLarge
if (window.isCompact) return const OnePane();
return const TwoPanes();
- Window size classes are the Material 3 ones: compact under 600, medium from 600, expanded from 840, large from 1200, extra large from 1600. Change them with
BrixBreakpoints(medium: 700)in the theme. BrixContentkeeps a form or a list readable: centred, at most 640 wide, with the page padding of the window (16 on phones, 24 on medium, 32 on wider windows).
Scaffold(body: BrixContent(child: LoginForm()))
- Spacing steps keep screens in line:
context.brix.spacing.s(8),m(12),l(16),xl(24) and more, changed in one place withBrixSpacing(...).
Make it yours #
Everything has a default. Change only what you need.
| What | How |
|---|---|
| Colours | BrixColors.light(primary: ..., background: ..., danger: ...) and BrixColors.dark(...) |
| Font and text sizes | BrixTypography(fontFamily: 'Inter'), or whole styles: BrixTypography(title: GoogleFonts.poppins(fontSize: 22)) |
| Corners and sizes | BrixShape(radius: 26, buttonHeight: 54, fieldHeight: 54, borderWidth: 1.5) |
| Texts (any language) | BrixUiTexts(ok: 'ٹھیک ہے', errorTitle: 'خرابی', requiredField: '...') |
| Icons (any set, SVG too) | BrixUiIcons(success: BrixIcon(CupertinoIcons.check_mark_circled), error: BrixIcon.custom(svg)) |
| Frosted glass dialogs and toasts | BrixTheme.light(glass: true) |
| Every button's look | BrixButtonStyle(radius: 40, height: 56, upperCase: true, gradient: true, pressedScale: 1, ...) |
| A completely own button | buttonBuilder: (context, button) => MyButton(...), brix keeps the logic |
| Every field's look | BrixTextFieldStyle(border: BrixFieldBorder.underline, labelInside: true, radius: 24, fillColor: ...) |
| A completely own field | textFieldBuilder: (context, field) => MyField(...), brix keeps the logic |
| Every dialog's place and look | BrixDialogStyle(alignment: Alignment.bottomCenter, transition: BrixDialogTransition.slideUp, maxWidth: 300, showIcon: false, buttonsVertical: true, ...) |
| A completely own dialog card | dialogBuilder: (context, dialog) => MyCard(...), brix keeps the dimmed screen and the returned value |
| Toast place, time and look | BrixToastStyle(position: BrixToastPosition.bottom, duration: Duration(seconds: 2), animationDuration: ..., ...), top, centre or bottom |
| A completely own toast | toastBuilder: (context, toast) => MyToast(...), brix keeps the timer and swiping |
| Sheets | BrixSheetStyle(radius: 16, showGrabber: false, backgroundColor: ...), or sheetBuilder: (context, sheet) => MySheet(...) |
| Select menus and sheets | BrixSelectStyle(menuRadius: 14, selectedColor: ...), or selectBuilder: (context, select) => MyPicker(...); the field follows your text field style |
| Cards | BrixCardStyle(radius: 20, padding: ..., shadow: [], borderWidth: 0, accentWidth: 6, pressedScale: 1, haptics: false), or cardBuilder: (context, card) => MyCard(...), brix keeps the tap and the pressed state |
| Spinner | BrixLoaderStyle(radius: 14, color: ...), or loaderBuilder: (context, loader) => MySpinner(...), loading buttons use it too |
| Button animation speed | BrixButtonStyle(pressDuration: ..., fadeDuration: ...) |
| Required marker and errors | BrixTextFieldStyle(requiredMarker: ' (required)', requiredMarkerStyle: ..., errorStyle: ..., errorMaxLines: 2) |
| Dimmed screen behind dialogs | BrixDialogStyle(scrimColor: ...), transparent to keep the screen as it is |
BrixTheme.light(
colors: const BrixColors.light(primary: Color(0xFF1E7A4C)),
shape: const BrixShape(radius: 26),
texts: const BrixUiTexts(ok: 'ٹھیک ہے'),
icons: BrixUiIcons(error: BrixIcon.custom(SvgPicture.asset('assets/error.svg'))),
)
Buttons your way #
Three levels: use the one you need:
// 1. Every button in the app.
BrixTheme.light(
button: const BrixButtonStyle(radius: 40, height: 56, upperCase: true, gradient: true),
)
// 2. One button.
BrixButton(label: 'Skip', style: const BrixButtonStyle(height: 40), onPressed: skip)
// 3. Your own widget. brix still blocks double taps, plays the haptic and
// disables it while loading.
BrixTheme.light(
buttonBuilder: (context, button) => MyButton(
label: button.label,
danger: button.variant == BrixButtonVariant.destructive,
busy: button.isLoading,
onTap: button.onPressed, // null while loading or disabled
),
)
Dialogs use your button too, so the whole app matches.

Text fields your way #
The same three levels:
// 1. Every field: outline (default), underline or none; label above or inside.
BrixTheme.light(
textField: const BrixTextFieldStyle(border: BrixFieldBorder.underline, labelInside: true),
)
// 2. One field.
BrixTextField(label: 'Notes', maxLines: 4, style: const BrixTextFieldStyle(radius: 20))
// 3. Your own widget. Pass brix's values to your TextFormField and the
// required check, password show / hide and Next / Done keep working.
BrixTheme.light(
textFieldBuilder: (context, field) => TextFormField(
controller: field.controller,
focusNode: field.focusNode,
validator: field.validator,
obscureText: field.obscureText,
textInputAction: field.textInputAction,
onEditingComplete: field.onEditingComplete,
onTapOutside: field.onTapOutside,
decoration: MyDecoration(label: field.label, onEye: field.toggleObscured),
),
)

Dialogs and toasts your way #
BrixTheme.light(
// Anywhere on the screen: centre (default), a bottom sheet, a top banner.
dialog: const BrixDialogStyle(
alignment: Alignment.bottomCenter,
transition: BrixDialogTransition.slideUp, // scale, fade, slideUp, slideDown
margin: EdgeInsets.all(12),
showIcon: false,
textAlign: TextAlign.start,
buttonsVertical: true,
),
toast: const BrixToastStyle(position: BrixToastPosition.bottom),
// Your own cards. brix still dims the screen, animates, returns the
// tapped value, runs the toast timer and handles swipes.
dialogBuilder: (context, dialog) => MyDialogCard(
title: dialog.title,
message: dialog.message,
actions: [
for (final button in dialog.buttons)
MyAction(button.label, onTap: () => dialog.onPressed(button.value)),
],
),
toastBuilder: (context, toast) => MySnack(toast.message, onUndo: toast.dismiss),
)
One dialog only: BrixDialog.show(style: ..., builder: ...).

Read the tokens in your own widgets too, so they match:
final brix = context.brix;
Text('Hello', style: brix.typography.body.copyWith(color: brix.colors.text));
With brix auth #
BrixUiFeedback is a ready brix AuthFeedback: failures and warnings as dialogs, success messages as a toast. No adapter to write:
LoginFlow(
provider: MyAuth(),
store: store,
navigator: MyNavigator(),
feedback: const BrixUiFeedback(),
)
When the backend sends no message (e.g. no connection), brix's default text is shown, so a dialog is never empty.
Example #
example/ shows every widget on one screen. Switch light and dark and three brands live; see example/lib/brands.dart for how each brand is set up.
Screenshots #
The images on this page are rendered from the real widgets by tool/screenshots_test.dart:
flutter test tool/screenshots_test.dart --update-goldens # widgets
More brix #
brix_ui is part of brix: auth, account, network, storage and GetX blocks that work together, each its own package.
MIT licensed.
The brix packages #
brix_ui is one part of brix. New app? Start with brix_cli. Existing app? Take only the packages you need; each brings the core with it.
| Package | Version | What it does |
|---|---|---|
| brix_cli | brix create my_app: a new app on every package below. Start here |
|
| brix_ui | Buttons, fields, select, sheets, dialogs, toasts, light and dark | |
| brix_getx | GetX controllers for every account screen | |
| brix_network | REST calls that return a Result |
|
| brix_storage | Values, secrets and a session store | |
| brix | The core every package builds on: flows, Result, Json, BrixLogger |
