at_backupkey_flutter 3.1.2 copy "at_backupkey_flutter: ^3.1.2" to clipboard
at_backupkey_flutter: ^3.1.2 copied to clipboard

outdated

A Flutter plugin project for saving the backup key of any @‎sign that is being onboarded with @‎platform apps. The backup key can be used to authenticate in other @‎platform apps.

example/lib/main.dart

import 'dart:async';

import 'package:at_backupkey_flutter/at_backupkey_flutter.dart';
import 'package:at_client_mobile/at_client_mobile.dart';
import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart' as path_provider;

enum OnboardingState {
  initial,
  success,
  error,
}

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  OnboardingState onboardingState = OnboardingState.initial;
  Map<String, AtClientService> atClientServiceMap;
  String atsign;
  final String rootDomain = 'root.atsign.org';

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

  Future<AtClientPreference> getAtClientPreference() async {
    final appDocumentDirectory =
        await path_provider.getApplicationSupportDirectory();
    String path = appDocumentDirectory.path;
    var _atClientPreference = AtClientPreference()
      ..isLocalStoreRequired = true
      ..commitLogPath = path
      ..namespace = 'backupkeys'
      ..rootDomain = rootDomain
      ..hiveStoragePath = path;
    return _atClientPreference;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Builder(
          builder: (context) => Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              if (onboardingState == OnboardingState.initial)
                Center(
                  child: TextButton(
                    onPressed: () async {
                      var _atClientPreference = await getAtClientPreference();
                      Onboarding(
                        context: context,
                        domain: rootDomain,
                        appColor: Color.fromARGB(255, 240, 94, 62),
                        atClientPreference: _atClientPreference,
                        onboard: (map, atsign) {
                          this.atClientServiceMap = map;
                          this.atsign = atsign;
                          onboardingState = OnboardingState.success;
                          setState(() {});
                        },
                        onError: (error) {
                          onboardingState = OnboardingState.error;
                          setState(() {});
                        },
                      );
                    },
                    child: Text('Onboard my @sign'),
                  ),
                ),
              if (onboardingState == OnboardingState.error ||
                  onboardingState == OnboardingState.success)
                Center(
                  child: TextButton(
                    onPressed: () async {
                      await KeyChainManager.getInstance()
                          .clearKeychainEntries();
                      atsign = null;
                      atClientServiceMap = null;
                      onboardingState = OnboardingState.initial;
                      setState(() {});
                    },
                    child: Text('Clear onboarded @sign'),
                  ),
                ),
              if (onboardingState == OnboardingState.success)
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(height: 32),
                    Text('Default button:'),
                    BackupKeyWidget(
                      atsign: this.atsign,
                      atClientService: this.atClientServiceMap[atsign],
                    ),
                    SizedBox(height: 16),
                    Text('Custom button:'),
                    ElevatedButton.icon(
                      icon: Icon(
                        Icons.file_copy,
                        color: Colors.white,
                      ),
                      label: Text('Backup your key'),
                      onPressed: () async {
                        BackupKeyWidget(
                          atsign: atsign,
                          atClientService: atClientServiceMap[atsign],
                        ).showBackupDialog(context);
                      },
                    ),
                  ],
                )
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
0
pub points
50%
popularity

Publisher

verified publisheratsign.org

A Flutter plugin project for saving the backup key of any @‎sign that is being onboarded with @‎platform apps. The backup key can be used to authenticate in other @‎platform apps.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

at_client_mobile, at_utils, file_saver, file_selector, file_selector_linux, file_selector_macos, file_selector_windows, flutter, path_provider, permission_handler, share_plus

More

Packages that depend on at_backupkey_flutter