Event Handler

    Event Handler


    기사 요약

    handleNavigation

    Shoplive에서 상품, 배너 등을 선택(탭) 했을 때, 선택한 상품 또는 배너 정보를 전달합니다.

    Parameter name

    Type

    Description

    url

    URL

    상품 또는 배너 선택 시 이동할 URL

    Sample Code
    import 'package:shoplive_player/shoplive_player.dart';
    import 'package:url_launcher/url_launcher.dart';
    
    _shopLivePlayer.handleNavigation.listen((data) {
      print("handleNavigation ${data.url}");
      launchUrl(Uri.parse(data.url), mode: LaunchMode.externalApplication);
    });

    Coupon

    쿠폰 처리를 완료할 때 쿠폰 활성 여부를 설정하기 위한 상태입니다.

    sendCustomActionResult 메서드

    커스텀 동작 처리 결과를 Shoplive에 전달하기 위한 메서드입니다.

    Future<void> sendCustomActionResult({
      required String id,            // 커스텀 동작 ID
      required bool success,          // 커스텀 동작 처리 성공/실패
      required String message,        // 알림 메시지
      required String popupStatus,   // 완료 후 커스텀 동작 상태 ("SHOW", "HIDE", "KEEP")
      required String alertType,     // 알림 메시지 출력 타입 ("ALERT", "TOAST")
    })
    Sample Code
    // 쿠폰 다운로드 결과 전달
    await _shopLivePlayer.sendDownloadCouponResult(
      couponId: couponId,
      success: true,
      message: "Coupon download success!",
      popupStatus: "KEEP",    // "SHOW", "HIDE", "KEEP"
      alertType: "ALERT",     // "ALERT", "TOAST"
    );
    
    // 커스텀 액션 결과 전달
    await _shopLivePlayer.sendCustomActionResult(
      id: customActionId,
      success: true,
      message: "Custom action success!",
      popupStatus: "HIDE",    // "SHOW", "HIDE", "KEEP"
      alertType: "TOAST",     // "ALERT", "TOAST"
    );

    popupStatus

    Value

    Description

    SHOW

    쿠폰 다시 활성

    HIDE

    쿠폰 사라짐

    KEEP

    상태 유지

    alertType

    Value

    Description

    ALERT

    얼럿

    TOAST

    토스트


    handleDownloadCoupon

    Shoplive에서 쿠폰을 선택 했을 때 클라이언트로 쿠폰 정보를 전달합니다. 클라이언트의 쿠폰 처리 결괄르 Shoplive Flutter SDK 로 다시 전달하는 sendDownloadCouponResult 메서드를 통해 Shoplive Player에서의 쿠폰 상태를 설정합니다.

    sendDownloadCouponResult 메서드

    쿠폰 처리 결과를 Shoplive에 전달하기 위한 메서드입니다.

    Future<void> sendDownloadCouponResult({
      required String couponId,      // 쿠폰 ID
      required bool success,          // 쿠폰 처리 성공/실패 여부
      required String message,        // 알림 메시지
      required String popupStatus,   // 완료 후 쿠폰 상태 ("SHOW", "HIDE", "KEEP")
      required String alertType,     // 알림 메시지 출력 타입 ("ALERT", "TOAST")
    })
    import 'package:shoplive_player/shoplive_player.dart';
    import 'package:rxdart/rxdart.dart';
    
    class MainPage extends StatefulWidget {
      const MainPage({Key? key}) : super(key: key);
    
      @override
      State<MainPage> createState() => _MainPageState();
    }
    
    class _MainPageState extends State<MainPage> {
      late final ShopLivePlayer _shopLivePlayer = ShopLivePlayer();
      final CompositeSubscription _subscriptions = CompositeSubscription();
    
      @override
      void initState() {
        super.initState();
        _initListener();
      }
    
      void _initListener() {
        _shopLivePlayer.handleDownloadCoupon.listen((data) async {
          await handleDownloadCoupon(data.couponId);
        }).addTo(_subscriptions);
      }
    
      Future<void> handleDownloadCoupon(String couponId) async {
        print("handleDownloadCoupon: $couponId");
        
        // 쿠폰 처리 완료 시 호출 (처리 결과)
        
        // 성공
        await _shopLivePlayer.sendDownloadCouponResult(
          couponId: couponId,
          success: true,
          message: "쿠폰 다운로드가 성공하였습니다.",
          popupStatus: "SHOW",
          alertType: "ALERT",
        );
        
        // 실패
        // await _shopLivePlayer.sendDownloadCouponResult(
        //   couponId: couponId,
        //   success: false,
        //   message: "쿠폰 다운로드가 실패하였습니다.",
        //   popupStatus: "HIDE",
        //   alertType: "TOAST",
        // );
      }
    
      @override
      void dispose() {
        _subscriptions.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('Shoplive Example')),
          body: const Center(child: Text('Shoplive')),
        );
      }
    }

    handleCustomAction

    팝업에서 클릭 이벤트를 custom으로 지정하고, 팝업을 선택(탭) 했을 때 팝업 정보를 전달합니다. 팝업의 idtype (COUPONBANNERNOTICE), payload를 전달합니다.

    Parameter name

    Type

    Description

    id

    String

    팝업 ID

    type

    String

    팝업 타입: COUPON, BANNER, NOTICE

    payload

    String

    사용자 정의 데이터(JSON 문자열)

    _shopLivePlayer.handleCustomAction.listen((data) async {
      print("handleCustomAction ${data.id} ${data.type} ${data.payload}");
      
      // 팝업 처리가 완료되면 호출됨(처리 결과)
      
      // 성공
      await _shopLivePlayer.sendCustomActionResult(
        id: data.id,
        success: true,
        message: "Coupon download was successful.",
        popupStatus: "SHOW",
        alertType: "ALERT",
      );
      
      // 실패
      // await _shopLivePlayer.sendCustomActionResult(
      //   id: data.id,
      //   success: false,
      //   message: "Coupon download was failed.",
      //   popupStatus: "HIDE",
      //   alertType: "TOAST",
      // );
    });

    handleReceviedCommand

    Shoplive Flutter SDK의 WEB으로부터 수신된 명령어 정보를 전달합니다.

    receivedCommand.listen((data) { ... })

    Parameter name

    Type

    Description

    command

    String

    명령어 이름

    data

    Map<String, dynamic>

    명령어와 함께 전달되는 데이터

    Sample Code
    _shopLivePlayer.receivedCommand.listen((data) {
      switch (data.command) {
        case "LOGIN_REQUIRED":
          // 로그인 화면으로 이동
          // 로그인이 성공하면, 인증 사용자 계정을 연동하여 샵라이브플레이어를 다시 호출
          _shopLivePlayer.startPictureInPicture();
          // 로그인 화면으로 이동하는 로직
          break;
          
        case "CLICK_PRODUCT_CART":
          // 장바구니 처리 로직
          break;
          
        default:
          break;
      }
    });

    setShareScheme

    공유하기를 선택(탭) 했을 때 시스템 공유 팝업으로 전달할 scheme을 설정합니다. shareDelegate를 설정하면 iOS 시스템 공유 팝업 대신 직접 커스텀 공유 팝업을 구현할 수 있습니다.

    void setShareScheme({
      required String shareSchemeUrl,
    })

    Parameter name

    Type

    Description

    scheme

    String?

    공유할 scheme 또는 URL

    Sample Code
    import 'package:shoplive_player/shoplive_player.dart';
    
    class MainPage extends StatefulWidget {
      const MainPage({Key? key}) : super(key: key);
    
      @override
      State<MainPage> createState() => _MainPageState();
    }
    
    class _MainPageState extends State<MainPage> {
      late final ShopLivePlayer _shopLivePlayer = ShopLivePlayer();
    
      @override
      void initState() {
        super.initState();
        
        // URI Scheme
        String scheme = "shoplive://live";
        // 또는 URL
        // String scheme = "https://shoplive.cloud/live";
        
        // iOS/Android 시스템 공유 팝업
        _shopLivePlayer.setShareScheme(shareSchemeUrl: scheme);
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('Shoplive Example')),
          body: const Center(child: Text('Shoplive')),
        );
      }
    }


    What's Next