package_signature 1.0.1 copy "package_signature: ^1.0.1" to clipboard
package_signature: ^1.0.1 copied to clipboard

PlatformAndroid

a easy way to get android package signature on flutter app.

example/lib/main.dart

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

import 'package:package_signature/package_signature.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _signatureSha256 = 'Unknown';
  String _signatureSha256Hex = 'Unknown';
  String _signatureSha1 = 'Unknown';
  String _signatureSha1Hex = 'Unknown';
  int _cost = 0;

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

  Future<void> initPlatformState() async {
    final n = DateTime.now();
    Signature? signature = await PackageSignature().signature;
    if (!mounted) return;

    setState(() {
      _cost = DateTime.now().difference(n).inMilliseconds;
      _signatureSha256 = signature?.sha256base64 ?? '';
      _signatureSha256Hex = signature?.sha256hex ?? '';
      _signatureSha1 = signature?.sha1base64 ?? '';
      _signatureSha1Hex = signature?.sha1hex ?? '';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light(useMaterial3: true),
      darkTheme: ThemeData.dark(useMaterial3: true),
      home: Scaffold(
        appBar: AppBar(
          title: const Text("App Signature"),
          actions: [
            IconButton(
              onPressed: initPlatformState,
              icon: const Icon(Icons.refresh),
            ),
          ],
        ),
        body: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Chip(label: Text("cost: $_cost ms")),
              const Chip(label: Text("SHA256")),
              Text(_signatureSha256),
              const SizedBox(height: 12),
              const Chip(label: Text("SHA256Hex")),
              Text(_signatureSha256Hex),
              const SizedBox(height: 12),
              const Chip(label: Text("SHA1")),
              Text(_signatureSha1),
              const SizedBox(height: 12),
              const Chip(label: Text("SHA1 Hex")),
              Text(_signatureSha1Hex),
            ],
          ),
        ),
      ),
    );
  }
}
9
likes
140
points
328
downloads

Publisher

verified publisherlaihz.tech

Weekly Downloads

a easy way to get android package signature on flutter app.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

convert, crypto, flutter

More

Packages that depend on package_signature