autocash 1.0.3 copy "autocash: ^1.0.3" to clipboard
autocash: ^1.0.3 copied to clipboard

Dart & Flutter SDK for AutoCash payment system (VF-Cash, OKX, Binance).

example/main.dart

import 'package:flutter/material.dart';
import 'package:autocash/autocash.dart';

void main() {
  runApp(const AutoCashExampleApp());
}

/// Root application widget
class AutoCashExampleApp extends StatelessWidget {
  const AutoCashExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'AutoCash Flutter Example',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: Colors.red,
      ),
      home: const AutoCashHomePage(),
    );
  }
}

/// Main screen that demonstrates:
/// 1) Creating a Vodafone Cash payment link
/// 2) Verifying the payment using phone + amount
class AutoCashHomePage extends StatefulWidget {
  const AutoCashHomePage({super.key});

  @override
  State<AutoCashHomePage> createState() => _AutoCashHomePageState();
}

class _AutoCashHomePageState extends State<AutoCashHomePage> {
  /// Controllers for user input
  final _phoneController = TextEditingController();
  final _amountController = TextEditingController();

  /// Form key for validation
  final _formKey = GlobalKey<FormState>();

  /// SDK instance
  final AutoCash _autoCash = AutoCash(
    userId: 'YOUR_USER_ID',
    panelId: 'YOUR_PANEL_ID',
  );

  /// UI state
  String? _paymentLink;
  String? _resultMessage;
  bool _loading = false;

  /// Generates a Vodafone Cash payment link
  void _createPaymentLink() {
    if (!_formKey.currentState!.validate()) return;

    // extra can be any identifier you want (order id, username, etc.)
    final extra = 'demo_${_phoneController.text.trim()}';

    final link = _autoCash.vfcashLink(extra: extra);

    setState(() {
      _paymentLink = link;
      _resultMessage = 'Payment link generated successfully.';
    });
  }

  /// Verifies the Vodafone Cash payment using phone number and amount
  Future<void> _verifyPayment() async {
    if (!_formKey.currentState!.validate()) return;

    final phone = _phoneController.text.trim();
    final amount = double.tryParse(_amountController.text.trim());

    if (amount == null) {
      setState(() {
        _resultMessage = 'Invalid amount value.';
      });
      return;
    }

    setState(() {
      _loading = true;
      _resultMessage = null;
    });

    try {
      final result = await _autoCash.checkVFCash(
        phone: phone,
        amount: amount,
        extra: 'demo_$phone',
      );

      setState(() {
        _resultMessage =
            'Status: ${result.status}\n'
            'Message: ${result.message}\n'
            'Transaction Key: ${result.key ?? '-'}';
      });
    } catch (e) {
      setState(() {
        _resultMessage = 'Error: $e';
      });
    } finally {
      setState(() {
        _loading = false;
      });
    }
  }

  @override
  void dispose() {
    _phoneController.dispose();
    _amountController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('AutoCash – Vodafone Cash Demo'),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            /// Input form
            Form(
              key: _formKey,
              child: Column(
                children: [
                  TextFormField(
                    controller: _phoneController,
                    keyboardType: TextInputType.phone,
                    decoration: const InputDecoration(
                      labelText: 'Vodafone Cash Phone',
                      hintText: '010xxxxxxxx',
                    ),
                    validator: (value) {
                      if (value == null || value.trim().isEmpty) {
                        return 'Please enter phone number';
                      }
                      return null;
                    },
                  ),
                  const SizedBox(height: 12),
                  TextFormField(
                    controller: _amountController,
                    keyboardType:
                        const TextInputType.numberWithOptions(decimal: true),
                    decoration: const InputDecoration(
                      labelText: 'Amount (EGP)',
                      hintText: '100',
                    ),
                    validator: (value) {
                      if (value == null || value.trim().isEmpty) {
                        return 'Please enter amount';
                      }
                      if (double.tryParse(value.trim()) == null) {
                        return 'Enter a valid number';
                      }
                      return null;
                    },
                  ),
                ],
              ),
            ),

            const SizedBox(height: 24),

            /// Action buttons
            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                    onPressed: _createPaymentLink,
                    child: const Text('Create Payment Link'),
                  ),
                ),
                const SizedBox(width: 12),
                Expanded(
                  child: ElevatedButton(
                    onPressed: _loading ? null : _verifyPayment,
                    child: _loading
                        ? const CircularProgressIndicator()
                        : const Text('Verify Payment'),
                  ),
                ),
              ],
            ),

            const SizedBox(height: 24),

            /// Show generated payment link
            if (_paymentLink != null) ...[
              const Text(
                'Payment Link:',
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
              SelectableText(_paymentLink!),
              const SizedBox(height: 16),
            ],

            /// Show result / status
            if (_resultMessage != null) ...[
              const Text(
                'Result:',
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
              Text(_resultMessage!),
            ],
          ],
        ),
      ),
    );
  }
}
0
likes
150
points
54
downloads

Publisher

verified publisherdarksidehost.com

Weekly Downloads

Dart & Flutter SDK for AutoCash payment system (VF-Cash, OKX, Binance).

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http

More

Packages that depend on autocash