metamask 0.0.1 copy "metamask: ^0.0.1" to clipboard
metamask: ^0.0.1 copied to clipboard

Platformweb
outdated

sing in with metamask, connect to ethereum network

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MetaMask',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Metamask Login Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var metamask = MetaMask();

  void _loginWithMetaMask() {
    metamask.login().then((success) {
      setState(() {
        if (success) {
          debugPrint('MetaMask address: ${metamask.address}');
          debugPrint('MetaMask signature: ${metamask.signature}');
        } else {
          debugPrint('MetaMask login failed');
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (metamask.address != null) Text('address: ${metamask.address}'),
            if (metamask.signature != null) Text('signed: ${metamask.signature}'),
            Text(
              metamask.address == null ? 'You are not logged in' : 'You are logged in',
            ),
            Text('Metamask support ${metamask.isSupported}'),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _loginWithMetaMask,
        tooltip: 'Login',
        child: const Icon(Icons.login),
      ),
    );
  }
}
10
likes
130
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

sing in with metamask, connect to ethereum network

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, js

More

Packages that depend on metamask