open method

  1. @override
Future<void> open({
  1. required BuildContext context,
  2. Web3ModalState? startState,
})
override

Opens the modal with the provided startState. If none is provided, the default state will be used based on platform.

Implementation

@override
Future<void> open({
  required BuildContext context,
  Web3ModalState? startState,
}) async {
  _checkInitialized();

  if (_isOpen) {
    return;
  }

  // If we aren't connected, connect!
  if (!_isConnected) {
    LoggerUtil.logger.i(
      'Connecting to WalletConnect, required namespaces: $_requiredNamespaces',
    );
    connectResponse = await web3App!.connect(
      requiredNamespaces: _requiredNamespaces,
    );
    _awaitConnectResponse();
  }

  // Reset the explorer
  explorerService.filterList(
    query: '',
  );

  this.context = context;

  final bool bottomSheet = Util.getPlatformType() == PlatformType.mobile ||
      Util.isMobileWidth(context);

  _isOpen = true;

  notifyListeners();

  if (bottomSheet) {
    await showModalBottomSheet(
      // enableDrag: false,
      backgroundColor: Colors.transparent,
      isDismissible: false,
      isScrollControlled: true,
      context: context,
      builder: (context) {
        return Web3Modal(
          service: this,
          toastService: _toastService,
          startState: startState,
        );
      },
    );
  } else {
    await showDialog(
      context: context,
      builder: (context) {
        return Web3Modal(
          service: this,
          toastService: _toastService,
          startState: startState,
        );
      },
    );
  }

  _isOpen = false;

  notifyListeners();
}