billing_country 1.0.0
billing_country: ^1.0.0 copied to clipboard
Cross-platform Flutter plugin to get the App Store / Google Play billing country and gate third-party payments.
import 'package:billing_country/billing_country.dart';
import 'package:flutter/material.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 _country = 'Loading…';
bool _externalPaymentSupported = false;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
// Demo: drive the supported-country lists from a remote source. In a real
// app the fetcher would hit Firebase Remote Config / your backend; here it
// returns a static JSON string. Never throws.
await BillingCountry.updateFromRemote(
() async => '{"appStore":["US"],"playStore":["IN","RU","KR"]}',
);
final String? country = await BillingCountry.getCountryCode();
final bool supported = await BillingCountry.isExternalPaymentSupportedHere();
if (!mounted) return;
setState(() {
_country = country ?? 'Unknown';
_externalPaymentSupported = supported;
});
}
@override
Widget build(BuildContext context) {
final BillingStore store = BillingCountry.store;
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('billing_country example')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Store: ${store.name}'),
const SizedBox(height: 8),
Text('Billing country: $_country'),
const SizedBox(height: 8),
Text(
_externalPaymentSupported
? 'Third-party payment: supported here'
: 'Third-party payment: not configured for here',
),
const SizedBox(height: 16),
ElevatedButton(onPressed: _load, child: const Text('Reload')),
],
),
),
),
);
}
}