Skip to content
Get started
Menu
Get started

Payment preferences

Choose a default payment method and payment notifications, then save. The block says “saved” only after the host confirms it. A failed save keeps the choices so the person can try again without choosing again. Choosing a default method only preselects it at checkout; it never charges or authorizes anything.

Default method radio list with an unavailable card and its reason, notification switches and a Save action.Default method radio list with an unavailable card and its reason, notification switches and a Save action.
Preferences
Save failed message under the title; the chosen Virtual account stays selected.
Save failed
Preferences saved message after the host confirmed the save.
Host-confirmed save

From example/:

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

Change the default method or a notification and tap Simpan. The developer menu’s Simpan pertama gagal scenario fails the first save; the choice stays and the next save is confirmed. Controls lock while the host saves.

PaymentPreferencesBlock takes the host’s last confirmed PaymentPreferences, the person’s draft, the methods, a confirmed flag and callbacks. It shows “unsaved changes” while the draft differs from the confirmed snapshot.

UI Existing library surface
Settings page, status line and Save PaymentSettingsView
Default method PaymentRadio, PaymentSection
Notifications and a locked security alert PaymentSwitch

The host owns persistence, the account’s methods, notification delivery and any sync with other devices. The block never shows “saved” optimistically. All methods are fictional. See the forms guide and the checkout pattern.

Source: compositions/payment_preferences_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';
/// The host's payment preferences. Choosing a default method only preselects
/// it at checkout; it never charges or authorizes anything.
@immutable
class PaymentPreferences {
const PaymentPreferences({
required this.defaultMethodId,
required this.receipts,
required this.reminders,
});
final String defaultMethodId;
final bool receipts;
final bool reminders;
PaymentPreferences copyWith({
String? defaultMethodId,
bool? receipts,
bool? reminders,
}) => PaymentPreferences(
defaultMethodId: defaultMethodId ?? this.defaultMethodId,
receipts: receipts ?? this.receipts,
reminders: reminders ?? this.reminders,
);
@override
bool operator ==(Object other) =>
other is PaymentPreferences &&
other.defaultMethodId == defaultMethodId &&
other.receipts == receipts &&
other.reminders == reminders;
@override
int get hashCode => Object.hash(defaultMethodId, receipts, reminders);
}
/// Copyable host composition: default payment method and payment
/// notifications with an explicit Save.
///
/// [saved] is the host's last confirmed snapshot and [draft] is what the
/// person has chosen since. The block says "saved" only when [confirmed] is
/// true and the draft equals the host's snapshot. A failed save keeps the
/// draft so the person can retry without choosing again. Controls are locked
/// while the host saves.
class PaymentPreferencesBlock extends StatelessWidget {
const PaymentPreferencesBlock({
super.key,
required this.methods,
required this.saved,
required this.draft,
required this.onChanged,
required this.onSave,
this.saving = false,
this.confirmed = false,
this.saveError,
});
/// Methods the host can make default; unavailable ones explain why.
final List<PaymentMethod> methods;
final PaymentPreferences saved;
final PaymentPreferences draft;
final ValueChanged<PaymentPreferences> onChanged;
final Future<void> Function() onSave;
final bool saving;
/// The host confirmed [saved] in this session.
final bool confirmed;
final String? saveError;
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
final dirty = draft != saved;
final (message, tone) = saving
? ('Menyimpan perubahan…', StatusTone.info)
: saveError != null
? ('Belum tersimpan. $saveError', StatusTone.danger)
: dirty
? ('Ada perubahan yang belum disimpan.', StatusTone.neutral)
: confirmed
? ('Preferensi tersimpan.', StatusTone.success)
: (null, StatusTone.neutral);
return PaymentSettingsView(
title: 'Preferensi pembayaran',
statusMessage: message,
statusTone: tone,
saveLabel: 'Simpan',
onSave: onSave,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.group),
children: [
PaymentSection(
title: 'Metode utama',
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
for (final method in methods)
PaymentRadio<String>(
value: method.id,
groupValue: draft.defaultMethodId,
label: method.label,
description: method.detail,
disabledReason: method.unavailableReason,
onChanged: saving || !method.isAvailable
? null
: (id) =>
onChanged(draft.copyWith(defaultMethodId: id)),
),
],
),
),
PaymentSection(
title: 'Notifikasi',
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
PaymentSwitch(
value: draft.receipts,
label: 'Struk pembayaran',
description: 'Dikirim ke email setelah pembayaran berhasil.',
onChanged: saving
? null
: (on) => onChanged(draft.copyWith(receipts: on)),
),
PaymentSwitch(
value: draft.reminders,
label: 'Pengingat tagihan',
description: 'Satu hari sebelum batas pembayaran.',
onChanged: saving
? null
: (on) => onChanged(draft.copyWith(reminders: on)),
),
const PaymentSwitch(
value: true,
label: 'Peringatan keamanan',
onChanged: null,
disabledReason: 'Selalu aktif untuk melindungi akun Anda.',
),
],
),
),
],
),
);
}
}
Source: payment_preferences_demo.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 'block_demo_shell.dart';
import 'compositions/payment_preferences_block.dart';
void main() => runBlockDemo(const PaymentPreferencesDemo());
enum PreferencesScenario { saves, firstSaveFails }
const preferenceMethods = [
PaymentMethod(
id: 'balance',
label: 'Saldo Ruang Bayar',
kind: PaymentMethodKind.balance,
detail: 'Saldo •••• 2190',
),
PaymentMethod(
id: 'va',
label: 'Virtual account',
kind: PaymentMethodKind.virtualAccount,
detail: 'Bank Demo',
),
PaymentMethod(
id: 'qris',
label: 'QRIS',
kind: PaymentMethodKind.eWallet,
detail: 'Bayar dengan aplikasi apa pun',
),
PaymentMethod(
id: 'card',
label: 'Kartu kredit',
kind: PaymentMethodKind.card,
unavailableReason: 'Tambahkan kartu dulu di Metode tersimpan.',
),
];
const preferencesSnapshot = PaymentPreferences(
defaultMethodId: 'balance',
receipts: true,
reminders: false,
);
/// Synthetic preferences host. Saving returns the host's stored copy after a
/// declared delay; nothing leaves the device.
class PaymentPreferencesDemo extends StatefulWidget {
const PaymentPreferencesDemo({
super.key,
this.initialScenario = PreferencesScenario.saves,
this.initialDark = false,
this.delay = const Duration(milliseconds: 600),
});
final PreferencesScenario initialScenario;
final bool initialDark;
final Duration delay;
@override
State<PaymentPreferencesDemo> createState() => _PaymentPreferencesDemoState();
}
class _PaymentPreferencesDemoState extends State<PaymentPreferencesDemo> {
late bool dark = widget.initialDark;
late PreferencesScenario scenario = widget.initialScenario;
PaymentPreferences saved = preferencesSnapshot;
PaymentPreferences draft = preferencesSnapshot;
bool saving = false;
bool confirmed = false;
String? saveError;
int saves = 0;
int generation = 0;
void reset(PreferencesScenario value) => setState(() {
generation++;
scenario = value;
saved = preferencesSnapshot;
draft = preferencesSnapshot;
saving = false;
confirmed = false;
saveError = null;
saves = 0;
});
Future<void> save() async {
// Nothing changed: there is nothing for the host to confirm.
if (saving || draft == saved) return;
final current = generation;
final count = ++saves;
final sent = draft;
setState(() {
saving = true;
saveError = null;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
saving = false;
if (scenario == PreferencesScenario.firstSaveFails && count == 1) {
saveError = 'Periksa koneksi, lalu simpan lagi.';
return;
}
// The host's stored copy is the truth; the draft follows it.
saved = sent;
draft = sent;
confirmed = true;
});
}
@override
Widget build(BuildContext context) => BlockDemoShell(
title: 'Pengaturan · Demo',
dark: dark,
onToggleDark: () => setState(() => dark = !dark),
scenarios: [
(
label: 'Simpan berhasil',
onSelected: () => reset(PreferencesScenario.saves),
),
(
label: 'Simpan pertama gagal',
onSelected: () => reset(PreferencesScenario.firstSaveFails),
),
],
body: (context) => PaymentPreferencesBlock(
key: ValueKey(generation),
methods: preferenceMethods,
saved: saved,
draft: draft,
saving: saving,
confirmed: confirmed,
saveError: saveError,
onChanged: (next) => setState(() {
draft = next;
saveError = null;
}),
onSave: save,
),
);
}
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)),
),
),
);
}

Widget tests cover failed-save recovery, confirmed save, locked controls while saving and a reachable Save action at 320 dp with 200% text. The demo keeps choices in memory; add account-scoped persistence in your host. See Compatibility for device coverage.