flutter_data_mobile_provider

A Flutter package that provides a database abstraction layer for mobile data operations. It wraps ObjectBox database operations with advanced features like SHA256 hashing, status tracking, and complex query capabilities.

Features

  • Database abstraction: Unified API for ObjectBox database operations
  • Complex queries: Support for index-based filtering with operators and OR/AND unions
  • Sorting and pagination: Built-in support for ordering, limit, and skip
  • Data integrity: SHA256 hashing for data verification
  • Transfer tracking: Track record synchronization status with eTransfer flag
  • Timestamp tracking: Get oldest/newest creation timestamps from collections

Installation

Add this to your pubspec.yaml:

dependencies:
  flutter_data_mobile_provider: ^1.0.0

Then run:

flutter pub get

Usage

Initialize MobileDb

import 'package:flutter_data_mobile_provider/flutter_data_mobile_provider.dart';

final mobileDb = MobileDb(
  flutterObjectBoxProvider: yourObjectBoxProvider,
  gestorData: yourGestorData,
);

Query data

// Query with filters
final result = await mobileDb.obtener<YourModel>(
  coleccion: 'your_collection',
  argsLocalBD: [
    ['fieldName'],      // Index names
    ['=='],             // Operators: ==, !=, >, <, >=, <=
    ['value'],          // Values to compare
  ],
  ordenar: '{"fieldName": 1}',  // 1 = asc, -1 = desc
  limit: '10',
  skip: '0',
);

Save data

final result = await mobileDb.guardar<YourModel>(
  data: [model1, model2],
);

Get untransferred records

final result = await mobileDb.obtenerRegistrosNoTransferidos<YourModel>(
  coleccion: 'your_collection',
  limit: '50',
);

Change record status

final result = await mobileDb.cambiaEstado<YourModel>(
  coleccion: 'your_collection',
  id: 'record_id',
  tipoId: 'idMobile',  // or 'idServer'
  estado: 'new_status',
);

Get hash for data verification

final result = await mobileDb.obtieneHashCreadoElDispositivo<YourModel>(
  coleccion: 'your_collection',
  argsLocalBD: [['field'], ['=='], ['value']],
);

print(result.hashCalculate);  // SHA256 hash
print(result.respuestaHash);  // Query response

Response Format

All methods return a Map<String, dynamic> with the following structure:

Success:

{
  'ok': true,
  'datos': [...],  // List of results
}

Error:

{
  'ok': false,
  'error': 'Error message',
}

Dependencies

This package depends on:

License

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