1- import 'package:flutter/material.dart' ;
21import 'dart:async' ;
3-
2+ import 'package:flutter/material.dart' ;
43import 'package:flutter/services.dart' ;
4+
55import 'package:flutter_crypto_algorithm/flutter_crypto_algorithm.dart' ;
66
77void main () {
@@ -16,34 +16,36 @@ class MyApp extends StatefulWidget {
1616}
1717
1818class _MyAppState extends State <MyApp > {
19- String _platformVersion = 'Unknown' ;
19+ String _encrypt = 'Unknown' ;
20+ String _decrypt = 'Unknown' ;
2021 final _flutterCryptoAlgorithmPlugin = FlutterCryptoAlgorithm ();
2122
2223 @override
2324 void initState () {
2425 super .initState ();
25- initPlatformState ();
26+ crypto ();
2627 }
2728
2829 // Platform messages are asynchronous, so we initialize in an async method.
29- Future <void > initPlatformState () async {
30- String platformVersion;
31- // Platform messages may fail, so we use a try/catch PlatformException.
32- // We also handle the message potentially returning null.
30+ Future <void > crypto () async {
31+ String encrypt;
32+ String decrypt;
3333 try {
34- platformVersion =
35- await _flutterCryptoAlgorithmPlugin.getPlatformVersion () ?? 'Unknown platform version' ;
34+ encrypt =
35+ await _flutterCryptoAlgorithmPlugin.encrypt ('Hello123' , 'Hello' ) ??
36+ 'Unknown encrypt' ;
37+ decrypt = await _flutterCryptoAlgorithmPlugin.decrypt (encrypt, 'Hello' ) ??
38+ 'Unknown decrypt' ;
3639 } on PlatformException {
37- platformVersion = 'Failed to get platform version.' ;
40+ encrypt = 'Failed encrypt.' ;
41+ decrypt = 'Failed decrypt.' ;
3842 }
3943
40- // If the widget was removed from the tree while the asynchronous platform
41- // message was in flight, we want to discard the reply rather than calling
42- // setState to update our non-existent appearance.
4344 if (! mounted) return ;
4445
4546 setState (() {
46- _platformVersion = platformVersion;
47+ _encrypt = encrypt;
48+ _decrypt = decrypt;
4749 });
4850 }
4951
@@ -52,12 +54,61 @@ class _MyAppState extends State<MyApp> {
5254 return MaterialApp (
5355 home: Scaffold (
5456 appBar: AppBar (
55- title: const Text ('Plugin example app ' ),
57+ title: const Text ('Flutter Crypto Algorithm ' ),
5658 ),
57- body: Center (
58- child: Text ('Running on: $_platformVersion \n ' ),
59+ body: SingleChildScrollView (
60+ child: Column (
61+ children: [
62+ Section (title: 'AES' , children: [
63+ _buildText ('Encrypt: ' , _encrypt),
64+ _buildText ('Decrypt: ' , _decrypt),
65+ ]),
66+ ],
67+ ),
5968 ),
6069 ),
6170 );
6271 }
72+
73+ Widget _buildText (String label, String value) {
74+ return Text .rich (
75+ overflow: TextOverflow .ellipsis,
76+ maxLines: 2 ,
77+ TextSpan (
78+ text: label,
79+ style: const TextStyle (fontSize: 16 , fontWeight: FontWeight .bold, color: Colors .red),
80+ children: [
81+ TextSpan (
82+ text: value,
83+ style: const TextStyle (
84+ fontSize: 16 , fontWeight: FontWeight .normal, color: Colors .black),
85+ ),
86+ ],
87+ ),
88+ );
89+ }
90+ }
91+
92+ class Section extends StatelessWidget {
93+ final String title;
94+ final List <Widget > children;
95+
96+ const Section ({super .key, required this .title, required this .children});
97+
98+ @override
99+ Widget build (BuildContext context) {
100+ return Padding (
101+ padding: const EdgeInsets .all (16.0 ),
102+ child: Column (
103+ crossAxisAlignment: CrossAxisAlignment .start,
104+ children: [
105+ Text (
106+ title,
107+ style: const TextStyle (fontSize: 20 , fontWeight: FontWeight .bold),
108+ ),
109+ ...children,
110+ ],
111+ ),
112+ );
113+ }
63114}
0 commit comments