juxta_flutter
A lightweight Flutter library for expression-oriented widget composition. Inspired from my time with Clojure and re-frame.
juxta_flutter provides small, composable widgets for inline conditional rendering, nullable-aware branching,
collection-driven UI building, and widget threading. It is designed for Flutter developers who prefer concise,
readable building blocks over repeated if statements, temporary variables, and boilerplate-heavy widget trees.
Highlights
- Express UI branching as widgets instead of control-flow scaffolding
- Build nullable and value-driven UI inline
- Render collections with compact, reusable builder widgets
- Compose widget transformations fluently
- Keep build methods declarative and easy to scan
Features
Conditional widgets
Write UI branching logic in a compact, expression-friendly style.
IfIfNotCondCondpCondEqCondLetCondpValueCaseCaseLetIfPredGuard
Value binding and nullable helpers
Introduce values into widget subtrees without extra local structure.
LetIfSomeNullOrGuardLet
Collection and layout builders
Turn iterables and grouped data into widgets with less boilerplate.
ReduceMapIndexedKeepKeepIndexedInterposeFilterRemovePartitionSplitWithGroupByIntoFirstWhereJuxt
Widget threading and side-effect helpers
Transform, wrap, and inspect widgets inline.
PipeThreadTapDebugTap
Boolean branch helpers
Render branches from grouped boolean checks.
AnyOfAllOfNoneOf
Why juxta_flutter?
Flutter already gives you excellent primitives for composing UI. juxta_flutter complements them with a focused set of tiny widgets for code that is:
- more declarative
- easier to compose
- simpler to reuse
- less repetitive in
buildmethods - pleasant to read in nested widget trees
It is especially useful when you want UI logic to read like expressions instead of a mix of temporary variables, imperative branching, and list preparation.
Installation
Add the package to your pubspec.yaml:
dependencies:
juxta_flutter: ^1.0.0
Then fetch dependencies:
flutter pub get
Import
import 'package:juxta_flutter/juxta_flutter.dart';
Usage
Conditional widgets
import 'package:flutter/widgets.dart';
import 'package:juxta_flutter/juxta_flutter.dart';
class StatusLabel extends StatelessWidget {
const StatusLabel({
super.key,
required this.isLoading,
required this.hasError,
});
final bool isLoading;
final bool hasError;
@override
Widget build(BuildContext context) {
return Cond(
clauses: [
(isLoading, (_) => const Text('Loading...')),
(hasError, (_) => const Text('Something went wrong')),
],
orElse: (_) => const Text('Ready'),
);
}
}
Nullable-aware rendering
import 'package:flutter/widgets.dart';
import 'package:juxta_flutter/juxta_flutter.dart';
class Greeting extends StatelessWidget {
const Greeting({
super.key,
required this.displayName,
});
final String? displayName;
@override
Widget build(BuildContext context) {
return IfSome<String>(
value: displayName,
whenSome: (_, name) => Text('Hello, $name'),
orElse: (_) => const Text('Hello, guest'),
);
}
}
Inline value binding
import 'package:flutter/widgets.dart';
import 'package:juxta_flutter/juxta_flutter.dart';
class PriceTag extends StatelessWidget {
const PriceTag({
super.key,
required this.cents,
});
final int cents;
@override
Widget build(BuildContext context) {
return Let<String>(
value: '\$${(cents / 100).toStringAsFixed(2)}',
builder: (_, price) {
return Text(price);
},
);
}
}
Collection-driven UI
import 'package:flutter/widgets.dart';
import 'package:juxta_flutter/juxta_flutter.dart';
class FruitList extends StatelessWidget {
const FruitList({
super.key,
required this.items,
});
final List<String> items;
@override
Widget build(BuildContext context) {
return Interpose<String>(
items: items,
itemBuilder: (_, item) => Text(item),
separatorBuilder: (_, __) => const SizedBox(height: 8),
layoutBuilder: (_, children) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
);
},
);
}
}
Widget threading
import 'package:flutter/widgets.dart';
import 'package:juxta_flutter/juxta_flutter.dart';
class FramedLabel extends StatelessWidget {
const FramedLabel({super.key});
@override
Widget build(BuildContext context) {
return Thread(
child: const Text('juxta_flutter'),
transforms: [
(child) =>
Padding(
padding: const EdgeInsets.all(8),
child: child,
),
(child) => Center(child: child),
],
);
}
}
API overview
Conditionals
Use these widgets when you want branching logic to stay inline and expression-based:
Ifrenders one of two branches from a booleanIfNotrenders from the inverted boolean caseCondreturns the first matching conditional branchCondpmatches cases using custom logicCondEqmatches cases with==CondLetbranches on a non-null value using ordered predicatesCondpValuematches a value while exposing both the test and value to the builderCaserenders from exact value-to-builder mappingsCaseLetdoes the same for nullable valuesIfPredbranches by applying a predicate to a valueGuardreturns one widget only when a predicate passes
Bindings and nullable helpers
Use these widgets to introduce values into a subtree cleanly:
Letbinds a value into a local widget builderIfSomebuilds only when a nullable value is presentNullOrchooses between null and non-null branchesGuardLetbuilds from a non-null value only when an additional predicate passes
Boolean group builders
Use these when multiple booleans drive the same branch:
AnyOfbuilds when any test is trueAllOfbuilds when every test is trueNoneOfbuilds when all tests are false
Collection builders
Use these to keep iterable-to-widget transformations declarative:
Reducemaps items and passes the result to a layout builderMapIndexedmaps items with index accessKeepskips null-built childrenKeepIndexedskips null-built children while preserving index accessInterposeinserts separators between built childrenFilterincludes only matching itemsRemoveexcludes matching itemsPartitionsplits items into matched and unmatched groupsSplitWithsplits items at the first failed predicateGroupBygroups items by a computed keyIntofolds items into a widget listFirstWhererenders the first matching itemJuxtbuilds multiple sibling widgets from one shared value
Threading and side effects
Use these when you want transformations to remain fluent:
Pipeapplies a single widget transformThreadapplies multiple widget transforms in sequenceTapruns a lightweight side effect during build and returns the childDebugTapprints a value during build for inspection
When this package fits well
juxta_flutter is a good fit when your codebase benefits from:
- compact inline UI branching
- nullable-aware rendering without repeated null checks
- iterable-to-widget transformations staying inside the widget tree
- reusable layout patterns from collections and predicates
- cleaner build methods with fewer temporary variables
Libraries
- juxta_flutter
- A lightweight Flutter library for expression-oriented widget composition.