QRIS checkout
Show the buyer the exact amount, payee and expiry for one host-issued QRIS code. They can scan it with a payment app on another device, then use Check status to check the same attempt. When the code expires, it disappears; that doesn’t tell you whether the buyer paid.






Run and try
Section titled “Run and try”From example/, run:
flutter run -d <device-id> -t lib/qris_checkout_demo.dartOr open QRIS checkout in the example app’s Gallery. The standalone demo also has a theme toggle and a scenario menu. It uses a QR image that decodes to plain demo text, not a QRIS payment payload.
| Scenario | What happens |
|---|---|
| Kode aktif | Scan instructions are shown. Cek status gets a synthetic success for the same attempt. |
| Kode kedaluwarsa | Instructions hide the code, not the pending status. A later check can still confirm success. |
| Respons QRIS hilang | No code is offered until the same attempt is confirmed and the host supplies its image. |
| Cek status gagal | A failed check keeps the last known status and hides the code while the result can’t be refreshed. The next check uses the same attempt. |
Composition and boundaries
Section titled “Composition and boundaries”Copy QrisCheckoutBlock into a bounded screen body so Check status stays
reachable while the buyer scrolls. Pass the current PaymentAttempt, exact
Money amount, host clock and onCheckStatus(attemptId). Supply a QrisCode
with an image, payee and expiry issued for that attempt and amount. Keep the
image’s entire light quiet zone; don’t crop, stretch or tint it in dark mode.
Use a stable host issuanceId within the attempt and keep the expiry unchanged
for that code. A replacement code needs a new ID even if it shares the same
deadline. While the block is mounted, a clock correction or refresh won’t make
an already expired issuance scannable again. On remount, supply the current
valid code only.
The host issues the code and binds it to the amount. For provider-supported
same-phone payments, see the Wallet handoff block.
The QRIS block doesn’t generate codes, open other apps, poll or offer another
payment. Set Observation.refreshing during a check and use
PaymentAttempt.reconcile for provider replies. On failure set
Observation.unavailable and retain the last trusted snapshot. Code expiry is separate
from a provider-reported PaymentStatus.expired. Follow the
status and receipt pattern when deciding how an
attempt can be recovered or replaced elsewhere in the host.
Source
Section titled “Source”Source: compositions/qris_checkout_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';
/// Host-issued QRIS instructions tied to one payment attempt. The image must/// include the QR quiet zone and keep its original light background./// Keep `issuanceId` and `expiresAt` stable for the same code. A replacement/// code needs a new ID within the attempt, even if its expiry is unchanged.typedef QrisCode = ({ String attemptId, String issuanceId, String payee, ImageProvider image, DateTime expiresAt,});
/// Copyable host composition. It never issues a code, submits a payment or/// changes the business status. Only the host can reconcile the attempt.class QrisCheckoutBlock extends StatefulWidget { const QrisCheckoutBlock({ super.key, required this.attempt, required this.amount, required this.clock, required this.onCheckStatus, this.code, });
final PaymentAttempt attempt; final Money amount; final DateTime Function() clock; final Future<void> Function(String attemptId) onCheckStatus; final QrisCode? code;
@override State<QrisCheckoutBlock> createState() => _QrisCheckoutBlockState();}
class _QrisCheckoutBlockState extends State<QrisCheckoutBlock> { final _elapsedIssuances = <(String, String)>{};
DateTime _readClock(QrisCode code) { final now = widget.clock(); final issuance = (code.attemptId, code.issuanceId); if (!now.isBefore(code.expiresAt)) { _elapsedIssuances.add(issuance); return now; } // Expiry is one-way for this issuance, even if instructions unmount during // recovery or the host clock later moves backward. return _elapsedIssuances.contains(issuance) ? code.expiresAt : now; }
@override Widget build(BuildContext context) { final attempt = widget.attempt; final snapshot = attempt.snapshot; final qr = widget.code; final matchesAttempt = qr != null && qr.attemptId == attempt.attemptId; final elapsed = matchesAttempt && !_readClock(qr).isBefore(qr.expiresAt); final showInstructions = matchesAttempt && attempt.submission == SubmissionState.accepted && // Don't invite another scan while the host is checking or unreachable. attempt.observation == Observation.fresh && (attempt.status == PaymentStatus.pending || attempt.status == PaymentStatus.requiresAction);
// This view has only one supported action, even if a host snapshot also // permits recovery actions elsewhere. Never mutate or reconcile this copy. final statusAttempt = snapshot != null && snapshot.allowedActions.any((a) => a != PaymentAction.checkStatus) ? attempt.copyWith( snapshot: PaymentStatusSnapshot( attemptId: snapshot.attemptId, serverReference: snapshot.serverReference, status: snapshot.status, revision: snapshot.revision, updatedAt: snapshot.updatedAt, safeReason: snapshot.safeReason, refund: snapshot.refund, instructions: snapshot.instructions, isCorrection: snapshot.isCorrection, allowedActions: { if (snapshot.allowedActions.contains(PaymentAction.checkStatus)) PaymentAction.checkStatus, }, ), ) : attempt;
return PaymentStatusView( // A press or in-flight button must never survive an attempt change. key: ValueKey(attempt.attemptId), attempt: statusAttempt, amount: showInstructions ? null : widget.amount, header: showInstructions ? _QrisInstructions( key: ValueKey(qr.issuanceId), code: qr, amount: widget.amount, elapsed: elapsed, clock: () => _readClock(qr), onElapsed: () => setState(() {}), ) : null, onAction: (action) async { if (action == PaymentAction.checkStatus) { await widget.onCheckStatus(attempt.attemptId); } }, ); }}
class _QrisInstructions extends StatelessWidget { const _QrisInstructions({ super.key, required this.code, required this.amount, required this.elapsed, required this.clock, required this.onElapsed, });
final QrisCode code; final Money amount; final bool elapsed; final DateTime Function() clock; final VoidCallback onElapsed;
@override Widget build(BuildContext context) { final id = Localizations.localeOf(context).languageCode == 'id'; final theme = PaymentTheme.of(context); final l10n = PaymentLocalizations.of(context); final type = PaymentType.of(context); final expiresAt = l10n.formatDateTime(code.expiresAt.toLocal()); final gap = SizedBox(height: theme.space(PaymentSpace.related));
return Padding( padding: EdgeInsets.only(bottom: theme.space(PaymentSpace.group)), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Semantics( header: true, child: Text( id ? 'Pembayaran QRIS' : 'QRIS payment', style: type.heading, ), ), gap, Align( alignment: AlignmentDirectional.centerStart, child: AmountText(amount, variant: AmountTextVariant.display), ), gap, InfoRow(label: id ? 'Penerima' : 'Payee', valueText: code.payee), gap, Text( id ? 'Berlaku hingga $expiresAt' : 'Valid until $expiresAt', style: type.caption, ), if (elapsed) ...[ gap, PaymentBanner( tone: StatusTone.warning, title: id ? 'Kode QR kedaluwarsa' : 'QR code expired', message: id ? 'Cek status sebelum membayar lagi.' : 'Check status before paying again.', announce: true, ), ] else ...[ Wrap( spacing: theme.space(PaymentSpace.inline), crossAxisAlignment: WrapCrossAlignment.center, children: [ ExcludeSemantics( child: Text( id ? 'Sisa waktu' : 'Time left', style: type.caption, ), ), CountdownText( expiresAt: code.expiresAt, clock: clock, onElapsed: onElapsed, ), ], ), gap, Text( id ? 'Pindai dari perangkat lain.' : 'Scan from another device.', textAlign: TextAlign.center, style: type.bodyFor(context), ), SizedBox(height: theme.space(PaymentSpace.inline)), Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 192), child: AspectRatio( aspectRatio: 1, child: PaymentImage( image: code.image, alt: id ? 'Kode pembayaran QRIS' : 'QRIS payment code', fit: BoxFit.contain, errorFallback: Center( child: Text( id ? 'Kode QR tidak dapat ditampilkan.' : 'The QR code could not be displayed.', textAlign: TextAlign.center, style: type.bodyFor(context), ), ), ), ), ), ), ], ], ), ); }}Source: qris_checkout_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/qris_checkout_block.dart';
void main() => runBlockDemo(const QrisCheckoutDemo());
enum QrisDemoScenario { active, elapsed, unknown, checkOffline }
final qrisDemoStart = DateTime(2026, 11, 24, 10);final qrisDemoExpiry = qrisDemoStart.add(const Duration(minutes: 15));
/// A standalone example and the gallery's bounded specimen. The QR decodes/// to plain demo text, never payment data. Every status reply is a fixture.class QrisCheckoutDemo extends StatefulWidget { const QrisCheckoutDemo({ super.key, this.initialDark = false, this.embedded = false, this.clock, this.delay = const Duration(milliseconds: 600), });
final bool initialDark; final bool embedded; final DateTime Function()? clock; final Duration delay;
@override State<QrisCheckoutDemo> createState() => _QrisCheckoutDemoState();}
class _QrisCheckoutDemoState extends State<QrisCheckoutDemo> { static const _initialAttempt = PaymentAttempt( attemptId: 'QRIS-DEMO-359', quoteId: 'QUOTE-DEMO-359', quoteRevision: 1, methodId: 'qris', submission: SubmissionState.outcomeUnknown, );
late bool _dark = widget.initialDark; QrisDemoScenario _scenario = QrisDemoScenario.active; late DateTime _launched; late PaymentAttempt _attempt; int _session = 0; int _checks = 0;
@override void initState() { super.initState(); _reset(QrisDemoScenario.active); }
DateTime _now() { final start = _scenario == QrisDemoScenario.elapsed ? qrisDemoExpiry : qrisDemoStart; return widget.clock?.call() ?? start.add(DateTime.now().difference(_launched)); }
PaymentStatusSnapshot _reply(String id, PaymentStatus status, int revision) => PaymentStatusSnapshot( attemptId: id, serverReference: 'TX-DEMO-359', status: status, revision: revision, updatedAt: _now(), allowedActions: { if (status == PaymentStatus.pending) PaymentAction.checkStatus, }, );
void _reset(QrisDemoScenario scenario) { _scenario = scenario; _launched = DateTime.now(); _session++; _checks = 0; _attempt = _initialAttempt; if (scenario != QrisDemoScenario.unknown) { _attempt = _attempt .reconcile(_reply(_attempt.attemptId, PaymentStatus.pending, 1)) .attempt .copyWith(lastCheckedAt: _now()); } }
Future<void> _check(String attemptId) async { if (attemptId != _attempt.attemptId || _attempt.observation == Observation.refreshing) { return; } final session = _session; final checks = ++_checks; setState(() { _attempt = _attempt.copyWith(observation: Observation.refreshing); }); await Future<void>.delayed(widget.delay); if (!mounted || session != _session) return; setState(() { if (_scenario == QrisDemoScenario.checkOffline && checks == 1) { _attempt = _attempt.copyWith(observation: Observation.unavailable); return; } final status = _scenario == QrisDemoScenario.unknown && checks == 1 ? PaymentStatus.pending : PaymentStatus.succeeded; _attempt = _attempt .reconcile( _reply(attemptId, status, status == PaymentStatus.pending ? 1 : 2), ) .attempt .copyWith(lastCheckedAt: _now()); }); }
Widget _block(BuildContext context) { final id = Localizations.localeOf(context).languageCode == 'id'; return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Padding( padding: EdgeInsets.all( PaymentTheme.of(context).space(PaymentSpace.block), ), child: Text( id ? 'Kode demo · tidak untuk pembayaran' : 'Demo code · not for payment', textAlign: TextAlign.center, style: PaymentType.of(context).caption, ), ), Expanded( child: QrisCheckoutBlock( key: ValueKey(_session), attempt: _attempt, amount: const Money.idr(152500), clock: _now, code: _attempt.submission == SubmissionState.accepted ? ( attemptId: _attempt.attemptId, issuanceId: 'QRIS-DEMO-CODE-$_session', payee: 'Ruang Bayar Akademi', image: const AssetImage('assets/qris/demo-code.webp'), expiresAt: qrisDemoExpiry, ) : null, onCheckStatus: _check, ), ), ], ); }
@override Widget build(BuildContext context) => widget.embedded ? _block(context) : BlockDemoShell( title: 'QRIS · Demo', dark: _dark, onToggleDark: () => setState(() => _dark = !_dark), scenarios: [ for (final (scenario, label) in [ (QrisDemoScenario.active, 'Kode aktif'), (QrisDemoScenario.elapsed, 'Kode kedaluwarsa'), (QrisDemoScenario.unknown, 'Respons QRIS hilang'), (QrisDemoScenario.checkOffline, 'Cek status gagal'), ]) ( label: label, onSelected: () => setState(() => _reset(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)), ), ), );}Proof and limits
Section titled “Proof and limits”The example tests exercise code expiry, same-attempt checking, an unknown issuing response and failed status checks. The Android demo was checked in light and dark, including at 200% text. No provider, bank or live payment app is connected.