Skip to content
Get started
Menu
Get started

Login

Use this general-purpose Authentication block when a host already owns its identity backend. It validates the email and password locally, keeps the password in host-owned input with a show/hide action, reports a safe host failure, and leaves authentication, recovery and navigation to the host.

Login screen with email and password fields, a show password action, Log in pinned at the bottom, Forgot password and Create account.Login screen with email and password fields, a show password action, Log in pinned at the bottom, Forgot password and Create account.
Login, light and dark
Login screen with a danger banner saying the host could not log the person in; the entered email and hidden password remain editable.
Host failure remains recoverable
Login screen at 200 percent text with the Log in and Forgot password actions still reachable.
200% text

From example/:

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

The connected demo uses an Annota-derived illustrative host theme and synthetic fixtures only. It is not Annota’s production authentication flow: nothing leaves the device, no account is created or stored, and no secret is logged. Use mina@example.com / notes123. The default scenario makes the first sign-in fail so the recovery path is visible; the second succeeds and the host navigates Home. The developer menu also starts the registration scenarios.

LoginBlock is self-contained apart from the package. LoginCredentials is the only value passed across the authentication boundary. The host supplies onSubmit, onForgotPassword, onRegister, busy and a safe errorText. The block never authenticates, stores, transmits or logs a credential.

UI Existing library surface
Phone and wide page layout, title navigation and pinned action PaymentFullPageView
Email input and validation error presentation PaymentTextField
Submit and recovery action states PaymentButton
Host failure announcement PaymentBanner
Registration navigation PaymentLink

The password control is deliberately host code inside the copied file. The kit does not accept secrets or provide a password-input mode (D1a); the host owns secret input, credential handling, rate limits, recovery and routing. Continue with Register for account creation and host-required verification.

Source: compositions/login_block.dart

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

import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:rakit_ui/rakit_ui.dart';
/// Credentials sent to the host when the form is valid.
@immutable
class LoginCredentials {
const LoginCredentials({required this.email, required this.password});
final String email;
final String password;
}
/// Copyable host composition: email/password login with local validation,
/// show/hide password, host failure, recovery and registration navigation.
///
/// The block never authenticates, stores or transmits credentials. [onSubmit]
/// is the host's authentication boundary; the host also owns recovery and
/// routing through [onForgotPassword] and [onRegister]. [busy] and
/// [errorText] describe the host's current attempt.
class LoginBlock extends StatefulWidget {
const LoginBlock({
super.key,
required this.onSubmit,
required this.onForgotPassword,
required this.onRegister,
this.initialEmail = '',
this.busy = false,
this.errorText,
});
final Future<void> Function(LoginCredentials credentials) onSubmit;
final VoidCallback onForgotPassword;
final VoidCallback onRegister;
final String initialEmail;
final bool busy;
/// Safe host message for the failed attempt. Never include the password.
final String? errorText;
@override
State<LoginBlock> createState() => _LoginBlockState();
}
class _LoginBlockState extends State<LoginBlock> {
final _formKey = GlobalKey<FormState>();
late final TextEditingController _email;
late final TextEditingController _password;
@override
void initState() {
super.initState();
_email = TextEditingController(text: widget.initialEmail);
_password = TextEditingController();
}
@override
void dispose() {
_email.dispose();
_password.dispose();
super.dispose();
}
String? _validateEmail(String? value) {
final email = value?.trim() ?? '';
if (email.isEmpty) return 'Enter your email address.';
final valid = RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$').hasMatch(email);
return valid ? null : 'Enter a valid email address.';
}
String? _validatePassword(String? value) =>
(value ?? '').isEmpty ? 'Enter your password.' : null;
void _submit() {
FocusScope.of(context).unfocus();
if (!(_formKey.currentState?.validate() ?? false)) return;
widget.onSubmit(
LoginCredentials(email: _email.text.trim(), password: _password.text),
);
}
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
return PaymentFullPageView(
title: 'Log in',
pageLink: PaymentLink(
label: 'Create account',
onPressed: widget.busy ? null : widget.onRegister,
),
primaryAction: PaymentButton(
label: 'Log in',
busy: widget.busy,
busyLabel: 'Signing you in',
onPressed: widget.busy ? null : _submit,
),
secondaryAction: PaymentButton(
label: 'Forgot password?',
variant: PaymentButtonVariant.quiet,
onPressed: widget.busy ? null : widget.onForgotPassword,
),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.group),
children: [
if (widget.errorText != null)
PaymentBanner(
tone: StatusTone.danger,
title: 'Couldn’t log you in',
message: widget.errorText,
announce: true,
),
PaymentTextField(
label: 'Email address',
controller: _email,
type: PaymentTextFieldType.email,
required: true,
enabled: !widget.busy,
validator: _validateEmail,
textInputAction: TextInputAction.next,
autofillHints: const [AutofillHints.username],
),
LoginPasswordField(
label: 'Password',
controller: _password,
enabled: !widget.busy,
validator: _validatePassword,
autofillHint: AutofillHints.password,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _submit(),
),
],
),
),
);
}
}
/// Host-owned password input. The kit deliberately has no secret-input mode;
/// a copied block keeps this control in host code.
class LoginPasswordField extends StatefulWidget {
const LoginPasswordField({
super.key,
required this.label,
required this.controller,
this.enabled = true,
this.validator,
this.errorText,
this.autofillHint = AutofillHints.password,
this.textInputAction,
this.onSubmitted,
});
final String label;
final TextEditingController controller;
final bool enabled;
final FormFieldValidator<String>? validator;
final String? errorText;
final String autofillHint;
final TextInputAction? textInputAction;
final ValueChanged<String>? onSubmitted;
@override
State<LoginPasswordField> createState() => _LoginPasswordFieldState();
}
class _LoginPasswordFieldState extends State<LoginPasswordField> {
bool _obscured = true;
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
final type = PaymentType.of(context);
final labelAbove = PaymentType.isLarge(context);
final border = OutlineInputBorder(
borderRadius: theme.controlBorderRadius,
borderSide: BorderSide(color: theme.border),
);
final errorBorder = OutlineInputBorder(
borderRadius: theme.controlBorderRadius,
borderSide: BorderSide(color: theme.danger.foreground),
);
return Semantics(
label: labelAbove ? widget.label : null,
isRequired: true,
validationResult: widget.errorText == null
? SemanticsValidationResult.none
: SemanticsValidationResult.invalid,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.inline),
children: [
if (labelAbove)
ExcludeSemantics(
child: Text(
widget.label,
style: type.label.copyWith(
color: widget.enabled ? theme.textSecondary : theme.disabled,
),
),
),
TextFormField(
controller: widget.controller,
enabled: widget.enabled,
obscureText: _obscured,
autocorrect: false,
enableSuggestions: false,
keyboardType: TextInputType.visiblePassword,
autofillHints: [widget.autofillHint],
textInputAction: widget.textInputAction,
onFieldSubmitted: widget.onSubmitted,
validator: widget.validator,
forceErrorText: widget.errorText,
style: type.input.copyWith(
color: widget.enabled ? theme.textPrimary : theme.disabled,
),
decoration: InputDecoration(
labelText: labelAbove ? null : widget.label,
labelStyle: type.label.copyWith(
color: widget.enabled ? theme.textSecondary : theme.disabled,
),
filled: true,
fillColor: theme.surface,
contentPadding: labelAbove
? EdgeInsetsDirectional.symmetric(
horizontal: theme.space(PaymentSpace.group) - 4,
vertical: theme.space(PaymentSpace.group),
)
: EdgeInsetsDirectional.fromSTEB(
theme.space(PaymentSpace.group) - 4,
theme.space(PaymentSpace.group) +
theme.space(PaymentSpace.inline),
theme.space(PaymentSpace.group) - 4,
theme.space(PaymentSpace.block),
),
enabledBorder: border,
disabledBorder: border.copyWith(
borderSide: BorderSide(color: theme.outline),
),
focusedBorder: border.copyWith(
borderSide: BorderSide(color: theme.accent, width: 2),
),
errorBorder: errorBorder,
focusedErrorBorder: errorBorder.copyWith(
borderSide: BorderSide(
color: theme.danger.foreground,
width: 2,
),
),
errorStyle: type.caption.copyWith(color: theme.danger.foreground),
suffixIconConstraints: const BoxConstraints(
minWidth: 48,
minHeight: 48,
),
suffixIcon: PaymentIconButton(
icon: _obscured
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
tooltip: _obscured ? 'Show password' : 'Hide password',
onPressed: widget.enabled
? () => setState(() => _obscured = !_obscured)
: null,
),
),
),
],
),
);
}
}
Source: auth_blocks_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/login_block.dart';
import 'compositions/register_block.dart';
void main() => runBlockDemo(const AuthBlocksDemo());
enum AuthDemoScenario {
signInFailsOnce,
registrationFailsOnce,
verificationRequired,
directAccount,
}
enum _Route { login, register, recovery, policy, home }
const _fixtureEmail = 'mina@example.com';
const _fixturePassword = 'notes123';
const _fixtureCode = '248913';
/// Synthetic Annota-themed host connecting the generic Login and Register
/// blocks. It is deliberately not Annota's production authentication flow:
/// there is no backend, account store, email delivery or secret persistence.
class AuthBlocksDemo extends StatefulWidget {
const AuthBlocksDemo({
super.key,
this.initialScenario = AuthDemoScenario.signInFailsOnce,
this.initialDark = false,
this.delay = const Duration(milliseconds: 600),
this.textScale,
this.initiallyRegister = false,
});
final AuthDemoScenario initialScenario;
final bool initialDark;
final Duration delay;
final bool initiallyRegister;
/// Optional fixed text scale for accessibility proof.
final double? textScale;
@override
State<AuthBlocksDemo> createState() => _AuthBlocksDemoState();
}
class _AuthBlocksDemoState extends State<AuthBlocksDemo> {
late bool dark = widget.initialDark;
late AuthDemoScenario scenario = widget.initialScenario;
late _Route route = widget.initiallyRegister ? _Route.register : _Route.login;
RegisterBlockStep registerStep = RegisterBlockStep.details;
String? loginError;
String? registerError;
String? recoveryMessage;
bool busy = false;
int generation = 0;
int signInAttempts = 0;
int registerAttempts = 0;
int recoveryVisits = 0;
String registeredEmail = _fixtureEmail;
void reset(AuthDemoScenario next) => setState(() {
generation++;
scenario = next;
route = _Route.login;
registerStep = RegisterBlockStep.details;
loginError = null;
registerError = null;
recoveryMessage = null;
busy = false;
signInAttempts = 0;
registerAttempts = 0;
recoveryVisits = 0;
registeredEmail = _fixtureEmail;
});
void open(_Route next) {
if (next != route) FocusScope.of(context).unfocus();
setState(() {
route = next;
loginError = null;
registerError = null;
if (next == _Route.recovery) {
recoveryVisits++;
recoveryMessage = null;
}
});
}
void abandonRegistration() {
FocusScope.of(context).unfocus();
setState(() {
route = _Route.login;
registerStep = RegisterBlockStep.details;
registerError = null;
registeredEmail = _fixtureEmail;
});
}
Future<void> signIn(LoginCredentials credentials) async {
if (busy) return;
final current = generation;
signInAttempts++;
setState(() {
busy = true;
loginError = null;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
busy = false;
final failFirst =
scenario == AuthDemoScenario.signInFailsOnce && signInAttempts == 1;
final wrongFixture =
credentials.email != _fixtureEmail ||
credentials.password != _fixturePassword;
if (failFirst || wrongFixture) {
loginError =
'Check the email and password for this synthetic account, then try again.';
return;
}
route = _Route.home;
});
}
Future<void> register(RegisterSubmission submission) async {
if (busy) return;
final current = generation;
registerAttempts++;
setState(() {
busy = true;
registerError = null;
registeredEmail = submission.email;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
busy = false;
if (scenario == AuthDemoScenario.registrationFailsOnce &&
registerAttempts == 1) {
registerError =
'The illustrative host could not create the account. Nothing was saved; try again.';
return;
}
if (scenario == AuthDemoScenario.verificationRequired) {
registerStep = RegisterBlockStep.verification;
} else {
route = _Route.home;
}
});
}
Future<void> verify(String code) async {
if (busy) return;
final current = generation;
setState(() {
busy = true;
registerError = null;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
busy = false;
if (code != _fixtureCode) {
registerError =
'That code does not match the synthetic message. Use $_fixtureCode or resend it.';
return;
}
route = _Route.home;
});
}
Future<void> resendCode() async {
if (busy) return;
final current = generation;
setState(() => busy = true);
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
setState(() {
busy = false;
registerError = null;
});
}
Future<void> sendRecovery(String email) async {
if (busy) return;
final current = generation;
final visit = recoveryVisits;
setState(() {
busy = true;
recoveryMessage = null;
});
await Future<void>.delayed(widget.delay);
if (!mounted || current != generation) return;
final deliver = visit == recoveryVisits && route == _Route.recovery;
setState(() {
busy = false;
recoveryMessage = deliver
? 'If $email belongs to this synthetic host, a reset message is waiting in the fixture inbox.'
: null;
});
}
RegisterBlock _registerBlock() => RegisterBlock(
key: ValueKey('register-$generation-$registerStep'),
step: registerStep,
initialEmail: _fixtureEmail,
verificationEmail: registeredEmail,
busy: busy,
errorText: registerError,
onSubmit: register,
onVerify: verify,
onResendVerification: resendCode,
onLogin: abandonRegistration,
onPolicy: () => open(_Route.policy),
);
Widget _registerOrPolicy() {
final policy = route == _Route.policy;
return Stack(
fit: StackFit.expand,
children: [
ExcludeFocus(
excluding: policy,
child: ExcludeSemantics(
excluding: policy,
child: Offstage(offstage: policy, child: _registerBlock()),
),
),
if (policy) _PolicyPage(onBack: () => open(_Route.register)),
],
);
}
@override
Widget build(BuildContext context) => BlockDemoShell(
title: 'Annota auth · illustrative demo',
dark: dark,
onToggleDark: () => setState(() => dark = !dark),
lightTheme: annotaTheme(Brightness.light),
darkTheme: annotaTheme(Brightness.dark),
locale: const Locale('en'),
textScale: widget.textScale,
scenarios: [
(
label: 'Sign-in fails once',
onSelected: () => reset(AuthDemoScenario.signInFailsOnce),
),
(
label: 'Registration fails once',
onSelected: () => reset(AuthDemoScenario.registrationFailsOnce),
),
(
label: 'Email verification required',
onSelected: () => reset(AuthDemoScenario.verificationRequired),
),
(
label: 'Registration continues directly',
onSelected: () => reset(AuthDemoScenario.directAccount),
),
],
body: (context) => switch (route) {
_Route.login => LoginBlock(
key: ValueKey('login-$generation'),
initialEmail: _fixtureEmail,
busy: busy,
errorText: loginError,
onSubmit: signIn,
onForgotPassword: () => open(_Route.recovery),
onRegister: () => open(_Route.register),
),
_Route.register || _Route.policy => _registerOrPolicy(),
_Route.recovery => _RecoveryPage(
key: ValueKey('recovery-$generation-$recoveryVisits'),
busy: busy,
message: recoveryMessage,
initialEmail: _fixtureEmail,
onSubmit: sendRecovery,
onBack: () => open(_Route.login),
),
_Route.home => _HomePage(onSignOut: () => reset(scenario)),
},
);
}
class _RecoveryPage extends StatefulWidget {
const _RecoveryPage({
super.key,
required this.busy,
required this.message,
required this.initialEmail,
required this.onSubmit,
required this.onBack,
});
final bool busy;
final String? message;
final String initialEmail;
final Future<void> Function(String email) onSubmit;
final VoidCallback onBack;
@override
State<_RecoveryPage> createState() => _RecoveryPageState();
}
class _RecoveryPageState extends State<_RecoveryPage> {
final _formKey = GlobalKey<FormState>();
late final _email = TextEditingController(text: widget.initialEmail);
@override
void dispose() {
_email.dispose();
super.dispose();
}
void submit() {
if (!(_formKey.currentState?.validate() ?? false)) return;
widget.onSubmit(_email.text.trim());
}
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
return PaymentFullPageView(
title: 'Reset password',
pageLink: PaymentLink(label: 'Log in', onPressed: widget.onBack),
primaryAction: PaymentButton(
label: 'Send reset message',
busy: widget.busy,
busyLabel: 'Sending reset message',
onPressed: widget.busy ? null : submit,
),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.group),
children: [
if (widget.message != null)
PaymentBanner(
tone: StatusTone.success,
title: 'Reset message recorded',
message: widget.message,
announce: true,
),
PaymentTextField(
label: 'Email address',
controller: _email,
type: PaymentTextFieldType.email,
required: true,
enabled: !widget.busy,
validator: (value) =>
RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$').hasMatch(value ?? '')
? null
: 'Enter a valid email address.',
textInputAction: TextInputAction.done,
onSubmitted: (_) => submit(),
),
],
),
),
);
}
}
class _PolicyPage extends StatelessWidget {
const _PolicyPage({required this.onBack});
final VoidCallback onBack;
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
final type = PaymentType.of(context);
return PaymentFullPageView(
title: 'Terms and privacy',
pageLink: PaymentLink(label: 'Create account', onPressed: onBack),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.group),
children: [
const PaymentBanner(
tone: StatusTone.neutral,
title: 'Illustrative host policy',
message:
'This page belongs to the demo host. It is not Annota production policy or authentication copy.',
),
Text(
'In a real app, this destination explains what account data the host collects, why it collects it, retention, deletion and contact choices. The block only opens the host destination; it never writes a consent record.',
style: type.body.copyWith(color: theme.textPrimary),
),
],
),
);
}
}
class _HomePage extends StatelessWidget {
const _HomePage({required this.onSignOut});
final VoidCallback onSignOut;
@override
Widget build(BuildContext context) {
final theme = PaymentTheme.of(context);
final type = PaymentType.of(context);
return PaymentFullPageView(
title: 'Home',
primaryAction: PaymentButton(
label: 'Sign out',
variant: PaymentButtonVariant.secondary,
onPressed: onSignOut,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
spacing: theme.space(PaymentSpace.group),
children: [
const PaymentBanner(
tone: StatusTone.success,
title: 'Signed in',
message:
'The host navigated here after its synthetic authentication callback.',
),
const PaymentBanner(
tone: StatusTone.neutral,
title: 'Illustrative Annota host',
message:
'This is a synthetic auth demo, not Annota’s production sign-in or account system.',
),
PaymentSection(
title: 'Next in Annota',
child: Text(
'Scan a document, review highlights and save notes. Those product surfaces are outside this authentication block demo.',
style: type.body.copyWith(color: theme.textPrimary),
),
),
],
),
);
}
}
/// Annota-derived illustrative host theme. Light colors follow the pinned web
/// handoff; the dark adaptation exists only so the demo can inspect kit states
/// in both appearances and is not an Annota production dark palette.
ThemeData annotaTheme(Brightness brightness) {
final dark = brightness == Brightness.dark;
final ink = dark ? const Color(0xFFF8FAFC) : const Color(0xFF0F172B);
final surface = dark ? const Color(0xFF0F172B) : Colors.white;
final muted = dark ? const Color(0xFF1E293B) : const Color(0xFFF8FAFC);
final secondary = dark ? const Color(0xFFCBD5E1) : const Color(0xFF62748E);
final border = dark ? const Color(0xFF94A3B8) : const Color(0xFF94A3B8);
final onAccent = dark ? const Color(0xFF0F172B) : Colors.white;
final scheme = ColorScheme.fromSeed(
seedColor: const Color(0xFF0F172B),
brightness: brightness,
primary: ink,
onPrimary: onAccent,
surface: surface,
onSurface: ink,
);
final payment = PaymentTheme.fromColorScheme(scheme).copyWith(
accent: ink,
onAccent: onAccent,
surface: surface,
surfaceMuted: muted,
outline: dark ? const Color(0xFF334155) : const Color(0xFFF1F5F9),
textPrimary: ink,
textSecondary: secondary,
border: border,
disabled: dark ? const Color(0xFF64748B) : const Color(0xFFA3AAB8),
radius: 12,
controlRadius: 6,
);
return ThemeData(
colorScheme: scheme,
useMaterial3: true,
scaffoldBackgroundColor: surface,
extensions: [payment],
dividerTheme: DividerThemeData(color: payment.outline, space: 1),
appBarTheme: AppBarTheme(
backgroundColor: surface,
foregroundColor: ink,
surfaceTintColor: Colors.transparent,
scrolledUnderElevation: 0,
centerTitle: false,
titleTextStyle: TextStyle(
fontSize: 17,
height: 24 / 17,
fontWeight: FontWeight.w600,
color: ink,
),
shape: Border(bottom: BorderSide(color: payment.outline)),
),
popupMenuTheme: PopupMenuThemeData(
color: surface,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: payment.controlBorderRadius,
side: BorderSide(color: payment.outline),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: surface,
border: OutlineInputBorder(
borderRadius: payment.controlBorderRadius,
borderSide: BorderSide(color: border),
),
),
);
}
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 invalid input, show/hide password, host failure and retry, busy locking, recovery navigation, the connected home destination, and 320 dp at 200% text. Android captures cover light, dark, failure and enlarged text. Connect your own identity provider, throttling, audit policy, account recovery and navigation before production use.