flutter_crypto_algorithm 0.1.0 copy "flutter_crypto_algorithm: ^0.1.0" to clipboard
flutter_crypto_algorithm: ^0.1.0 copied to clipboard

A Flutter package for secure encryption algorithms, providing efficient tools for data protection and encryption operations

example/lib/main.dart

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

import 'package:flutter_crypto_algorithm/flutter_crypto_algorithm.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  String _encrypt = '';
  String _decrypt = '';
  final _crypto = Crypto();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> crypto() async {
    String encrypt;
    String decrypt;
    try {
      encrypt =
          await _crypto.encrypt('Hello123', 'Hello') ??
              'Unknown encrypt';
      decrypt = await _crypto.decrypt(encrypt, 'Hello') ??
          'Unknown decrypt';
    } on PlatformException {
      encrypt = 'Failed encrypt.';
      decrypt = 'Failed decrypt.';
    }

    if (!mounted) return;

    print('encrypt: $encrypt');

    setState(() {
      _encrypt = encrypt;
      _decrypt = decrypt;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Crypto Algorithm'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: [
              Section(title: 'AES', children: [
                _buildText('Encrypt: ', _encrypt),
                _buildText('Decrypt: ', _decrypt),
              ]),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildText(String label, String value) {
    return Text.rich(
      overflow: TextOverflow.ellipsis,
      maxLines: 2,
      TextSpan(
        text: label,
        style: const TextStyle(
            fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red),
        children: [
          TextSpan(
            text: value,
            style: const TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.normal,
                color: Colors.black),
          ),
        ],
      ),
    );
  }
}

class Section extends StatelessWidget {
  final String title;
  final List<Widget> children;

  const Section({super.key, required this.title, required this.children});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            title,
            style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
          ),
          ...children,
        ],
      ),
    );
  }
}
1
likes
150
points
15
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for secure encryption algorithms, providing efficient tools for data protection and encryption operations

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_crypto_algorithm