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

Flutter wrapper for Amber (Nostr Signer)

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:amberflutter/amberflutter.dart';
import 'package:dart_nostr/nostr/model/event/send_event.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _amberflutterPlugin = Amberflutter();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              FilledButton(
                onPressed: () async {
                  print('waiting for pk...');
                  String? pk = await _amberflutterPlugin.getPublicKey();
                  if (pk == null) {
                    print('pk is null');
                  } else {
                    print('pk $pk');
                  }
                },
                child: Text('Login with Amber'),
              ),
              FilledButton(
                onPressed: () async {
                  print('waiting to signEvent...');

                  final ev = {
                    'kind': 1,
                    'content': 'test from amber flutter!',
                    'pubkey':
                        '1bbd7fdf68eaf5c19446c3aaf63b39dd4a8e33548bc96f6bd239a4124d8f229e',
                    'createdAt': DateTime.now().millisecondsSinceEpoch / 1000
                  };

                  String? signedEvent = await _amberflutterPlugin.signEvent(
                    "npub1rw7hlhmgat6ur9zxcw40vweem49guv6530yk767j8xjpynv0y20q6qsl3w",
                    jsonEncode(ev),
                  );
                  if (signedEvent == null) {
                    print('ev is null');
                  } else {
                    print('signed event $signedEvent');
                  }
                },
                child: Text('Sign Event'),
              )
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
0
pub points
49%
popularity

Publisher

unverified uploader

Flutter wrapper for Amber (Nostr Signer)

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on amberflutter