Enable Dark Mode!
overview-of-pagination-and-lazy-loading-odoo-data-in-mobo-apps.jpg
By: Cybrosys Technologies

Overview of Pagination & Lazy Loading Odoo Data in Mobo Apps

Technical Flutter mobo

Modern mobile applications often deal with large datasets. When integrating Flutter apps with Odoo ERP, fetching all records at once can cause performance issues, slow UI rendering, and excessive network usage. This is where Pagination and Lazy Loading become essential.

Integrating Flutter mobile applications with Odoo ERP is becoming increasingly popular for building modern, scalable business apps. However, handling large datasets such as products, customers, or invoices can lead to performance bottlenecks if data is loaded all at once.

In this blog, we will explore how to efficiently load Odoo data in Flutter using pagination and lazy loading techniques.

Why Pagination & Lazy Loading Matter

When your Flutter app connects to Odoo, it often retrieves records such as:

  • Products
  • Customers
  • Orders
  • Invoices
  • Inventory Data

When fetching data from Odoo, loading thousands of records at once can cause:

  • Slow application performance
  • Increased memory usage
  • Poor user experience
  • Heavy server load

Understanding Odoo Data Fetching

odoo_rpc is a Flutter package that simplifies communication with Odoo servers using JSON-RPC. It helps developers:

  • Authenticate users.
  • Call Odoo models.
  • Execute search_read, create, write and unlink.
  • Handle sessions easily.
  • Offset: Starting index of records.
  • Limit: Number of records to fetch.

Understanding Pagination in Odoo

Odoo supports pagination through:

  • offset > Starting position.
  • limit > Number of records per request.

Example

PageOffsetLimit
Page 1020
Page 22020
Page 34020

Implementing Pagination with odoo_rpc

Let’s fetch product records using pagination.

Create Product Fetch Service:-

// Fetch products with pagination
Future<List<dynamic>> fetchProducts(int offset, int limit) async {
  if (OdooConfig.useMockData) {
    return _getMockProducts(offset, limit);
  }
  try {
    final client = await _getClient();
    
    // Using the OdooClient's callKw with the correct Map parameter
    final result = await client.callKw({
      'model': OdooConfig.productModel,
      'method': 'search_read',
      'args': [],
      'kwargs': {
        'fields': OdooConfig.productFields,
        'domain': OdooConfig.domain,
        'limit': limit,
        'offset': offset,
      },
    });
    if (result is List) return result;
    if (result is Map && result['records'] != null) {
      return result['records'] as List;
    }
    return [];
  } catch (e) {
    print('Fetch Products Error: $e');
    rethrow;
  }
}

Implementing Lazy Loading in Flutter UI

Create Stateful Widget:-

class ProductListPage extends StatefulWidget {
  const ProductListPage({super.key});
  @override
  State<ProductListPage> createState() => _ProductListPageState();
}

Manage Pagination State:-

class _ProductListPageState extends State<ProductListPage> {
  final OdooService _odooService = OdooService();
  final List<dynamic> _products = [];
  int _offset = OdooConfig.initialOffset;
  final int _limit = OdooConfig.pageSize;
  bool _isLoading = false;
  bool _hasMore = true;
  final ScrollController _scrollController = ScrollController();

Load Initial Data:-

@override
void initState() {
  super.initState();
  _fetchProducts();
  _scrollController.addListener(_scrollListener);
}

Implement Lazy Loading Scroll Listener:-

void _scrollListener() {
  if (_scrollController.position.pixels >= 
      _scrollController.position.maxScrollExtent - 100) {
    _fetchProducts();
  }
}

Best Practices for Odoo Pagination

  • Keep a limit between 15 – 30 records.
  • Implement loading indicators.
  • Reset pagination during search or filters.
  • Use caching for offline support.
  • Load images separately if records contain media.

Common Use Cases

Pagination with odoo_rpc works well for:

  • Product Catalogs
  • Sales Orders
  • Customer Lists
  • Inventory Management
  • Accounting Records

Advantages of Using odoo_rpc

  • Simplifies Odoo API calls.
  • Maintains authentication session.
  • Structured method calls.
  • Easy integration with Flutter.
  • Supports full Odoo ORM operations.

Pagination and lazy loading are essential techniques when working with large Odoo datasets in Mobo apps. By combining these techniques with the odoo_rpc package, developers can build scalable, fast, and efficient mobile applications.

Using offset and limit, you can ensure smooth scrolling experiences while minimizing server load and memory usage.

To read more about How to Implement Offline Mode in Mobo with Odoo Data Sync, refer to our blog How to Implement Offline Mode in Mobo with Odoo Data Sync.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, KINFRA Techno Park
Kakkanchery, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message