br_code_pix

pub package Dart

A fully native Dart package strictly following the official Banco Central do Brasil (BCB) BR Code and EMV QR Code manual.

Generate and parse both Static and Dynamic Pix (BR Code) payloads effortlessly, with built-in robust CRC16-CCITT validation ensuring 100% compliance with Pix scanning applications.

Features

  • Standard Emv Integration: Generates blocks following the exact ID + Length + Value strict formatting.
  • Accurate CRC16: Mathematical CRC16-CCITT calculation strictly validating your payloads to avoid reading errors.
  • Static Pix: Best for simple offline or hardcoded charges where you provide the Pix Key, Receiver Name, City, and an optional Fixed Amount.
  • Dynamic Pix (Cob/CobV): As specified by the Pix API Documentation, allowing you to drop in a payload URL provided by your PSP and automatically assembling a dynamic QR Code EMV string.
  • Fully independent: No heavy dependencies or native platform integrations. Works in any Dart/Flutter environment.

Usage

Here are some simple examples showing how to generate valid Pix payloads and easily render them as a QR Code widget inside your Flutter app. Look at the example/ folder for more.

1. Rendering a Pix QR Code Widget

The package provides an out-of-the-box BrCodePixWidget that automatically calculates the EMV and generates the QR Code rendering.

import 'package:flutter/material.dart';
import 'package:br_code_pix/br_code_pix.dart';

class PaymentScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: BrCodePixWidget.staticPix(
        pixKey: '+5511999999999',
        merchantName: 'MINHA LOJA PIX',
        merchantCity: 'SAO PAULO',
        amount: 35.50,
        size: 250.0,
      ),
    );
  }
}

2. Generating a Static Pix Payload String

If you just need the raw EMV string data for other usages:

import 'package:br_code_pix/br_code_pix.dart';

void main() {
  final staticPix = BrCodePix.generateStatic(
    pixKey: '+5511999999999', // E.g: Phone, CPF, CNPJ, Email, Random
    merchantName: 'NOME DO RECEBEDOR',
    merchantCity: 'SAO PAULO',
    amount: 10.00, // Optional
    txid: 'PGTO123', // Optional, defaults to '***'
  );

  print('Static Pix Payload: $staticPix');
}

3. Generating a Dynamic Pix Payload String

For Dynamic Pix, the transaction details are managed by your PSP API. You only inject the URL returned by them.

import 'package:br_code_pix/br_code_pix.dart';

void main() {
  final dynamicPix = BrCodePix.generateDynamic(
    url: 'pix.bcb.gov.br/qr/v2/cobv/000abc123',
    merchantName: 'MINHA LOJA PIX',
    merchantCity: 'BRASILIA',
  );

  print('Dynamic Pix Payload: $dynamicPix');
}

Contributing

Pull tests, reports, and code contributions are always welcome.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Libraries

br_code_pix
Provides utilities to generate Static and Dynamic Pix BR Codes (EMV QR Codes).