pinelabs_native 1.0.0 copy "pinelabs_native: ^1.0.0" to clipboard
pinelabs_native: ^1.0.0 copied to clipboard

Flutter wrapper for the Pine Labs Online iOS and Android SDKs. Provides a unified API for startPayment across both platforms.

example/lib/main.dart

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

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

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pine Labs SDK Example',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF0B6E4F)),
        useMaterial3: true,
      ),
      home: const ExampleHomePage(),
    );
  }
}

class ExampleHomePage extends StatefulWidget {
  const ExampleHomePage({super.key});

  @override
  State<ExampleHomePage> createState() => _ExampleHomePageState();
}

class _ExampleHomePageState extends State<ExampleHomePage> {
  final _sdk = const PinelabsFlutterSdk();
  final _tokenController = TextEditingController();
  bool _isLoading = false;
  String? _message;

  @override
  void dispose() {
    _tokenController.dispose();
    super.dispose();
  }

  Future<void> _startPayment() async {
    final token = _tokenController.text.trim();
    if (token.isEmpty) {
      setState(() {
        _message = 'Order token is required.';
      });
      return;
    }

    setState(() {
      _isLoading = true;
      _message = null;
    });

    try {
      final result = await _sdk.startPayment(
        PinelabsPaymentRequest(
          orderToken: token,
          environment: PinelabsEnvironment.uat,
        ),
      );

      if (!mounted) {
        return;
      }

      setState(() {
        _message =
            'status: ${result.status.name}\norderId: ${result.orderId ?? '-'}\ncode: ${result.code ?? '-'}\nmessage: ${result.message ?? '-'}';
      });
    } catch (error) {
      if (!mounted) {
        return;
      }

      setState(() {
        _message = error.toString();
      });
    } finally {
      if (mounted) {
        setState(() {
          _isLoading = false;
        });
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Pine Labs SDK Example')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            TextField(
              controller: _tokenController,
              decoration: const InputDecoration(
                labelText: 'Order Token',
                border: OutlineInputBorder(),
              ),
            ),
            const SizedBox(height: 16),
            FilledButton(
              onPressed: _isLoading ? null : _startPayment,
              child: Text(_isLoading ? 'Processing...' : 'Start Payment'),
            ),
            if (_message != null) ...[
              const SizedBox(height: 16),
              Text(_message!),
            ],
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
98
downloads

Documentation

API reference

Publisher

verified publisherpinelabsonline.com

Weekly Downloads

Flutter wrapper for the Pine Labs Online iOS and Android SDKs. Provides a unified API for startPayment across both platforms.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on pinelabs_native

Packages that implement pinelabs_native