Skip to content
Get started
Menu
Get started

KYC onboarding and consent

Explain what data the host collects and why before asking for consent. The consent box starts unchecked and Continue waits for it. The person then fills the host’s identity fields, reviews them with the ID number masked and saves. Saving details never verifies identity; the document photos come next.

List of requested data with the reason for each, a privacy policy link and a disabled Continue action until consent.List of requested data with the reason for each, a privacy policy link and a disabled Continue action until consent.
Purpose before consent
Identity form where the host rejected the ID number; the error sits under that field and the other values stay filled.
Host rejects a field
Review of name, masked ID number showing only its last four digits, birth date and occupation, with Edit and Save.
Review masked
Save failed banner above the unchanged review, with Save available again.
Save failed
Details saved, with a notice that identity is not verified yet and the next step is the ID photo and selfie.
Saved, not verified

From example/:

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

Check the consent box and continue, fill the synthetic form, review and save. The developer menu offers NIK ditolak host (the host rejects the ID number after a check; the person corrects only that field) and Simpan gagal (the first save fails and keeps the details). Changing a scenario starts a fresh synthetic session and ignores answers from the previous one.

KycOnboardingBlock takes a typed step, the host’s requirement list, field specs, values, server errors, an IdentityFormController and callbacks. The host records consent, runs its own field rules and saves the details. The form keeps what the person typed across host answers.

UI Existing library surface
Purpose list, consent and policy link VerificationIntro
Host fields, validation and server errors IdentityForm, IdentityFieldSpec, IdentityFormController
Steps, error slot and pinned action PaymentOnboardingView, PaymentTaskListItem
Saved state PaymentBanner

The block collects no PIN, OTP, password or document bytes. The host owns the privacy policy, consent records, retention, field rules and identity checks. All identities in the demo are fictional. See the verification pattern and the forms guide. Continue with the KYC capture block for the photos.

Source: compositions/kyc_onboarding_block.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';
enum KycOnboardingStep { consent, details, review, saved }
/// Copyable host composition: informed consent, identity details and a
/// review before the host saves them.
///
/// The consent box starts unchecked and Continue stays disabled until the
/// person checks it. Field rules belong to the host: [fields] carry their own
/// validators and [serverErrors] carries the host's answer after a save
/// attempt, while the form keeps what the person typed. Masked fields show
/// only their last four characters in review. Saving details never verifies
/// identity; the document photos come next. The block collects no PIN, OTP,
/// password or document bytes.
class KycOnboardingBlock extends StatelessWidget {
const KycOnboardingBlock({
super.key,
required this.step,
required this.requirements,
required this.fields,
required this.values,
required this.formController,
required this.onConsent,
required this.onOpenPolicy,
required this.onDetails,
required this.onEditDetails,
required this.onSave,
this.serverErrors = const {},
this.saving = false,
this.saveError,
this.savedAction,
});
final KycOnboardingStep step;
/// What the host collects and why, shown before consent.
final List<DataRequirement> requirements;
final List<IdentityFieldSpec> fields;
/// The person's details as last submitted from the form.
final Map<String, String> values;
final IdentityFormController formController;
/// The person checked consent and continued; the host records it.
final VoidCallback onConsent;
final VoidCallback onOpenPolicy;
/// The form passed the host rules on this device. The host may still
/// answer with [serverErrors].
final FutureOr<void> Function(Map<String, String> values) onDetails;
final VoidCallback onEditDetails;
final Future<void> Function() onSave;
/// Host field errors, keyed by field; the form shows them on its fields.
final Map<String, String> serverErrors;
final bool saving;
final String? saveError;
/// Quiet follow-up on the saved step, for example returning to the app.
final PaymentButton? savedAction;
List<PaymentTaskListItem> get _tasks {
PaymentTaskStatus at(int index) {
final current = step.index;
if (index < current) return PaymentTaskStatus.complete;
if (index == current) return PaymentTaskStatus.inProgress;
return PaymentTaskStatus.notStarted;
}
return [
PaymentTaskListItem(title: 'Persetujuan', status: at(0)),
PaymentTaskListItem(title: 'Data diri', status: at(1)),
PaymentTaskListItem(title: 'Tinjau data', status: at(2)),
// Photos belong to the capture block; saving details never finishes
// verification.
const PaymentTaskListItem(
title: 'Foto identitas',
status: PaymentTaskStatus.notStarted,
),
];
}
@override
Widget build(BuildContext context) {
final type = PaymentType.of(context);
return switch (step) {
KycOnboardingStep.consent => VerificationIntro(
requirements: requirements,
onContinue: onConsent,
onOpenPolicy: () {
onOpenPolicy();
},
consentLabel:
'Saya setuju data di atas diproses untuk verifikasi identitas.',
),
KycOnboardingStep.details => ListenableBuilder(
// The controller reports when the form is submitting.
listenable: formController,
builder: (context, form) => PaymentOnboardingView(
title: 'Data diri',
description: 'Isi sesuai KTP. Kami memeriksanya sebelum disimpan.',
tasks: _tasks,
primaryAction: PaymentButton(
label: 'Lanjutkan',
busy: formController.busy,
busyLabel: 'Memeriksa data…',
onPressed: formController.submit,
),
child: form!,
),
// The form keeps its state across host answers, so edits survive.
child: IdentityForm(
fields: fields,
initialValues: values,
serverErrors: serverErrors,
controller: formController,
onSubmit: onDetails,
),
),
KycOnboardingStep.review => PaymentOnboardingView(
title: 'Tinjau data',
tasks: _tasks,
error: saveError == null
? null
: PaymentBanner(
tone: StatusTone.danger,
icon: Icons.cloud_off_outlined,
title: 'Data belum tersimpan',
message: saveError,
),
primaryAction: PaymentButton(
label: 'Simpan data',
busy: saving,
busyLabel: 'Menyimpan…',
onPressed: onSave,
),
child: _DetailsReview(
fields: fields,
values: values,
onEdit: saving ? null : onEditDetails,
),
),
KycOnboardingStep.saved => PaymentOnboardingView(
title: 'Data diri tersimpan',
tasks: _tasks,
secondaryAction: savedAction,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const PaymentBanner(
tone: StatusTone.neutral,
icon: Icons.info_outline,
title: 'Identitas belum terverifikasi',
message:
'Langkah berikutnya: foto KTP dan swafoto. Verifikasi '
'dimulai setelah semua dokumen terkirim.',
),
SizedBox(
height: PaymentTheme.of(context).space(PaymentSpace.related),
),
Text(
'Anda dapat mengubah data ini sebelum mengirim verifikasi.',
style: type.caption,
),
],
),
),
};
}
}
class _DetailsReview extends StatelessWidget {
const _DetailsReview({
required this.fields,
required this.values,
required this.onEdit,
});
final List<IdentityFieldSpec> fields;
final Map<String, String> values;
final VoidCallback? onEdit;
String _display(BuildContext context, IdentityFieldSpec field) {
final value = values[field.key] ?? '';
if (field.maskInReview) return VerificationReview.mask(value);
return switch (field.kind) {
IdentityFieldKind.date => switch (DateTime.tryParse(value)) {
final date? => PaymentLocalizations.of(context).formatDate(date),
null => value,
},
IdentityFieldKind.choice || IdentityFieldKind.search =>
field.options.where((o) => o.value == value).firstOrNull?.label ??
value,
IdentityFieldKind.text => value,
};
}
@override
Widget build(BuildContext context) => PaymentSection(
title: 'Data diri',
trailing: onEdit == null
? null
: PaymentLink(
label: 'Ubah',
semanticLabel: 'Ubah data diri',
onPressed: onEdit,
),
child: PaymentPropertyList(
items: [
for (final field in fields)
PaymentPropertyListItem(
label: field.label,
valueText: _display(context, field),
),
],
),
);
}
Source: kyc_onboarding_demo.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:rakit_ui/rakit_ui.dart';
import 'block_demo_shell.dart';
import 'compositions/kyc_onboarding_block.dart';
void main() => runBlockDemo(const KycOnboardingDemo());
enum KycOnboardingScenario { fresh, hostRejectsId, saveFails }
/// Synthetic identity used by the prefilled scenarios. The demo host rejects
/// this ID number, so the person has to correct it.
const kycOnboardingRejectedId = '9999 0000 0000 2190';
const kycOnboardingPrefill = {
'name': 'Rina Contoh',
'nik': kycOnboardingRejectedId,
'dob': '1994-05-17',
'occupation': 'employee',
};
const kycOnboardingRequirements = [
DataRequirement(
title: 'Nama dan tanggal lahir',
purpose: 'Mencocokkan Anda dengan data kependudukan.',
),
DataRequirement(
title: 'Nomor KTP (NIK)',
purpose:
'Mencegah akun ganda. Hanya empat digit terakhir yang ditampilkan.',
),
DataRequirement(
title: 'Pekerjaan',
purpose: 'Diminta regulasi untuk menilai risiko transaksi.',
),
DataRequirement(
title: 'Foto KTP dan swafoto',
purpose:
'Memastikan pemilik KTP adalah Anda. Diambil di langkah berikutnya.',
),
];
/// Host identity rules. They run on the device; the host checks again when
/// it receives the details.
final kycOnboardingFields = [
IdentityFieldSpec(
key: 'name',
label: 'Nama lengkap sesuai KTP',
textCapitalization: TextCapitalization.words,
autofillHints: const [AutofillHints.name],
validator: (v) => v.runes.length < 2 ? 'Isi nama lengkap Anda.' : null,
),
IdentityFieldSpec(
key: 'nik',
label: 'NIK',
hint: '16 digit di KTP',
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[0-9 ]'))],
maskInReview: true,
validator: (v) => RegExp(r'^\d{16}$').hasMatch(v.replaceAll(' ', ''))
? null
: 'NIK terdiri dari 16 angka.',
),
IdentityFieldSpec(
key: 'dob',
label: 'Tanggal lahir',
kind: IdentityFieldKind.date,
firstDate: DateTime(1900),
lastDate: DateTime(2009, 12, 31),
validator: (v) => v.isEmpty ? 'Pilih tanggal lahir Anda.' : null,
),
const IdentityFieldSpec(
key: 'occupation',
label: 'Pekerjaan',
kind: IdentityFieldKind.choice,
options: [
PaymentSelectOption(value: 'employee', label: 'Karyawan'),
PaymentSelectOption(value: 'entrepreneur', label: 'Wiraswasta'),
PaymentSelectOption(value: 'student', label: 'Pelajar atau mahasiswa'),
PaymentSelectOption(value: 'other', label: 'Lainnya'),
],
validator: _required,
),
];
String? _required(String v) => v.isEmpty ? 'Pilih pekerjaan Anda.' : null;
/// Synthetic onboarding host. Consent, field checks and saving are declared
/// fixture answers; nothing leaves the device and no identity is verified.
class KycOnboardingDemo extends StatefulWidget {
const KycOnboardingDemo({
super.key,
this.initialScenario = KycOnboardingScenario.fresh,
this.initialStep = KycOnboardingStep.consent,
this.initialDark = false,
this.delay = const Duration(milliseconds: 500),
});
final KycOnboardingScenario initialScenario;
/// Starts past consent for captures; the person still saw consent first in
/// any real session.
final KycOnboardingStep initialStep;
final bool initialDark;
final Duration delay;
@override
State<KycOnboardingDemo> createState() => _KycOnboardingDemoState();
}
class _KycOnboardingDemoState extends State<KycOnboardingDemo> {
late bool dark = widget.initialDark;
late KycOnboardingScenario scenario = widget.initialScenario;
late KycOnboardingStep step = widget.initialStep;
late Map<String, String> values = prefill(scenario);
final form = IdentityFormController();
Map<String, String> serverErrors = const {};
bool saving = false;
String? saveError;
int saves = 0;
int generation = 0;
static Map<String, String> prefill(KycOnboardingScenario value) =>
value == KycOnboardingScenario.fresh ? const {} : kycOnboardingPrefill;
@override
void dispose() {
form.dispose();
super.dispose();
}
void reset(KycOnboardingScenario value) => setState(() {
generation++;
scenario = value;
step = KycOnboardingStep.consent;
values = prefill(value);
serverErrors = const {};
saving = false;
saveError = null;
saves = 0;
});
Future<void> details(Map<String, String> submitted) async {
final current = generation;
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
final id = submitted['nik']!.replaceAll(' ', '');
setState(() {
values = submitted;
if (scenario == KycOnboardingScenario.hostRejectsId &&
id == kycOnboardingRejectedId.replaceAll(' ', '')) {
serverErrors = const {
'nik': 'NIK ini tidak cocok dengan data kependudukan. Periksa lagi.',
};
return;
}
serverErrors = const {};
step = KycOnboardingStep.review;
});
}
Future<void> save() async {
if (saving) return;
final current = generation;
final count = ++saves;
setState(() {
saving = true;
saveError = null;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
saving = false;
if (scenario == KycOnboardingScenario.saveFails && count == 1) {
saveError =
'Periksa koneksi, lalu simpan lagi. Data Anda tetap di sini.';
return;
}
step = KycOnboardingStep.saved;
});
}
@override
Widget build(BuildContext context) => BlockDemoShell(
title: 'Verifikasi · Demo',
dark: dark,
onToggleDark: () => setState(() => dark = !dark),
scenarios: [
for (final (value, label) in [
(KycOnboardingScenario.fresh, 'Isi data baru'),
(KycOnboardingScenario.hostRejectsId, 'NIK ditolak host'),
(KycOnboardingScenario.saveFails, 'Simpan gagal'),
])
(label: label, onSelected: () => reset(value)),
],
body: (context) => KycOnboardingBlock(
key: ValueKey(generation),
step: step,
requirements: kycOnboardingRequirements,
fields: kycOnboardingFields,
values: values,
formController: form,
serverErrors: serverErrors,
saving: saving,
saveError: saveError,
onConsent: () => setState(() => step = KycOnboardingStep.details),
onOpenPolicy: () => showPaymentSheet<void>(
context: context,
builder: (sheet) => PaymentSheet(
header: PaymentSheetHeader(
title: 'Kebijakan privasi · Demo',
onClose: () => Navigator.pop(sheet),
),
body: const Text(
'Ringkasan contoh. Aplikasi Anda menampilkan kebijakan privasinya '
'sendiri: data apa yang disimpan, berapa lama, siapa yang dapat '
'mengaksesnya, dan cara menarik persetujuan.',
),
),
),
onDetails: details,
onEditDetails: () => setState(() => step = KycOnboardingStep.details),
onSave: save,
savedAction: PaymentButton(
label: 'Mulai ulang demo',
variant: PaymentButtonVariant.quiet,
onPressed: () => reset(scenario),
),
),
);
}
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 consent, field correction, masked review, failed-save recovery and a reachable Continue action at 320 dp with 200% text. Connect your own consent records, persistence and identity service. See Compatibility for device coverage.