zipup_partners 0.0.6
zipup_partners: ^0.0.6 copied to clipboard
Flutter plugin that provides a WebView-based SDK using a native Android AAR and iOS XCFramework, with real-time message and event communication between WebView and Flutter.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:zipup_partners/zipup_sdk_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _zipupSdk = ZipupSdk();
String _status = 'Ready';
StreamSubscription<Map<String, dynamic>>? _eventSubscription;
@override
void initState() {
super.initState();
_setupEventListener();
}
@override
void dispose() {
_eventSubscription?.cancel();
_zipupSdk.removeEventListener();
super.dispose();
}
void _setupEventListener() {
print('Setting up event listener');
_eventSubscription = _zipupSdk.addEventListener(({required event, data}) {
print('Received event: $event, data: $data');
if (event == 'ping' && mounted) {
print('Ping received');
final navigatorContext = context;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
showDialog(
context: navigatorContext,
builder: (ctx) => AlertDialog(
title: const Text('Ping'),
content: const Text('Ping received'),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(),
child: const Text('OK'),
),
],
),
);
});
}
// 상태 업데이트
if (mounted) {
setState(() {
_status = 'Event: $event${data != null ? ' - $data' : ''}';
});
}
});
}
Future<void> _initSdk() async {
try {
setState(() {
_status = 'Initializing SDK...';
});
final result = await _zipupSdk.init(
'your_user_key',
'your_user_phone',
'your_proxy_url',
);
if (!mounted) return;
setState(() {
_status = result ?? 'Initialization failed';
});
} catch (e) {
if (!mounted) return;
setState(() {
_status = 'Error: $e';
});
}
}
Future<void> _viewSdk() async {
try {
setState(() {
_status = 'Opening SDK...';
});
final result = await _zipupSdk.open();
if (!mounted) return;
setState(() {
_status = result ?? 'Failed to open SDK';
});
} catch (e) {
if (!mounted) return;
setState(() {
_status = 'Error: $e';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Status: $_status',
style: const TextStyle(fontSize: 14, color: Colors.grey),
),
const SizedBox(height: 32),
ElevatedButton(
onPressed: _initSdk,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 32,
vertical: 16,
),
),
child: const Text('Initialize SDK'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _viewSdk,
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
horizontal: 32,
vertical: 16,
),
),
child: const Text('View Zipup SDK'),
),
],
),
),
),
),
);
}
}