web3_webview 1.0.10 copy "web3_webview: ^1.0.10" to clipboard
web3_webview: ^1.0.10 copied to clipboard

web3_webview is a powerful bridge between a DApp running inside a WebView and your Flutter application, enabling secure and seamless two-way communication between them

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:web3_webview/web3_webview.dart';

/// Example app for `web3_webview`.
///
/// Loads `privateKey` from secure storage in production – here a placeholder.
/// Do NOT hardcode keys in real apps.
void main() => runApp(const ExampleApp());

/// Root widget.
class ExampleApp extends StatelessWidget {
  /// Creates example app.
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'web3_webview example',
      home: Scaffold(
        appBar: AppBar(title: const Text('web3_webview example')),
        body: const DappView(),
      ),
    );
  }
}

/// DApp WebView with EIP-1193 bridge.
class DappView extends StatefulWidget {
  /// Creates view.
  const DappView({super.key});

  @override
  State<DappView> createState() => _DappViewState();
}

class _DappViewState extends State<DappView> {
  // In production, load from flutter_secure_storage.
  static const _demoPk =
      '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef';

  late final NetworkConfig _eth = NetworkConfig(
    chainId: '0x1',
    chainName: 'Ethereum Mainnet',
    nativeCurrency: NativeCurrency(name: 'Ether', symbol: 'ETH', decimals: 18),
    rpcUrls: ['https://mainnet.infura.io/v3/YOUR_KEY'],
    blockExplorerUrls: ['https://etherscan.io'],
  );

  @override
  Widget build(BuildContext context) {
    return Web3WebView(
      web3WalletConfig: Web3WalletConfig(
        privateKey: _demoPk,
        currentNetwork: _eth,
        supportNetworks: [_eth],
        name: 'Example Wallet',
        id: 'com.example.web3example',
        onError: (method, params, message) =>
            debugPrint('onError $method: $message'),
      ),
      initialUrlRequest:
          URLRequest(url: WebUri('https://metamask.github.io/test-dapp/')),
      // Default DENY – grant selectively if needed
      onPermissionRequest: (controller, request) async => PermissionResponse(
        resources: request.resources,
        action: PermissionResponseAction.DENY,
      ),
    );
  }
}
7
likes
0
points
62
downloads

Publisher

verified publisherdatit309.is-a.dev

Weekly Downloads

web3_webview is a powerful bridge between a DApp running inside a WebView and your Flutter application, enabling secure and seamless two-way communication between them

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, flutter_inappwebview, hex, http, intl, modal_bottom_sheet, uuid, web3dart

More

Packages that depend on web3_webview