plugin_clover 0.0.6
plugin_clover: ^0.0.6 copied to clipboard
Plugin Flutter para integrar com Clover POS.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:plugin_clover/plugin_clover.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _pluginCloverPlugin = PluginClover();
String _saleResult = '';
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
String platformVersion;
try {
platformVersion =
await _pluginCloverPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
Future<void> _startSale() async {
try {
// Exemplo de amount: 1000 (centavos = R$10,00)
// Exemplo de applicationId: passe o ID do seu app Clover
await _pluginCloverPlugin.iniciaVenda(
2.toString(), //2 - Debito, 3-Credito, 122 - PIX
1560.toString(),
'12.138.070/0001-59',
'12.138.070/0001-59',
1.toString(),
);
setState(() {
_saleResult = 'Sale started successfully!';
});
} on PlatformException catch (e) {
setState(() {
_saleResult = 'Failed to start sale: ${e.message}';
});
}
}
Future<void> _cancelavenda() async {
try {
// Exemplo de amount: 1000 (centavos = R$10,00)
// Exemplo de applicationId: passe o ID do seu app Clover
await _pluginCloverPlugin.cancelaVenda(
'1', //documento para cancelar,
'12.138.070/0001-59',
'12.138.070/0001-59',
);
setState(() {
_saleResult = 'venda cancelada com sucesso!';
});
} on PlatformException catch (e) {
setState(() {
_saleResult = 'Failed to cancel sale: ${e.message}';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Running on: $_platformVersion\n'),
ElevatedButton(
onPressed: _startSale,
child: const Text('Start Sale'),
),
ElevatedButton(
onPressed: _cancelavenda,
child: const Text('Start Sale'),
),
if (_saleResult.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(_saleResult),
),
],
),
),
),
);
}
}