Skip to main content

juxta_flutter 1.0.0 copy "juxta_flutter: ^1.0.0" to clipboard
juxta_flutter: ^1.0.0 copied to clipboard

A lightweight Flutter library for expression-oriented widget composition.

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.

  • If
  • IfNot
  • Cond
  • Condp
  • CondEq
  • CondLet
  • CondpValue
  • Case
  • CaseLet
  • IfPred
  • Guard

Value binding and nullable helpers #

Introduce values into widget subtrees without extra local structure.

  • Let
  • IfSome
  • NullOr
  • GuardLet

Collection and layout builders #

Turn iterables and grouped data into widgets with less boilerplate.

  • Reduce
  • MapIndexed
  • Keep
  • KeepIndexed
  • Interpose
  • Filter
  • Remove
  • Partition
  • SplitWith
  • GroupBy
  • Into
  • FirstWhere
  • Juxt

Widget threading and side-effect helpers #

Transform, wrap, and inspect widgets inline.

  • Pipe
  • Thread
  • Tap
  • DebugTap

Boolean branch helpers #

Render branches from grouped boolean checks.

  • AnyOf
  • AllOf
  • NoneOf

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 build methods
  • 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:

  • If renders one of two branches from a boolean
  • IfNot renders from the inverted boolean case
  • Cond returns the first matching conditional branch
  • Condp matches cases using custom logic
  • CondEq matches cases with ==
  • CondLet branches on a non-null value using ordered predicates
  • CondpValue matches a value while exposing both the test and value to the builder
  • Case renders from exact value-to-builder mappings
  • CaseLet does the same for nullable values
  • IfPred branches by applying a predicate to a value
  • Guard returns one widget only when a predicate passes

Bindings and nullable helpers #

Use these widgets to introduce values into a subtree cleanly:

  • Let binds a value into a local widget builder
  • IfSome builds only when a nullable value is present
  • NullOr chooses between null and non-null branches
  • GuardLet builds from a non-null value only when an additional predicate passes

Boolean group builders #

Use these when multiple booleans drive the same branch:

  • AnyOf builds when any test is true
  • AllOf builds when every test is true
  • NoneOf builds when all tests are false

Collection builders #

Use these to keep iterable-to-widget transformations declarative:

  • Reduce maps items and passes the result to a layout builder
  • MapIndexed maps items with index access
  • Keep skips null-built children
  • KeepIndexed skips null-built children while preserving index access
  • Interpose inserts separators between built children
  • Filter includes only matching items
  • Remove excludes matching items
  • Partition splits items into matched and unmatched groups
  • SplitWith splits items at the first failed predicate
  • GroupBy groups items by a computed key
  • Into folds items into a widget list
  • FirstWhere renders the first matching item
  • Juxt builds multiple sibling widgets from one shared value

Threading and side effects #

Use these when you want transformations to remain fluent:

  • Pipe applies a single widget transform
  • Thread applies multiple widget transforms in sequence
  • Tap runs a lightweight side effect during build and returns the child
  • DebugTap prints 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
0
likes
150
points
13
downloads

Documentation

API reference

Publisher

verified publisheraxrs.dev

Weekly Downloads

A lightweight Flutter library for expression-oriented widget composition.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on juxta_flutter