inatroget_flutter

Description

inatroget_flutter is a small Dart/Flutter library that automates the login flow for the INATRO portal and parses the returned dashboard into strongly typed models. It handles client-side validation, cookie persistence, HTML parsing, and exposes lightweight models for login results and driver license data.

Setup

  1. Add the dependency to your pubspec.yaml:
    dependencies:
      inatroget_flutter: ^0.0.1
    
  2. Run flutter pub get (or dart pub get for pure Dart projects).
  3. Import the package where you need it:
    import 'package:inatroget_flutter/inatroget_flutter.dart';
    
  4. (Optional) Adjust InatroConfig if you need custom URLs or timeouts:
    final config = InatroConfig(
      loginUrl: 'https://example/login',
      loginPostUrl: 'https://example/login-submit',
      estadoCartaUrl: 'https://example/dashboard',
      timeout: const Duration(seconds: 20),
    );
    

Examples

Validate login inputs only

final error = Validators.validateLoginInputs('123456789', '2000-01-01');
if (error != null) {
  print('Validation failed: ${error.message}');
}

Perform the full login flow

final service = InatroService(
  config: InatroConfig.defaultConfig,
);

final result = await service.doLogin('123456789', '2000-01-01');

if (result.success && result.data != null) {
  final carta = result.data!;
  print('Nome: ${carta.nomeCompleto}');
  print('Estado: ${carta.estadoCarta}');
} else {
  print('Login failed (${result.code}): ${result.message}');
}

Reuse cookies across sessions

final cookies = await CookieManager.loadCookies();
if (cookies != null) {
  // Attach custom cookies to your HTTP client if needed
}

Refer to the test/inatroget_flutter_test.dart file for additional usage patterns around validation logic. For more advanced scenarios (mocking HTTP or parsing different HTML layouts), extend InatroService or swap the injected http.Client.***

Libraries

inatroget_flutter