|
8 | 8 | A Flutter package for secure encryption algorithms, providing efficient tools for data protection and encryption operations
|
9 | 9 |
|
10 | 10 | ## Installation
|
11 |
| -Run this command: |
12 |
| -With Flutter: |
| 11 | +Run this command with Flutter: |
13 | 12 | ```sh
|
14 | 13 | flutter pub add encryption_algorithm
|
15 | 14 | ```
|
16 | 15 |
|
| 16 | +## Usage |
| 17 | +### Methods |
| 18 | +#### 🚀 AES |
| 19 | +```dart |
| 20 | +import 'package:flutter_crypto_algorithm/flutter_crypto_algorithm.dart'; |
| 21 | +``` |
| 22 | +```dart |
| 23 | +void main() { |
| 24 | + runApp(const MyApp()); |
| 25 | +} |
| 26 | +
|
| 27 | +class MyApp extends StatefulWidget { |
| 28 | + const MyApp({super.key}); |
| 29 | +
|
| 30 | + @override |
| 31 | + State<MyApp> createState() => _MyAppState(); |
| 32 | +} |
| 33 | +
|
| 34 | +class _MyAppState extends State<MyApp> { |
| 35 | + String _encrypt = ''; |
| 36 | + String _decrypt = ''; |
| 37 | + final _crypto = Crypto(); |
| 38 | +
|
| 39 | + @override |
| 40 | + void initState() { |
| 41 | + super.initState(); |
| 42 | + crypto(); |
| 43 | + } |
| 44 | +
|
| 45 | + // Platform messages are asynchronous, so we initialize in an async method. |
| 46 | + Future<void> crypto() async { |
| 47 | + String encrypt; |
| 48 | + String decrypt; |
| 49 | + try { |
| 50 | + encrypt = |
| 51 | + await _crypto.encrypt('Hello123', 'Hello') ?? |
| 52 | + 'Unknown encrypt'; |
| 53 | + decrypt = await _crypto.decrypt(encrypt, 'Hello') ?? |
| 54 | + 'Unknown decrypt'; |
| 55 | + } on PlatformException { |
| 56 | + encrypt = 'Failed encrypt.'; |
| 57 | + decrypt = 'Failed decrypt.'; |
| 58 | + } |
| 59 | + if (!mounted) return; |
| 60 | + setState(() { |
| 61 | + _encrypt = encrypt; |
| 62 | + _decrypt = decrypt; |
| 63 | + }); |
| 64 | + } |
| 65 | +
|
| 66 | + @override |
| 67 | + Widget build(BuildContext context) { |
| 68 | + return MaterialApp( |
| 69 | + home: Scaffold( |
| 70 | + appBar: AppBar( |
| 71 | + title: const Text('Flutter Crypto Algorithm'), |
| 72 | + ), |
| 73 | + body: SingleChildScrollView( |
| 74 | + child: Column( |
| 75 | + children: [ |
| 76 | + Section(title: 'AES', children: [ |
| 77 | + _buildText('Encrypt: ', _encrypt), |
| 78 | + _buildText('Decrypt: ', _decrypt), |
| 79 | + ]), |
| 80 | + ], |
| 81 | + ), |
| 82 | + ), |
| 83 | + ), |
| 84 | + ); |
| 85 | + } |
| 86 | +
|
| 87 | + Widget _buildText(String label, String value) { |
| 88 | + return Text.rich( |
| 89 | + overflow: TextOverflow.ellipsis, |
| 90 | + maxLines: 2, |
| 91 | + TextSpan( |
| 92 | + text: label, |
| 93 | + style: const TextStyle( |
| 94 | + fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red), |
| 95 | + children: [ |
| 96 | + TextSpan( |
| 97 | + text: value, |
| 98 | + style: const TextStyle( |
| 99 | + fontSize: 16, |
| 100 | + fontWeight: FontWeight.normal, |
| 101 | + color: Colors.black), |
| 102 | + ), |
| 103 | + ], |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
| 108 | +
|
| 109 | +class Section extends StatelessWidget { |
| 110 | + final String title; |
| 111 | + final List<Widget> children; |
| 112 | +
|
| 113 | + const Section({super.key, required this.title, required this.children}); |
| 114 | +
|
| 115 | + @override |
| 116 | + Widget build(BuildContext context) { |
| 117 | + return Padding( |
| 118 | + padding: const EdgeInsets.all(16.0), |
| 119 | + child: Column( |
| 120 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 121 | + children: [ |
| 122 | + Text( |
| 123 | + title, |
| 124 | + style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), |
| 125 | + ), |
| 126 | + ...children, |
| 127 | + ], |
| 128 | + ), |
| 129 | + ); |
| 130 | + } |
| 131 | +} |
| 132 | +``` |
17 | 133 |
|
18 | 134 | ## Getting Started
|
19 | 135 |
|
|
0 commit comments