how-to-implement-barcode-qr-code-scanning-in-odoo-apps-using-flutter

How to Implement Barcode & QR Code Scanning in Odoo Apps Using Flutter?

Barcode and QR Code Scanning in Odoo Apps using Flutter

Barcode and QR code scanning are essential for inventory management, POS systems, and logistics applications. Imagine walking through a warehouse, pointing your phone at a barcode, and instantly updating your inventory in Odoo, no paperwork, no manual entry, just smooth, automated precision. That’s the advantage of combining Flutter’s sleek mobile framework with Odoo’s powerful backend system. In today’s fast-moving business world, speed and accuracy aren’t just goals, they’re essentials. Barcode and QR code scanning bring new efficiency to POS systems, logistics, and inventory tracking. You get real-time updates and more intelligent workflows with just a quick scan. This guide will walk you through building a Flutter app that connects directly with Odoo and transforms how you manage operations.

Prerequisites

  • Flutter installed
  • Odoo backend with necessary modules (Inventory, POS, or custom module for barcode scanning)
  • API access to Odoo (REST or XML-RPC)
  • flutter_barcode_scanner package for scanning

How to Implement Barcode and QR Code Scanning in Odoo Apps Using Flutter: A Step-by-Step Guide

Step 1: Install Dependencies

Add the required package in pubspec.yaml:

				
					dependencies: flutter:
sdk: flutter
flutter_barcode scanner: ^2.0.0 
http: ^0.13.0

				
			

Then Run:

				
					flutter pub get
				
			

Step 2: Implement Barcode/QR Scanner in Flutter

In this step, you’ll integrate the barcode and QR code scanning feature using the flutter_barcode_scanner package. The scanned data will be captured and displayed within the app’s UI for further processing.

				
					class _BarcodeScannerScreenState extends State {
  String _scannedBarcode = '';


  Future scanBarcode() async {
    String barcodeScanResult;
    try {
      barcodeScanResult = await FlutterBarcodeScanner.scanBarcode(
        '#ff6666', 'Cancel', true, ScanMode.BARCODE);
    } catch (e) {
      barcodeScanResult = 'Failed to get barcode';
    }


    setState(() {
      _scannedBarcode = barcodeScanResult;
    });
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Scan Barcode/QR Code')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Scanned Code: $_scannedBarcode'),
            ElevatedButton(
              onPressed: scanBarcode,
              child: Text('Scan'),
            ),
          ],
        ),
      ),
    );
  }
}



				
			

Step 3: Sending Scanned Data to Odoo

Once a barcode is scanned, we need to send the data to Odoo using its API. Below is an example using the Odoo REST API.

				
					import 'package:http/http.dart' as http;
import 'dart:convert';


Future sendBarcodeToOdoo(String barcode) async {
  final String url = 'https://your-odoo-instance.com/api/inventory/barcode';
  final response = await http.post(
    Uri.parse(url),
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_ODOO_ACCESS_TOKEN',
    },
    body: jsonEncode({'barcode': barcode}),
  );


  if (response.statusCode == 200) {
    print('Barcode sent successfully');
  } else {
    print('Failed to send barcode: ${response.body}');
  }
}



				
			

Call this function after scanning the barcode:

				
					scanBarcode() async {
  String barcodeScanResult = await FlutterBarcodeScanner.scanBarcode(
    '#ff6666',
    'zCancel',
    true,
    ScanMode.BARCODE
  );


  setState(() {
    _scannedBarcode = barcodeScanResult;
  });


  await sendBarcodeToOdoo(_scannedBarcode);
}

				
			

Step 4: Handling Odoo Response

Odoo might return inventory details for a scanned product. Parse and display this data in your Flutter app:

				
					Future getProductDetails(String barcode) async {
  final response = await http.get(
    Uri.parse('https://your-odoo-instance.com/api/product?barcode=$barcode'),
    headers: {'Authorization': 'Bearer YOUR_ODOO_ACCESS_TOKEN'},
  );


  if (response.statusCode == 200) {
    final productData = jsonDecode(response.body);
    print('Product Name: ${productData["name"]}');
  } else {
    print('Product not found');
  }
}

				
			

Call this function after scanning:

				
					await getProductDetalis(_scannedBarcode);
				
			

Step 5: Displaying Scanned Data in UI

Modify your UI to show product details fetched from Odoo:

				
					Text('Product Name: ${productData["name"]}'),
Text('Stock Quantity: ${productData["quantity"]}'),
				
			

Step 6: Error Handling and Edge Cases

To make your application robust, consider handling the following cases:

No Barcode Scanned: Show an error message if the user cancels scanning.

Invalid Barcode: Validate the barcode before sending it to Odoo.

Network Errors: Handle API failures and show appropriate messages.

Odoo Authentication Issues: Implement token expiration handling.

Example:
				
					if (response.statusCode == 401) {
  print('Authentication error. Please log in again.');    
  }
				
			

Step 7: Testing the Integration

Before deploying, thoroughly test the barcode scanning functionality:

  1. Test scanning with different barcode types (EAN, UPC, QR, etc.).
  2. Validate API responses and ensure data is correctly fetched from Odoo.
  3. Check UI responsiveness and error handling.
  4. Simulate network failures to test offline handling.

Step 8: Deploying the App

Once testing is complete:

  • Build the Flutter app (flutter build apk or flutter build ios).
  • Deploy the app to Google Play Store or App Store.
  • Ensure Odoo is properly configured to handle barcode requests.

Bringing Smart Scanning to Life with Flutter and Odoo

This guide demonstrates implementing barcode/QR code scanning in Flutter and syncing scanned data with an Odoo backend. By integrating these steps, you can efficiently build inventory management, POS, and logistics applications. Whether aiming for faster checkouts, accurate stock tracking, or simplified warehouse operations, combining Flutter’s flexibility with Odoo’s backend power equips your business with a modern, tech-driven solution.

Picture of Veerabhadram Rudrararpu

Veerabhadram Rudrararpu

I'm Veerabhadram Rudrararpu, a Flutter Developer focused on building high-performance, cross-platform mobile apps with clean code and responsive UI/UX. Passionate about solving real-world problems and delivering user-centric solutions through modern mobile technologies.

Get a free quote