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
- Add the dependency to your
pubspec.yaml:dependencies: inatroget_flutter: ^0.0.1 - Run
flutter pub get(ordart pub getfor pure Dart projects). - Import the package where you need it:
import 'package:inatroget_flutter/inatroget_flutter.dart'; - (Optional) Adjust
InatroConfigif 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.***