|
import 'package:flutter/material.dart'; |
|
import 'encryption_service.dart'; |
|
|
|
void main() { |
|
runApp(const MyApp()); |
|
} |
|
|
|
class MyApp extends StatelessWidget { |
|
const MyApp({super.key}); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return MaterialApp( |
|
theme: ThemeData( |
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.lightBlue), |
|
useMaterial3: true, |
|
), |
|
home: const MyHomePage(title: 'String (d)e(n)cryption'), |
|
); |
|
} |
|
} |
|
|
|
class MyHomePage extends StatefulWidget { |
|
const MyHomePage({super.key, required this.title}); |
|
|
|
final String title; |
|
|
|
@override |
|
State<MyHomePage> createState() => _MyHomePageState(); |
|
} |
|
|
|
class _MyHomePageState extends State<MyHomePage> { |
|
final TextEditingController _inputController = TextEditingController(); |
|
final TextEditingController _keyController = TextEditingController(); |
|
String _result = ''; |
|
|
|
void _encrypt() { |
|
String input = _inputController.text; |
|
String key = _keyController.text; |
|
setState(() { |
|
_result = EncryptionService.encryptText(input, key); |
|
}); |
|
// _inputController.clear(); |
|
} |
|
|
|
void _decrypt() { |
|
String input = _inputController.text; |
|
String key = _keyController.text; |
|
setState(() { |
|
_result = EncryptionService.decryptText(input, key); |
|
}); |
|
} |
|
|
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
appBar: AppBar( |
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary, |
|
title: Text(widget.title), |
|
), |
|
body: Padding( |
|
padding: const EdgeInsets.all(16.0), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
spacing: 16, |
|
children: <Widget>[ |
|
TextField( |
|
controller: _inputController, |
|
decoration: InputDecoration( |
|
labelText: 'Input String', |
|
border: OutlineInputBorder(), |
|
), |
|
), |
|
TextField( |
|
controller: _keyController, |
|
decoration: InputDecoration( |
|
labelText: 'Secret Key', |
|
border: OutlineInputBorder(), |
|
), |
|
), |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly, |
|
children: [ |
|
ElevatedButton( |
|
onPressed: _encrypt, |
|
child: Text('Encrypt'), |
|
), |
|
ElevatedButton( |
|
onPressed: _decrypt, |
|
child: Text('Decrypt'), |
|
), |
|
], |
|
), |
|
Column( |
|
mainAxisAlignment: MainAxisAlignment.start, |
|
children: [ |
|
Row( |
|
spacing: 8, |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
Text( |
|
'Result:', |
|
style: |
|
TextStyle(fontSize: 18, fontWeight: FontWeight.bold), |
|
), |
|
Tooltip( |
|
message: 'Double Tap or long press to copy result', |
|
child: SelectableText( |
|
_result, |
|
style: TextStyle(fontSize: 16), |
|
toolbarOptions: ToolbarOptions(copy: true), |
|
), |
|
), |
|
], |
|
), |
|
Text( |
|
'(Double tap/Long press to copy)', |
|
style: TextStyle(fontSize: 12, color: Colors.grey), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
), |
|
); |
|
} |
|
} |