zipup_partners 0.0.20 copy "zipup_partners: ^0.0.20" to clipboard
zipup_partners: ^0.0.20 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;

  /// getConfig()에서 받은 safeArea (px). null이면 패딩 미적용.
  Map<String, dynamic>? _safeArea;

  @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',
      );

      // final testResult = await _zipupSdk.test('http://10.177.195.98:3005');
      // print('testResult: $testResult');

      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();
      debugPrint('[Zipup] open() returned: $result');

      final config = await _zipupSdk.getConfig();

      if (!mounted) return;

      setState(() {
        _status = result ?? 'Failed to open SDK';
        _safeArea = config != null && config['safeArea'] != null
            ? Map<String, dynamic>.from(config['safeArea'] as Map)
            : null;
      });
    } catch (e) {
      if (!mounted) return;
      setState(() {
        _status = 'Error: $e';
      });
    }
  }

  EdgeInsets get _safeAreaPadding {
    if (_safeArea == null) return EdgeInsets.zero;
    final num top = _safeArea!['top'] ?? 0;
    final num bottom = _safeArea!['bottom'] ?? 0;
    final num left = _safeArea!['left'] ?? 0;
    final num right = _safeArea!['right'] ?? 0;
    return EdgeInsets.fromLTRB(
      left.toDouble(),
      top.toDouble(),
      right.toDouble(),
      bottom.toDouble(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Padding(
          padding: _safeAreaPadding,
          child: Center(
            child: SingleChildScrollView(
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  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'),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
145
points
869
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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.

Homepage

License

MIT (license)

Dependencies

flutter, plugin_platform_interface, url_launcher

More

Packages that depend on zipup_partners

Packages that implement zipup_partners