181186 - Criar PDV Android para rodar em maquinas P.O.S.
This commit is contained in:
commit
c9983cbad5
204 files changed
+11453
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
abstract interface class AppVersionProvider {
|
||||
Future<String> getVersion();
|
||||
}
|
||||
|
||||
class PackageInfoAppVersionProvider implements AppVersionProvider {
|
||||
const PackageInfoAppVersionProvider();
|
||||
|
||||
@override
|
||||
Future<String> getVersion() async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
return packageInfo.version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
|
||||
import '../../domain/entities/pos_device.dart';
|
||||
|
||||
abstract interface class PosDeviceProvider {
|
||||
Future<PosDevice> getDevice();
|
||||
}
|
||||
|
||||
class PlatformPosDeviceProvider implements PosDeviceProvider {
|
||||
PlatformPosDeviceProvider({DeviceInfoPlugin? plugin})
|
||||
: _plugin = plugin ?? DeviceInfoPlugin();
|
||||
|
||||
final DeviceInfoPlugin _plugin;
|
||||
|
||||
@override
|
||||
Future<PosDevice> getDevice() async {
|
||||
if (!Platform.isAndroid) {
|
||||
return PosDevice(platform: Platform.operatingSystem);
|
||||
}
|
||||
final info = await _plugin.androidInfo;
|
||||
return PosDevice(
|
||||
platform: 'android',
|
||||
serial: info.id,
|
||||
model: info.model,
|
||||
brand: info.brand,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
class ServerUrlValidator {
|
||||
ServerUrlValidator._();
|
||||
|
||||
static String? validate(String value, {bool requireHttps = false}) {
|
||||
final trimmed = value.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
return 'Informe a URL do servidor.';
|
||||
}
|
||||
|
||||
final uri = Uri.tryParse(trimmed);
|
||||
if (uri == null || !uri.hasAuthority || uri.host.isEmpty) {
|
||||
return 'Informe uma URL válida, incluindo o host.';
|
||||
}
|
||||
if (uri.scheme != 'https' && uri.scheme != 'http') {
|
||||
return 'A URL deve usar HTTP ou HTTPS.';
|
||||
}
|
||||
if (requireHttps && uri.scheme != 'https') {
|
||||
return 'Use uma URL HTTPS para proteger a conexão.';
|
||||
}
|
||||
if (uri.userInfo.isNotEmpty || uri.hasFragment) {
|
||||
return 'A URL não pode conter credenciais ou fragmentos.';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
abstract interface class SecureSessionStorage {
|
||||
Future<String?> readCookie();
|
||||
|
||||
Future<String?> readServerUrl();
|
||||
|
||||
Future<String?> readSessionId();
|
||||
|
||||
Future<void> writeSession(
|
||||
{required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId});
|
||||
|
||||
Future<void> clearCookie();
|
||||
}
|
||||
|
||||
class FlutterSecureSessionStorage implements SecureSessionStorage {
|
||||
FlutterSecureSessionStorage({FlutterSecureStorage? storage})
|
||||
: _storage = storage ?? const FlutterSecureStorage();
|
||||
|
||||
static const _cookieKey = 'pdv.odoo_session_cookie';
|
||||
static const _serverUrlKey = 'pdv.odoo_session_server_url';
|
||||
static const _sessionIdKey = 'pdv.odoo_session_id';
|
||||
final FlutterSecureStorage _storage;
|
||||
|
||||
@override
|
||||
Future<String?> readCookie() => _storage.read(key: _cookieKey);
|
||||
|
||||
@override
|
||||
Future<String?> readServerUrl() => _storage.read(key: _serverUrlKey);
|
||||
|
||||
@override
|
||||
Future<String?> readSessionId() => _storage.read(key: _sessionIdKey);
|
||||
|
||||
@override
|
||||
Future<void> writeSession(
|
||||
{required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId}) async {
|
||||
await _storage.write(key: _cookieKey, value: cookie);
|
||||
await _storage.write(key: _serverUrlKey, value: serverUrl);
|
||||
await _storage.write(key: _sessionIdKey, value: sessionId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearCookie() async {
|
||||
await _storage.delete(key: _cookieKey);
|
||||
await _storage.delete(key: _serverUrlKey);
|
||||
await _storage.delete(key: _sessionIdKey);
|
||||
}
|
||||
}
|
||||
|
||||
class InMemorySessionStorage implements SecureSessionStorage {
|
||||
String? _cookie;
|
||||
String? _serverUrl;
|
||||
String? _sessionId;
|
||||
|
||||
@override
|
||||
Future<String?> readCookie() async => _cookie;
|
||||
|
||||
@override
|
||||
Future<String?> readServerUrl() async => _serverUrl;
|
||||
|
||||
@override
|
||||
Future<String?> readSessionId() async => _sessionId;
|
||||
|
||||
@override
|
||||
Future<void> writeSession({
|
||||
required String cookie,
|
||||
required String serverUrl,
|
||||
required String sessionId,
|
||||
}) async {
|
||||
_cookie = cookie;
|
||||
_serverUrl = serverUrl;
|
||||
_sessionId = sessionId;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> clearCookie() async {
|
||||
_cookie = null;
|
||||
_serverUrl = null;
|
||||
_sessionId = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'secure_session_storage.dart';
|
||||
|
||||
SecureSessionStorage createSessionStorage() {
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
return FlutterSecureSessionStorage();
|
||||
}
|
||||
if (kDebugMode) {
|
||||
return InMemorySessionStorage();
|
||||
}
|
||||
throw UnsupportedError(
|
||||
'O armazenamento seguro de sessão só está disponível em Android/iOS.',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
class CurrencyFormatter {
|
||||
CurrencyFormatter._();
|
||||
|
||||
static String formatBrl(int? minorUnits) {
|
||||
if (minorUnits == null) return 'Preço indisponível';
|
||||
|
||||
final negative = minorUnits < 0;
|
||||
final value = minorUnits.abs();
|
||||
final whole = value ~/ 100;
|
||||
final cents = (value % 100).toString().padLeft(2, '0');
|
||||
final groupedWhole = _groupThousands(whole.toString());
|
||||
final sign = negative ? '-' : '';
|
||||
return '${sign}R\$ $groupedWhole,$cents';
|
||||
}
|
||||
|
||||
static String _groupThousands(String digits) {
|
||||
final groups = <String>[];
|
||||
for (var end = digits.length; end > 0; end -= 3) {
|
||||
final start = end - 3 < 0 ? 0 : end - 3;
|
||||
groups.insert(0, digits.substring(start, end));
|
||||
}
|
||||
return groups.join('.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppButton extends StatelessWidget {
|
||||
const AppButton({
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
this.icon,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final VoidCallback? onPressed;
|
||||
final IconData? icon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FilledButton.icon(
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon ?? Icons.arrow_forward),
|
||||
label: Text(label),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppTextField extends StatelessWidget {
|
||||
const AppTextField({
|
||||
required this.label,
|
||||
this.controller,
|
||||
this.obscureText = false,
|
||||
this.keyboardType,
|
||||
this.textInputAction,
|
||||
this.prefixIcon,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final TextEditingController? controller;
|
||||
final bool obscureText;
|
||||
final TextInputType? keyboardType;
|
||||
final TextInputAction? textInputAction;
|
||||
final IconData? prefixIcon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
obscureText: obscureText,
|
||||
keyboardType: keyboardType,
|
||||
textInputAction: textInputAction,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: prefixIcon == null ? null : Icon(prefixIcon),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EmptyView extends StatelessWidget {
|
||||
const EmptyView({
|
||||
required this.title,
|
||||
required this.message,
|
||||
this.icon = Icons.inbox_outlined,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String message;
|
||||
final IconData icon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 48, color: Theme.of(context).colorScheme.outline),
|
||||
const SizedBox(height: 12),
|
||||
Text(title, style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 4),
|
||||
Text(message, textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ErrorView extends StatelessWidget {
|
||||
const ErrorView({
|
||||
required this.message,
|
||||
this.onRetry,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String message;
|
||||
final VoidCallback? onRetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.cloud_off_outlined,
|
||||
size: 40,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(message, textAlign: TextAlign.center),
|
||||
if (onRetry != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextButton.icon(
|
||||
onPressed: onRetry,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Tentar novamente'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoadingView extends StatelessWidget {
|
||||
const LoadingView({this.message = 'Carregando...', super.key});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text(message),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user