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

Flutter sdk to support Peppermint functionality.

example/lib/main.dart

import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:peppermint_sdk/peppermint_sdk.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Peppermint SDK Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const CreateWalletPage(),
    );
  }
}

class CreateWalletPage extends StatefulWidget {
  const CreateWalletPage({Key? key}) : super(key: key);

  @override
  State<CreateWalletPage> createState() => _CreateWalletPageState();
}

class _CreateWalletPageState extends State<CreateWalletPage> {
  late WalletManager _manager;
  WalletKeys? _walletKeys;

  @override
  void initState() {
    _manager = WalletManager();
    super.initState();
  }

  _generateWallet() async {
    _walletKeys = await _manager.createWallet();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Create Wallet'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => Navigator.push(context,
            MaterialPageRoute(builder: (context) => const RestoreWalletPage())),
        tooltip: 'Restore wallet',
        child: const Icon(Icons.restore),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('Your public key / wallet address'),
            Text(_walletKeys?.publicKey ?? ''),
            const SizedBox(height: 16.0),
            const Text('Your private key'),
            InkWell(
              onTap: () {
                FlutterClipboard.copy(_walletKeys?.privateKey ?? '').then(
                  (value) {
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(
                        content: Text('Private key copied!'),
                      ),
                    );
                  },
                );
              },
              child: Text(_walletKeys?.privateKey ?? ''),
            ),
            const SizedBox(height: 16.0),
            InkWell(
              onTap: _generateWallet,
              child: Container(
                width: double.infinity,
                height: 44.0,
                color: Colors.blue,
                alignment: Alignment.center,
                child: const Text(
                  'Generate new Wallet',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class RestoreWalletPage extends StatefulWidget {
  const RestoreWalletPage({Key? key}) : super(key: key);

  @override
  State<RestoreWalletPage> createState() => _RestoreWalletPageState();
}

class _RestoreWalletPageState extends State<RestoreWalletPage> {
  TextEditingController controller = TextEditingController();
  String? walletAddress;
  late WalletManager manager;

  @override
  void initState() {
    manager = WalletManager();
    super.initState();
  }

  void _restoreWallet() async {
    walletAddress = await manager.restoreWallet(controller.text);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Restore Wallet'),
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextFormField(
                controller: controller,
                decoration: const InputDecoration(
                  hintText: 'insert your private key',
                ),
              ),
              const SizedBox(height: 16.0),
              Text(walletAddress ?? ''),
              const SizedBox(height: 16.0),
              InkWell(
                onTap: _restoreWallet,
                child: Container(
                  width: double.infinity,
                  height: 44.0,
                  color: Colors.blue,
                  alignment: Alignment.center,
                  child: const Text(
                    'Generate new Wallet',
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Flutter sdk to support Peppermint functionality.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_secure_storage, web3dart

More

Packages that depend on peppermint_sdk