Skip to content
Get started
Menu
Get started

Collection

Use Collection for documents, OCR history, notes, or other records that need their own row layout. Import PaymentCollection when your host supplies the page controls and state content. Copy the Load more block when you want a ready-made append and retry example.

Give the collection finite width and height, for example in a Scaffold body or an Expanded child of a bounded Column. It already scrolls. For pull-to-refresh, wrap it in a RefreshIndicator and pass AlwaysScrollableScrollPhysics so short and empty pages can refresh too.

import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
Widget documentCollection({
required List<({String id, String title})> documents,
required Widget stateContent,
required Future<void> Function() refreshCurrentPage,
required double bottomClearance,
Widget? pager,
}) {
final indexByKey = {
for (final (index, document) in documents.indexed)
ValueKey(document.id): index,
};
return RefreshIndicator(
onRefresh: refreshCurrentPage,
child: PaymentCollection(
rowCount: documents.length,
rowBuilder: (context, index) {
final document = documents[index];
return Text(document.title, key: ValueKey(document.id));
},
findItemIndexCallback: (key) => indexByKey[key],
placeholder: stateContent,
footer: pager,
physics: const AlwaysScrollableScrollPhysics(),
padding: EdgeInsets.fromLTRB(16, 16, 16, bottomClearance),
maxContentWidth: 448,
),
);
}
  • Pass only the current page’s rows for numbered paging, or accumulated rows for append paging. The builder runs on demand; no record type is required.
  • If a refresh or sort can reorder mounted rows, key each row by its stable record ID and supply findItemIndexCallback. Return the row’s zero-based index in the new snapshot, excluding separators, or null if it was removed. Keep the collection mounted so row state can follow the key.
  • With zero rows, placeholder can show your branded loading, empty or error widget. With rows, the placeholder is ignored. Supply accessible labels and error announcements in your state widgets.
  • footer scrolls after either the rows or the placeholder. Leave Previous on an empty later page if the server allows it. Hide the pager when the host has no valid navigation targets, such as an initial load.
  • Use padding for host insets, including clearance for a floating bar. maxContentWidth caps the whole content column inside those insets. When padding is omitted, the viewport uses the theme’s group spacing.
  • Keep query, account and page identity in your app. Replace rows only with responses for the active request; discard stale successes and failures. Retry the failed page. To keep scroll offsets separate across pages or queries, give each identity a different PageStorageKey, or manage the offset with a host-owned scroll controller.

Open Page collection in Gallery, or from example/ run flutter run -d <device-id> -t lib/collection_page_demo.dart. The first Next fails once. Try again to open page 2, then go to the empty page 3 and use Previous or pull to refresh. See the runnable demo source for the host wiring.

PaymentCollection

class PaymentCollection extends StatelessWidget · lib/src/content/collection.dart

A bounded, lazy viewport for records with host-defined rows and states.

Supply either the current page's rows or accumulated rows. The collection does not fetch, select a state, or infer paging availability. Place it in a parent with finite width and height, not another vertical scroll view.

ParameterTypeDefaultDescription
rowCount:requiredint—Number of rows in the host's current snapshot.
rowBuilder:requiredIndexedWidgetBuilder—Builds visible and nearby rows by index, on demand.
findItemIndexCallback:ChildIndexGetter?—Looks up the current index of a key on a widget from rowBuilder.

For reordered rows, give each row a stable key and return its zero-based index in the current snapshot, not counting separators. Return null for a key that is no longer present. This lets mounted rows keep their state when their index changes.

placeholder:Widget?—Scrolling content shown only when rowCount is zero.

The host selects and labels its loading, empty or error content.

footer:Widget?—Optional content that scrolls after the rows or placeholder.

Also shown with zero rows, so an empty page can still offer a way back. With a footer, scroll semantics omit the indexed row count while keeping the footer available to assistive technologies.

controller:ScrollController?—Optional host-owned scroll controller. The host disposes it.
physics:ScrollPhysics?—Scroll physics. Use AlwaysScrollableScrollPhysics with a host refresh indicator to allow pull-to-refresh on short or empty pages.
padding:EdgeInsetsGeometry?—Scrollable insets, defaulting to PaymentSpace.group on all sides.
maxContentWidth:double?—Optional finite positive width cap for all content, excluding padding. Extra width is distributed equally beyond the specified side insets.
rowGap:PaymentSpacePaymentSpace.relatedSemantic spacing between adjacent rows.

From example/:

Terminal window
flutter run -d <device-id> -t lib/collection_block_demo.dart

Or open Collection in Gallery to try the sample document cards. In the standalone demo, the scenario menu can start with an empty list, return an empty next page, or fail the first or next page once. Use Load more and Retry to try paging and recovery. The demo uses synthetic data only.

Copy collection_block.dart and paged_block_footer.dart. Give the block a bounded viewport such as a Scaffold body. It already scrolls; do not nest it in another vertical scroll view. Pass the accumulated rowCount, a rowBuilder that reads your records by index, and the current pageState. Supply your localized labels and a StateMessage for the first empty page. Use the optional header for content that should scroll with the list.

Host state What the block shows
loading with no rows Initial skeleton
ready with no rows First-page empty copy, optionally with an action such as Upload PDF
moreAvailable Existing rows and Load more
loading with rows Existing rows and a busy Load more button
CollectionPageFailure Retry; with rows, the error stays beside them instead of replacing the list
laterEmpty Earlier rows and an end-of-list message, without a first-page action
ready with rows Completed collection, without a pager action

Bind onRequestPage to your host. Ignore repeated requests while one is pending. Keep the cursor and rows until the request succeeds; on failure, use safe display copy and a distinct attempt even if the message is unchanged. The block publishes the live error only when it enters the viewport and does not pull a reader back to a footer they have scrolled away from.

On a query or collection change, start a new request generation and discard old successes and failures. Give the block a PageStorageKey for the active generation if the new collection should start at the top. The demo treats an empty next page as terminal. If your backend can return empty intermediate pages with a valid next cursor, normalize them before passing a terminal state. Authorization, routing and data access stay in your app.

The sample card is a PaymentBox built by the host row builder, not a required row type. Use Rakit’s public theme to set the surface, spacing and typography, and use your own widgets for row actions. The copyable source is unchanged; it does not require PaymentCollection.

Source: compositions/collection_block.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
import 'paged_block_footer.dart';
sealed class CollectionPageState {
const CollectionPageState();
}
enum CollectionPageStatus implements CollectionPageState {
ready,
moreAvailable,
loading,
laterEmpty,
}
/// Display-safe copy and a fresh identity for each accepted failure.
final class CollectionPageFailure extends CollectionPageState {
const CollectionPageFailure({required this.message, required this.attempt});
final String message;
final int attempt;
}
/// A bounded, scrolling body. The host builds the accumulated rows and owns
/// the cursor, authorization, request ordering and all effects.
class CollectionBlock extends StatelessWidget {
const CollectionBlock({
super.key,
this.header,
required this.rowCount,
required this.rowBuilder,
required this.pageState,
required this.firstEmpty,
required this.laterEmptyMessage,
required this.errorTitle,
required this.loadMoreLabel,
required this.retryLabel,
required this.onRequestPage,
});
final Widget? header;
final int rowCount;
final IndexedWidgetBuilder rowBuilder;
final CollectionPageState pageState;
final StateMessage firstEmpty;
final String laterEmptyMessage;
final String errorTitle;
final String loadMoreLabel;
final String retryLabel;
/// Load the next page or retry the same failed request in the host.
final VoidCallback onRequestPage;
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
final type = PaymentType.of(context);
final group = theme.space(PaymentSpace.group);
final status = pageState;
final error = status is CollectionPageFailure ? status : null;
final loading = status == CollectionPageStatus.loading;
final empty = rowCount == 0;
final Widget? footer = switch (status) {
CollectionPageStatus.laterEmpty => StateMessage(
icon: Icons.inbox_outlined,
title: laterEmptyMessage,
),
CollectionPageStatus.moreAvailable ||
CollectionPageStatus.loading ||
CollectionPageFailure() when !empty => PagedBlockFooter(
label: error == null ? loadMoreLabel : retryLabel,
loading: loading,
error: error == null
? null
: (message: error.message, attempt: error.attempt),
onPressed: onRequestPage,
),
_ => null,
};
return CustomScrollView(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
semanticChildCount: rowCount,
slivers: [
SliverPadding(
padding: EdgeInsets.all(group),
sliver: SliverMainAxisGroup(
slivers: [
if (header case final header?) ...[
SliverToBoxAdapter(child: header),
SliverToBoxAdapter(child: SizedBox(height: group)),
],
if (!empty)
SliverList.separated(
itemCount: rowCount,
itemBuilder: rowBuilder,
separatorBuilder: (_, _) =>
SizedBox(height: theme.space(PaymentSpace.related)),
)
else if (status != CollectionPageStatus.laterEmpty)
SliverToBoxAdapter(
child: switch (status) {
CollectionPageStatus.loading => const LoadingSkeleton(
rows: 4,
leading: false,
),
CollectionPageFailure(:final message, :final attempt) =>
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: group),
child: VisibleBlockError(
key: ValueKey(attempt),
message: '$errorTitle\n$message',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: theme.space(PaymentSpace.inline),
children: [
Text(errorTitle, style: type.heading),
Text(
message,
style: type
.bodyFor(context)
.copyWith(color: theme.textSecondary),
),
],
),
),
),
PaymentButton(
label: retryLabel,
variant: PaymentButtonVariant.secondary,
onPressed: onRequestPage,
),
],
),
_ => firstEmpty,
},
),
if (footer != null)
SliverPadding(
padding: EdgeInsets.only(top: empty ? 0 : group),
sliver: SliverToBoxAdapter(child: footer),
),
],
),
),
],
);
}
}
Source: compositions/paged_block_footer.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:rakit_ui/rakit_ui.dart';
/// The host keeps the active page on failure and supplies a fresh attempt ID.
class PagedBlockFooter extends StatefulWidget {
const PagedBlockFooter({
super.key,
required this.label,
required this.loading,
required this.error,
required this.onPressed,
});
final String label;
final bool loading;
final ({String message, int attempt})? error;
final VoidCallback onPressed;
@override
State<PagedBlockFooter> createState() => _PagedBlockFooterState();
}
class _PagedBlockFooterState extends State<PagedBlockFooter> {
@override
void didUpdateWidget(PagedBlockFooter oldWidget) {
super.didUpdateWidget(oldWidget);
final attempt = widget.error?.attempt;
if (attempt == null || attempt == oldWidget.error?.attempt) return;
final footer = context.findRenderObject()! as RenderBox;
final viewport = RenderAbstractViewport.of(footer);
final position = Scrollable.of(context).position;
final offset = position.pixels;
final top = viewport.getOffsetToReveal(footer, 0).offset;
// Don't pull the reader back to the footer if they scrolled away.
if (position.isScrollingNotifier.value ||
top + footer.size.height <= offset ||
top >= offset + position.viewportDimension) {
return;
}
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted ||
widget.error?.attempt != attempt ||
!footer.attached ||
position.isScrollingNotifier.value ||
position.pixels != offset) {
return;
}
// When the message cannot fit with Retry, reveal the button first.
position.ensureVisible(
footer,
alignmentPolicy: footer.size.height > position.viewportDimension
? ScrollPositionAlignmentPolicy.explicit
: ScrollPositionAlignmentPolicy.keepVisibleAtEnd,
);
});
}
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.related),
children: [
PaymentButton(
label: widget.label,
variant: PaymentButtonVariant.secondary,
busy: widget.loading,
onPressed: widget.onPressed,
),
if (widget.error case (:final message, :final attempt))
VisibleBlockError(
key: ValueKey(attempt),
message: message,
child: Text(
message,
style: PaymentType.of(
context,
).bodyFor(context).copyWith(color: theme.textSecondary),
),
),
],
);
}
}
/// A keyed live region whose copy isn't announced while clipped offscreen.
class VisibleBlockError extends Semantics {
VisibleBlockError({super.key, required String message, required super.child})
: super(
container: true,
excludeSemantics: true,
liveRegion: true,
label: message,
);
@override
RenderSemanticsAnnotations createRenderObject(BuildContext context) =>
_RenderVisibleErrorSemantics(properties, Directionality.of(context));
}
class _RenderVisibleErrorSemantics extends RenderSemanticsAnnotations {
_RenderVisibleErrorSemantics(
SemanticsProperties properties,
TextDirection textDirection,
) : super(
properties: properties,
textDirection: textDirection,
container: true,
excludeSemantics: true,
);
@override
void assembleSemanticsNode(
SemanticsNode node,
SemanticsConfiguration config,
Iterable<SemanticsNode> children,
) {
// Flutter computes clipping before assembly. A scroll can supersede the
// reveal, so never publish a new label while the node is hidden.
if (config.isHidden) {
config = config.copy()..liveRegion = false;
if (node.label != config.label) config.label = '';
}
super.assembleSemanticsNode(node, config, children);
}
}
Source: collection_block_demo.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
import 'block_demo_shell.dart';
import 'compositions/collection_block.dart';
void main() => runBlockDemo(const CollectionBlockDemo());
enum CollectionDemoScenario {
ready,
firstEmpty,
firstError,
laterEmpty,
laterError,
}
typedef CollectionSample = ({String title, String detail});
typedef CollectionDemoPage = ({
List<CollectionSample> rows,
String? nextCursor,
});
typedef CollectionDemoSource =
Future<CollectionDemoPage> Function(String? cursor);
const _samples = <CollectionSample>[
(title: 'Workshop notes', detail: 'PDF · 6 pages'),
(title: 'Field guide', detail: 'PDF · 12 pages'),
(title: 'Reading list', detail: 'PDF · 3 pages'),
(title: 'Site sketches', detail: 'PDF · 4 pages'),
];
/// Synthetic host. The same composition can render notes, scans or documents.
class CollectionBlockDemo extends StatefulWidget {
const CollectionBlockDemo({
super.key,
this.embedded = false,
this.initialDark = false,
this.initialScenario = CollectionDemoScenario.ready,
this.fetchPage,
this.fixtureDelay = const Duration(milliseconds: 280),
});
final bool embedded;
final bool initialDark;
final CollectionDemoScenario initialScenario;
final CollectionDemoSource? fetchPage;
final Duration fixtureDelay;
@override
State<CollectionBlockDemo> createState() => _CollectionBlockDemoState();
}
class _CollectionBlockDemoState extends State<CollectionBlockDemo> {
late bool _dark = widget.initialDark;
late CollectionDemoScenario _scenario = widget.initialScenario;
List<CollectionSample> _rows = [];
String? _nextCursor;
CollectionPageState _pageState = CollectionPageStatus.loading;
int _generation = 0;
int _failureAttempt = 0;
@override
void initState() {
super.initState();
unawaited(_fetch(null));
}
void _restart(CollectionDemoScenario scenario) {
setState(() {
_scenario = scenario;
_generation++;
_rows = [];
_nextCursor = null;
_pageState = CollectionPageStatus.loading;
});
unawaited(_fetch(null));
}
void _requestPage() {
if (_pageState != CollectionPageStatus.moreAvailable &&
_pageState is! CollectionPageFailure) {
return;
}
setState(() => _pageState = CollectionPageStatus.loading);
unawaited(_fetch(_nextCursor));
}
Future<void> _fetch(String? cursor) async {
final generation = _generation;
try {
final page = await (widget.fetchPage ?? _fixturePage)(cursor);
if (!mounted || generation != _generation) return;
setState(() {
_rows = [..._rows, ...page.rows];
_nextCursor = page.rows.isEmpty ? null : page.nextCursor;
_pageState = switch ((cursor, page.rows.isEmpty, _nextCursor)) {
(_?, true, _) => CollectionPageStatus.laterEmpty,
(_, _, null) => CollectionPageStatus.ready,
_ => CollectionPageStatus.moreAvailable,
};
});
} catch (_) {
if (!mounted || generation != _generation) return;
setState(() {
_pageState = CollectionPageFailure(
message: cursor == null
? 'The collection couldn’t load. Try again.'
: 'The next page couldn’t load. Your earlier items are still here.',
attempt: ++_failureAttempt,
);
});
}
}
Future<CollectionDemoPage> _fixturePage(String? cursor) async {
final scenario = _scenario;
final fail = cursor == null
? scenario == CollectionDemoScenario.firstError
: scenario == CollectionDemoScenario.laterError;
if (fail) _scenario = CollectionDemoScenario.ready;
if (widget.fixtureDelay > Duration.zero) {
await Future<void>.delayed(widget.fixtureDelay);
}
if (fail) throw StateError('Synthetic page failure');
return switch ((cursor, scenario)) {
(null, CollectionDemoScenario.firstEmpty) ||
(
_?,
CollectionDemoScenario.laterEmpty,
) => (rows: const <CollectionSample>[], nextCursor: null),
(null, _) => (rows: _samples.take(2).toList(), nextCursor: 'more'),
_ => (rows: _samples.skip(2).toList(), nextCursor: null),
};
}
Widget _block(BuildContext context) => CollectionBlock(
key: PageStorageKey('collection-$_generation'),
header: Text('Documents', style: PaymentType.of(context).title),
rowCount: _rows.length,
rowBuilder: (context, index) {
final row = _rows[index];
final type = PaymentType.of(context);
return PaymentBox(
key: ValueKey(row.title),
padding: PaymentSpace.group,
gap: PaymentSpace.inline,
radius: PaymentRadius.box,
background: PaymentBoxBackground.surface,
keyline: PaymentKeyline.neutral,
children: [
Text(row.title, style: type.heading),
Text(row.detail, style: type.caption),
],
);
},
pageState: _pageState,
firstEmpty: StateMessage(
icon: Icons.folder_open_outlined,
title: 'No documents yet',
message: 'Add a document to start your collection.',
actionLabel: 'Add sample documents',
onAction: () => _restart(CollectionDemoScenario.ready),
),
laterEmptyMessage: 'No more documents on this page.',
errorTitle: 'Couldn’t load documents',
loadMoreLabel: 'Load more',
retryLabel: 'Retry',
onRequestPage: _requestPage,
);
@override
Widget build(BuildContext context) => widget.embedded
? _block(context)
: BlockDemoShell(
title: 'Collection demo',
dark: _dark,
onToggleDark: () => setState(() => _dark = !_dark),
scenarios: [
for (final (scenario, label) in [
(CollectionDemoScenario.ready, 'Documents available'),
(CollectionDemoScenario.firstEmpty, 'Empty first page'),
(CollectionDemoScenario.firstError, 'Fail first page once'),
(CollectionDemoScenario.laterEmpty, 'Empty next page'),
(CollectionDemoScenario.laterError, 'Fail next page once'),
])
(label: label, onSelected: () => _restart(scenario)),
],
body: _block,
);
}
Source: block_demo_shell.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:rakit_ui/rakit_ui.dart';
import 'themes.dart';
/// Starts a block demo edge-to-edge, as the shipped checkout demo does.
void runBlockDemo(Widget app) {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
runApp(app);
}
/// The example host's clipboard effect. It reports the real outcome and never
/// claims a copy that did not happen. The kit itself never touches the
/// clipboard (B11).
Future<bool> copyToClipboard(String value) async {
try {
await Clipboard.setData(ClipboardData(text: value));
return true;
} on PlatformException {
return false;
}
}
/// One developer scenario in the demo menu. Choosing it restarts the
/// synthetic session; it is never an end-user action.
typedef DemoScenario = ({String label, VoidCallback onSelected});
/// Ordinary phone host chrome shared by the block demos: app themes, Indonesian
/// localization, D85 system-bar styling, a light/dark switch and a developer
/// scenario menu. It is example scaffolding, not a block runtime: copy the
/// composition under `compositions/` and keep your own app shell.
class BlockDemoShell extends StatelessWidget {
const BlockDemoShell({
super.key,
required this.title,
required this.dark,
required this.onToggleDark,
required this.body,
this.scenarios = const [],
this.lightTheme,
this.darkTheme,
this.locale = const Locale('id'),
this.textScale,
});
final String title;
final bool dark;
final VoidCallback onToggleDark;
final List<DemoScenario> scenarios;
/// Optional illustrative host themes; the payment demos use Ruang Bayar.
final ThemeData? lightTheme;
final ThemeData? darkTheme;
/// Host locale for this synthetic demo.
final Locale locale;
/// Optional fixed text scale for accessibility captures; null follows the
/// device setting.
final double? textScale;
/// Built below the Scaffold, so sheets and toasts find their ancestors.
final WidgetBuilder body;
@override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
theme: lightTheme ?? buildTheme(DemoBrand.ruangBayar, Brightness.light),
darkTheme: darkTheme ?? buildTheme(DemoBrand.ruangBayar, Brightness.dark),
themeMode: dark ? ThemeMode.dark : ThemeMode.light,
locale: locale,
supportedLocales: const [Locale('id'), Locale('en')],
localizationsDelegates: const [
PaymentLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
builder: (context, child) {
final scale = textScale;
if (scale == null) return child!;
return MediaQuery(
data: MediaQuery.of(
context,
).copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
);
},
home: AnnotatedRegion<SystemUiOverlayStyle>(
// D85: the host styles the system bars from its resolved theme.
value: (dark ? SystemUiOverlayStyle.light : SystemUiOverlayStyle.dark)
.copyWith(
systemNavigationBarColor: Colors.transparent,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarContrastEnforced: false,
),
child: Scaffold(
appBar: AppBar(
title: Text(title),
actions: [
PaymentIconButton(
icon: dark ? Icons.light_mode_outlined : Icons.dark_mode_outlined,
tooltip: dark ? 'Mode terang' : 'Mode gelap',
onPressed: onToggleDark,
),
if (scenarios.isNotEmpty)
PopupMenuButton<int>(
tooltip: 'Skenario demo',
onSelected: (i) => scenarios[i].onSelected(),
itemBuilder: (_) => [
for (final (i, s) in scenarios.indexed)
PopupMenuItem(value: i, child: Text(s.label)),
],
),
],
),
body: SafeArea(top: false, child: Builder(builder: body)),
),
),
);
}
Source: themes.dart

Open this file on GitHub. Copy and adapt it in your host app.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:rakit_ui/rakit_ui.dart';
/// Three independent brands applied from outside the package, without forking.
enum DemoBrand { ruangBayar, lumen, soft }
ThemeData buildTheme(DemoBrand brand, Brightness brightness) {
final dark = brightness == Brightness.dark;
switch (brand) {
case DemoBrand.ruangBayar:
// "Hairline": white page, navy-black ink, rules instead of cards.
// Colors are contrast-checked in docs/design-research.md, section 0.
final ink = dark ? const Color(0xFFECEDF0) : const Color(0xFF1A1F36);
final surface = dark ? const Color(0xFF131417) : Colors.white;
final scheme = ColorScheme.fromSeed(
seedColor: const Color(0xFF1A1F36),
brightness: brightness,
dynamicSchemeVariant: DynamicSchemeVariant.monochrome,
primary: ink,
onPrimary: surface,
surface: surface,
onSurface: ink,
);
final payment = PaymentTheme.fromColorScheme(scheme).copyWith(
accent: ink,
onAccent: surface,
surface: surface,
surfaceMuted: dark ? const Color(0xFF1C1E23) : const Color(0xFFF5F6F8),
outline: dark ? const Color(0xFF2C2E35) : const Color(0xFFE3E6EC),
textPrimary: ink,
textSecondary: dark ? const Color(0xFFA2A8B5) : const Color(0xFF5E6678),
// Control edge 3.37:1 light, 4.85:1 dark; disabled labels stay above
// 2:1 on the muted fill.
border: dark ? const Color(0xFF7E838E) : const Color(0xFF868C9A),
disabled: dark ? const Color(0xFF62656E) : const Color(0xFFA6ABB5),
);
return _base(scheme, payment, background: surface);
case DemoBrand.lumen:
// "Contrast": pure black and white and heavier amounts, with the same
// corners as Hairline (radius 8).
final ink = dark ? Colors.white : Colors.black;
final surface = dark ? const Color(0xFF0F0F0F) : Colors.white;
final scheme = ColorScheme.fromSeed(
seedColor: Colors.black,
brightness: brightness,
dynamicSchemeVariant: DynamicSchemeVariant.monochrome,
primary: ink,
onPrimary: surface,
surface: surface,
onSurface: ink,
);
final payment = PaymentTheme.fromColorScheme(scheme).copyWith(
accent: ink,
onAccent: surface,
surface: surface,
surfaceMuted: dark ? const Color(0xFF1F1F1F) : const Color(0xFFF3F3F3),
outline: dark ? const Color(0xFF333333) : const Color(0xFFE8E8E8),
textPrimary: ink,
textSecondary: dark ? const Color(0xFFB3B3B3) : const Color(0xFF545454),
radius: 8,
amountWeight: FontWeight.w700,
);
return _base(scheme, payment, background: surface);
case DemoBrand.soft:
// "Soft": a tinted page with white inset panels, an indigo accent,
// rounder corners and a lighter amount. Tokens only; the panels are
// host styling (SoftInsetPanel). Contrast on the tinted page: body
// text 14.3:1, secondary 5.6:1, accent 6.3:1, control edge 3.5:1,
// status tones at least 5.6:1 (docs/design-research.md, section 9).
final page = dark ? const Color(0xFF0E0F13) : const Color(0xFFF1F2F6);
final surface = dark ? const Color(0xFF18191E) : Colors.white;
final ink = dark ? const Color(0xFFECEDF1) : const Color(0xFF1C2133);
final accent = dark ? const Color(0xFFAEB7FF) : const Color(0xFF3D4AC4);
final onAccent = dark ? page : Colors.white;
final scheme = ColorScheme.fromSeed(
seedColor: const Color(0xFF3D4AC4),
brightness: brightness,
primary: accent,
onPrimary: onAccent,
surface: surface,
onSurface: ink,
);
final payment = PaymentTheme.fromColorScheme(scheme).copyWith(
accent: accent,
onAccent: onAccent,
surface: surface,
surfaceMuted: dark ? const Color(0xFF212329) : const Color(0xFFF4F5F9),
outline: dark ? const Color(0xFF2E3038) : const Color(0xFFE2E4EB),
textPrimary: ink,
textSecondary: dark ? const Color(0xFFA4AAB7) : const Color(0xFF586074),
border: dark ? const Color(0xFF7F8592) : const Color(0xFF7A8090),
disabled: dark ? const Color(0xFF62656E) : const Color(0xFFA3A8B4),
// D101 radius roles: 8 tags, 12 controls, 16 boxes, 20 sheets.
radius: 16,
controlRadius: 12,
sheetRadius: 20,
amountWeight: FontWeight.w500,
);
// D102: fields stay white on the tinted page.
return _base(
scheme,
payment,
background: page,
field: PaymentFieldTheme(fillColor: surface),
);
}
}
ThemeData _base(
ColorScheme scheme,
PaymentTheme payment, {
required Color background,
PaymentFieldTheme? field,
}) {
final controlRadius = payment.controlBorderRadius;
return ThemeData(
colorScheme: scheme,
useMaterial3: true,
splashFactory: switch (defaultTargetPlatform) {
TargetPlatform.iOS => NoSplash.splashFactory,
TargetPlatform.android when !kIsWeb => InkSparkle.splashFactory,
_ => null,
},
scaffoldBackgroundColor: background,
extensions: [payment, ?field],
dividerTheme: DividerThemeData(color: payment.outline, space: 1),
appBarTheme: AppBarTheme(
backgroundColor: background,
foregroundColor: payment.textPrimary,
surfaceTintColor: Colors.transparent,
scrolledUnderElevation: 0,
centerTitle: false,
titleTextStyle: TextStyle(
fontSize: 17,
height: 24 / 17,
letterSpacing: 0,
fontWeight: FontWeight.w600,
color: payment.textPrimary,
),
shape: Border(bottom: BorderSide(color: payment.outline)),
),
// Demo/Scenarios/Gallery switcher: a plain bar with a hairline, the
// selected destination in ink, no tonal pill.
navigationBarTheme: NavigationBarThemeData(
backgroundColor: background,
surfaceTintColor: Colors.transparent,
indicatorColor: Colors.transparent,
height: 64,
iconTheme: WidgetStateProperty.resolveWith(
(states) => IconThemeData(
size: 24,
color: states.contains(WidgetState.selected)
? payment.textPrimary
: payment.textSecondary,
),
),
labelTextStyle: WidgetStateProperty.resolveWith(
(states) => TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: states.contains(WidgetState.selected)
? payment.textPrimary
: payment.textSecondary,
),
),
),
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: controlRadius),
),
dialogTheme: DialogThemeData(
backgroundColor: payment.surface,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(borderRadius: payment.sheetBorderRadius),
),
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: payment.surface,
surfaceTintColor: Colors.transparent,
),
popupMenuTheme: PopupMenuThemeData(
color: payment.surface,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: controlRadius,
side: BorderSide(color: payment.outline),
),
),
// Plain Material buttons in example screens match PaymentButton: 6 px
// corners, ink outline, no pill.
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: controlRadius),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: payment.textPrimary,
side: BorderSide(color: payment.border),
shape: RoundedRectangleBorder(borderRadius: controlRadius),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: payment.textPrimary,
shape: RoundedRectangleBorder(borderRadius: controlRadius),
),
),
// Chips in example screens (sheet filters, the scenario picker): small
// corners, no check mark, selection shown by an ink outline.
chipTheme: ChipThemeData(
showCheckmark: false,
backgroundColor: payment.surface,
selectedColor: payment.surfaceMuted,
side: WidgetStateBorderSide.resolveWith(
(states) => BorderSide(
color: states.contains(WidgetState.selected)
? payment.accent
: payment.outline,
),
),
shape: RoundedRectangleBorder(borderRadius: controlRadius),
labelStyle: TextStyle(fontSize: 14, color: payment.textPrimary),
),
checkboxTheme: CheckboxThemeData(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: payment.surface,
border: OutlineInputBorder(
borderRadius: controlRadius,
borderSide: BorderSide(color: payment.textSecondary),
),
enabledBorder: OutlineInputBorder(
borderRadius: controlRadius,
borderSide: BorderSide(color: payment.border),
),
focusedBorder: OutlineInputBorder(
borderRadius: controlRadius,
borderSide: BorderSide(color: payment.accent, width: 2),
),
),
);
}

See Transaction history for a domain-specific example using the same pager.