renderAgreement method

Future<AgreementWidgetControl> renderAgreement({
  1. required String selector,
  2. RenderAgreementOptions? options,
})

결제 약관 UI를 렌더링하는 메서드입니다. selector : 렌더링할 위젯의 식별자입니다. UI 트리에 추가한 AgreementWidget의 생성자에 넣은 값을 입력합니다. options : 약관 위젯의 렌더링 옵션입니다. UI 트리에 selector을 갖는 AgreementWidget이 없는 경우 Exception 을 발생시킵니다. 정상적으로 렌더링되면 AgreementWidgetControl의 Future를 반환합니다.

Implementation

Future<AgreementWidgetControl> renderAgreement({
  required String selector,
  RenderAgreementOptions? options,
}) {
  final completer = Completer<AgreementWidgetControl>();
  WidgetsBinding.instance.addPostFrameCallback((_) async {
    final paymentAgreementKey = _widgetKeyMap[selector];
    if (paymentAgreementKey is! GlobalKey<PaymentAgreementWidgetState>) {
      throw Exception('AgreementWidget with selector \'$selector\' does not exist.');
    }
    (paymentAgreementKey.currentState?.renderAgreement(options: options) ??
            (throw Exception('Agreement is not rendered. Call \'renderAgreement\' method first.')))
        .then((value) {
      completer.complete(value);
    }, onError: (e) {
      completer.completeError(e);
    });
  });
  return completer.future;
}