paywit 0.1.0
paywit: ^0.1.0 copied to clipboard
Accept USDC payments in your Flutter app. Creates a Paywit payment, opens the hosted checkout, and returns the settled result — no native setup required.
import 'package:flutter/material.dart';
import 'package:paywit/paywit.dart';
// Both values come from your Paywit dashboard.
const publishableKey = String.fromEnvironment('PAYWIT_PUBLISHABLE_KEY');
const apiBaseUrl = String.fromEnvironment('PAYWIT_API_BASE_URL');
void main() => runApp(const ExampleApp());
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
late final Paywit _paywit = Paywit(
publishableKey: publishableKey,
apiBaseUrl: apiBaseUrl,
);
String _message = 'Tap to pay 1 USDC.';
@override
void dispose() {
_paywit.dispose();
super.dispose();
}
void _show(String message) => setState(() => _message = message);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Paywit example',
theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
home: Scaffold(
appBar: AppBar(title: const Text('Paywit example')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_message, textAlign: TextAlign.center),
const SizedBox(height: 24),
PaywitButton(
paywit: _paywit,
amount: 1,
description: 'Example order',
onResult: (result) => _show(
switch (result.status) {
PaymentStatus.paid => 'Paid. Thank you!',
PaymentStatus.expired => 'The payment window closed.',
PaymentStatus.canceled => 'Checkout dismissed.',
_ => 'Payment ${result.status.name}.',
},
),
onError: (error) => _show(error.message),
),
],
),
),
),
),
);
}
}