airvoy 1.0.0
airvoy: ^1.0.0 copied to clipboard
Flutter SDK for Airvoy - Zero-rated eSIM connectivity for mobile apps. Give your users connectivity, keep your competitors offline.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:airvoy/airvoy.dart';
void main() {
runApp(const AirvoyExampleApp());
}
class AirvoyExampleApp extends StatelessWidget {
const AirvoyExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Airvoy SDK Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const ExampleHomePage(),
);
}
}
class ExampleHomePage extends StatefulWidget {
const ExampleHomePage({super.key});
@override
State<ExampleHomePage> createState() => _ExampleHomePageState();
}
class _ExampleHomePageState extends State<ExampleHomePage> {
// Initialize Airvoy client
// In production, get these from your secure config
late final Airvoy _airvoy;
Esim? _esim;
bool _loading = false;
String? _error;
String? _status;
@override
void initState() {
super.initState();
_airvoy = Airvoy(
apiKey: 'sk_live_your_api_key_here',
groupId: 'your-group-id-here',
);
}
Future<void> _createEsim() async {
setState(() {
_loading = true;
_error = null;
_status = 'Creating eSIM...';
});
try {
final esim = await _airvoy.createEsim();
setState(() {
_esim = esim;
_status = 'eSIM created successfully!';
_loading = false;
});
} on AirvoyException catch (e) {
setState(() {
_error = e.message;
_status = null;
_loading = false;
});
}
}
Future<void> _installEsim() async {
if (_esim == null) return;
setState(() => _status = 'Opening eSIM setup...');
try {
await _airvoy.installOnDevice(_esim!.activationCode);
setState(() => _status = 'eSIM setup opened');
} catch (e) {
setState(() => _error = e.toString());
}
}
Future<void> _refreshEsim() async {
if (_esim == null) return;
setState(() {
_loading = true;
_status = 'Refreshing...';
});
try {
final esim = await _airvoy.getEsim(_esim!.id);
setState(() {
_esim = esim;
_status = 'Refreshed';
_loading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_loading = false;
});
}
}
Future<void> _enableFullInternet() async {
if (_esim == null) return;
setState(() {
_loading = true;
_status = 'Enabling full internet...';
});
try {
final esim = await _airvoy.enableFullInternet(
_esim!.id,
dataLimitMb: 1024, // 1GB
);
setState(() {
_esim = esim;
_status = 'Full internet enabled!';
_loading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_loading = false;
});
}
}
Future<void> _disableFullInternet() async {
if (_esim == null) return;
setState(() {
_loading = true;
_status = 'Switching to restricted...';
});
try {
final esim = await _airvoy.disableFullInternet(_esim!.id);
setState(() {
_esim = esim;
_status = 'Back to restricted mode';
_loading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_loading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Airvoy SDK Example'),
actions: [
if (_esim != null)
IconButton(
icon: const Icon(Icons.refresh),
onPressed: _loading ? null : _refreshEsim,
),
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Status/Error messages
if (_status != null)
Container(
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.blue[50],
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
if (_loading)
const Padding(
padding: EdgeInsets.only(right: 12),
child: SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
Text(_status!),
],
),
),
if (_error != null)
Container(
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.red[50],
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Icon(Icons.error, color: Colors.red[700], size: 20),
const SizedBox(width: 8),
Expanded(child: Text(_error!, style: TextStyle(color: Colors.red[700]))),
],
),
),
// No eSIM yet - show create button
if (_esim == null) ...[
const Text(
'Welcome to Airvoy',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
const Text(
'Get free connectivity to essential apps while traveling. Upgrade anytime for full internet access.',
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: _loading ? null : _createEsim,
icon: const Icon(Icons.sim_card),
label: const Text('Activate Free eSIM'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
),
),
],
// eSIM exists - show card and controls
if (_esim != null) ...[
// eSIM Card widget
EsimCard(
airvoy: _airvoy,
esimId: _esim!.id,
onInstall: _installEsim,
onUpgrade: _esim!.fullInternet ? null : _enableFullInternet,
),
const SizedBox(height: 16),
// Manual controls
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Manual Controls',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 12),
// Install button
InstallButton(
activationCode: _esim!.activationCode,
onInstalled: () {
setState(() => _status = 'eSIM setup opened!');
},
onError: (e) {
setState(() => _error = e);
},
),
const SizedBox(height: 8),
// Toggle full internet
if (_esim!.fullInternet)
OutlinedButton.icon(
onPressed: _loading ? null : _disableFullInternet,
icon: const Icon(Icons.lock),
label: const Text('Switch to Restricted (Free)'),
)
else
ElevatedButton.icon(
onPressed: _loading ? null : _enableFullInternet,
icon: const Icon(Icons.rocket_launch),
label: const Text('Enable Full Internet (1GB)'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.purple,
foregroundColor: Colors.white,
),
),
],
),
),
),
const SizedBox(height: 16),
// Upsell banner (only show when restricted)
if (!_esim!.fullInternet)
UpsellBanner(
airvoy: _airvoy,
esimId: _esim!.id,
onSelectPackage: (package) {
// In a real app, you'd handle payment here
// then call enableFullInternet
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Confirm Purchase'),
content: Text(
'Buy ${package.dataFormatted} for ${package.priceFormatted}?',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Cancel'),
),
ElevatedButton(
onPressed: () {
Navigator.pop(ctx);
_airvoy.enableFullInternet(
_esim!.id,
dataLimitMb: package.dataMb,
).then((esim) {
setState(() {
_esim = esim;
_status = 'Full internet activated!';
});
});
},
child: const Text('Buy'),
),
],
),
);
},
),
],
],
),
),
);
}
}