flutter_data_cloud_provider 3.0.0 copy "flutter_data_cloud_provider: ^3.0.0" to clipboard
flutter_data_cloud_provider: ^3.0.0 copied to clipboard

Flutter package that provides cloud database and authentication functionality. Handles data operations, caching, session management, and secure API communication with time-based HMAC signatures.

Flutter Data Cloud Provider #

A Flutter package that provides cloud database and authentication functionality for Flutter applications. It acts as a client library for communicating with a backend API system, handling authentication, data operations, caching, and session management.

Features #

  • Data Operations: CRUD operations (guardar, actualizar, obtener, leeById)
  • Authentication: Complete auth flow with session authorization, token acquisition, and automatic token refresh
  • Caching: Two-tier caching system (in-memory + SharedPreferences persistence)
  • Security: Time-based HMAC signatures for request integrity
  • Session Management: Active sessions tracking and logout functionality
  • OTP Support: Generation and validation of one-time passwords
  • File Uploads: Support for uploading files and images
  • Password Management: Password change, recovery, and reset workflows

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_data_cloud_provider: ^1.0.0

Then run:

flutter pub get

Usage #

Initialize CloudDb #

import 'package:flutter_data_cloud_provider/flutter_data_cloud_provider.dart';

final cloudDb = CloudDb(
  endpointApi: 'https://api.example.com',
  endpointAuth: 'https://auth.example.com',
  flutterHttpProvider: flutterHttpProvider,
  dataShpProvider: dataShpProvider,
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  redirectUri: RedirectUri.login_post,
  enableDebugLogs: true, // Optional: enable debug logging
);

Authentication #

// Step 1: Authorize session
final authResponse = await cloudDb.autorizaSesionV4();
final codigoAutorizacion = authResponse['codigoAutorizacion'];
final idSesion = authResponse['idSesion'];

// Step 2: Get token
final tokenResponse = await cloudDb.obtieneToken(
  codigoAutorizacion: codigoAutorizacion,
);

// Step 3: Login (if using login_post redirect)
final loginResponse = await cloudDb.loginAuthV4(
  codigoAutorizacion: codigoAutorizacion,
  clientId: 'your-client-id',
  keyLogin: 'user@example.com',
  password: 'hashedPassword',
);

Data Operations #

// Save new data
final saveResponse = await cloudDb.guardar(
  coleccion: 'users',
  versionData: '1.0',
  data: {'name': 'John', 'email': 'john@example.com'},
  runIsolate: false,
);

// Get data
final getData = await cloudDb.obtener(
  coleccion: 'users',
  consulta: '{"estado": "A"}',
  hash: '',
  runIsolate: false,
);

// Get by ID
final getById = await cloudDb.leeById(
  coleccion: 'users',
  consulta: '60f7b3b3b3b3b3b3b3b3b3b3',
  hash: '',
);

// Update data
final updateResponse = await cloudDb.actualizar(
  coleccion: 'users',
  idServer: '60f7b3b3b3b3b3b3b3b3b3b3',
  versionData: '1.0',
  data: {'name': 'John Updated'},
  dataOriginal: '{"name": "John"}',
  encodeKeys: [],
  esquema: {},
  runIsolate: false,
);

Generic Route #

For custom API endpoints:

final response = await cloudDb.rutaGenerica(
  accion: 'POST',
  endPoint: 'https://api.example.com/custom/endpoint',
  body: '{"key": "value"}',
  runIsolate: false,
  hashQuery: '',
  coleccion: 'custom',
  cacheON: true, // Enable caching for this request
  timeout: 30, // Optional timeout in seconds
);

Session Management #

// Get active sessions
final sessions = await cloudDb.sesionesActivas();

// Close current session
await cloudDb.cerrarSesionActiva();

// Close specific session
await cloudDb.cerrarSesionActiva(idSesion: 'session-id');

OTP Operations #

// Generate OTP
final otpResponse = await cloudDb.generaOTP(
  coleccion: 'users',
  idColeccion: 'user-id',
);

// Validate OTP
final validateResponse = await cloudDb.validaOTP(
  coleccion: 'users',
  idColeccion: 'user-id',
  codigoOTP: '123456',
);

Password Reset Flow #

// Step 1: Request password reset
await cloudDb.reseteoPassWord(
  clientId: 'your-client-id',
  email: 'user@example.com',
);

// Step 2: Verify code
await cloudDb.verificacionCodigoReseteoPassWord(
  clientId: 'your-client-id',
  email: 'user@example.com',
  codigo: '123456',
);

// Step 3: Set new password
await cloudDb.enviaNuevoPassword(
  clientId: 'your-client-id',
  email: 'user@example.com',
  codigo: '123456',
  password: 'NewSecurePassword123!',
);

Response Format #

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

Success Response:

{
  'dataOk': 'Success message',
  'data': [...] // or single object
}

Error Response:

{
  'dataNOk': 'NOK',
  'error': 'Error description'
}

Caching #

The package implements a two-tier caching system:

  • In-Memory Cache: Fast access during app runtime
  • Persistent Cache: Survives app restarts using SharedPreferences

Cache duration is 15 minutes by default. Cache is automatically invalidated when data is modified through guardar or actualizar methods.

Dependencies #

This package depends on the following companion packages:

  • flutter_data_shp_provider
  • flutter_http_provider
  • flutter_models_provider
  • flutter_security_provider
  • flutter_utils_providers

License #

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

Author #

Roble Sistemas - roblesistemas.com.ar

0
likes
120
points
450
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package that provides cloud database and authentication functionality. Handles data operations, caching, session management, and secure API communication with time-based HMAC signatures.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

crypto, flutter, flutter_data_shp_provider, flutter_http_provider, flutter_models_provider, flutter_security_provider, flutter_utils_providers, shared_preferences

More

Packages that depend on flutter_data_cloud_provider