QR scanner
Some ndk_flutter widgets can read a value from a QR code. For example, the wallet widgets
let the user scan an NWC connection URI (nostr+walletconnect://...) instead of typing it.
ndk_flutter does not bundle a camera/scanner dependency. Instead you provide your own
scanner, so you stay in control of the camera plugin, runtime permissions, and the UI. When you
don't provide one, the scan button is hidden and users can still paste a value manually.
Provide a scanner
A scanner is a callback that opens your scanning UI and returns the scanned string, or null
if the user cancels:
typedef NwcUriScanner = Future<String?> Function(BuildContext context);
Pass it to the widget (or dialog) that needs it. For wallets, that's NWallets:
body: NWallets(
key: _walletsKey,
ndkFlutter: ndkFlutter,
nwcUriScanner: scanNwcUri,
),
The same nwcUriScanner: parameter is accepted by the standalone add-wallet dialogs:
showAddNwcWalletDialog(context, ndkFlutter, nwcUriScanner: scanNwcUri);
showNwcConnectionOptionsDialog(context, ndkFlutter, nwcUriScanner: scanNwcUri);
The widgets validate the scanned value (e.g. that an NWC URI starts with
nostr+walletconnect://) and show an error for anything else, so your callback only needs to
return the raw scanned string.
Example: scanning with mobile_scanner
The sample app implements the callback with
mobile_scanner. Add it to your app (not to
ndk_flutter):
flutter pub add mobile_scanner
The callback just opens a dialog that wraps the camera view and pops the first decoded value:
Future<String?> scanNwcUri(BuildContext context) {
return showDialog<String?>(
context: context,
builder: (context) => const _NwcQrScannerDialog(),
);
}
The full dialog lives in
packages/sample-app/lib/nwc_qr_scanner.dart.
It adds a camera preview, a paste fallback, error handling, and a desktop/web-safe layout.