This commit is contained in:
parent
3f6ea2e332
commit
4062ae75d3
1
dialer/android/.gitignore
vendored
1
dialer/android/.gitignore
vendored
@ -5,6 +5,7 @@ gradle-wrapper.jar
|
||||
/gradlew.bat
|
||||
/local.properties
|
||||
GeneratedPluginRegistrant.java
|
||||
gradle.properties
|
||||
|
||||
# Remember to never publicly share your keystore.
|
||||
# See https://flutter.dev/to/reference-keystore
|
||||
|
@ -2,5 +2,4 @@ org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryErro
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
dev.steenbakker.mobile_scanner.useUnbundled=true
|
||||
org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-amd64
|
||||
#org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-17.0.13.0.11-3.fc41.x86_64
|
||||
org.gradle.java.home=/usr/lib/jvm/java-17-openjdk-17.0.13.0.11-3.fc41.x86_64
|
||||
|
@ -1,99 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'contact_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'contact_service.dart';
|
||||
|
||||
class ContactState extends StatefulWidget {
|
||||
final Widget child;
|
||||
class ContactState extends StatefulWidget {
|
||||
final Widget child;
|
||||
|
||||
const ContactState({super.key, required this.child});
|
||||
const ContactState({super.key, required this.child});
|
||||
|
||||
static _ContactStateState of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<_InheritedContactState>()!.data;
|
||||
}
|
||||
|
||||
@override
|
||||
_ContactStateState createState() => _ContactStateState();
|
||||
}
|
||||
|
||||
class _ContactStateState extends State<ContactState> {
|
||||
final ContactService _contactService = ContactService();
|
||||
List<Contact> _contacts = [];
|
||||
bool _loading = true;
|
||||
double _scrollOffset = 0.0;
|
||||
Contact? _selfContact = Contact();
|
||||
|
||||
List<Contact> get contacts => _contacts;
|
||||
bool get loading => _loading;
|
||||
double get scrollOffset => _scrollOffset;
|
||||
Contact? get selfContact => _selfContact;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchContacts();
|
||||
|
||||
// Add listener for contact changes
|
||||
FlutterContacts.addListener(_onContactChange);
|
||||
}
|
||||
|
||||
void _onContactChange() => _fetchContacts();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Remove listener
|
||||
FlutterContacts.removeListener(_onContactChange);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchContacts() async {
|
||||
List<Contact> contacts = await _contactService.fetchContacts();
|
||||
|
||||
debugPrint("Fetched ${contacts.length} contacts");
|
||||
|
||||
// Find selfContact before filtering
|
||||
_selfContact = contacts.firstWhere(
|
||||
(contact) => contact.displayName.toLowerCase() == "user",
|
||||
orElse: () => Contact(),
|
||||
);
|
||||
if (_selfContact!.phones.isEmpty) {
|
||||
debugPrint("Self contact has no phone numbers");
|
||||
_selfContact = null;
|
||||
static _ContactStateState of(BuildContext context) {
|
||||
return context.dependOnInheritedWidgetOfExactType<_InheritedContactState>()!.data;
|
||||
}
|
||||
|
||||
contacts = contacts.where((contact) => contact.phones.isNotEmpty).toList();
|
||||
contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
|
||||
setState(() {
|
||||
_contacts = contacts;
|
||||
_loading = false;
|
||||
_selfContact = _selfContact;
|
||||
});
|
||||
@override
|
||||
_ContactStateState createState() => _ContactStateState();
|
||||
}
|
||||
|
||||
Future<void> addNewContact(Contact contact) async {
|
||||
await _contactService.addNewContact(contact);
|
||||
await _fetchContacts();
|
||||
class _ContactStateState extends State<ContactState> {
|
||||
final ContactService _contactService = ContactService();
|
||||
List<Contact> _contacts = [];
|
||||
bool _loading = true;
|
||||
double _scrollOffset = 0.0;
|
||||
Contact? _selfContact = Contact();
|
||||
|
||||
List<Contact> get contacts => _contacts;
|
||||
bool get loading => _loading;
|
||||
double get scrollOffset => _scrollOffset;
|
||||
Contact? get selfContact => _selfContact;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchContacts();
|
||||
|
||||
// Add listener for contact changes
|
||||
FlutterContacts.addListener(_onContactChange);
|
||||
}
|
||||
|
||||
void _onContactChange() => _fetchContacts();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Remove listener
|
||||
FlutterContacts.removeListener(_onContactChange);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchContacts() async {
|
||||
List<Contact> contacts = await _contactService.fetchContacts();
|
||||
|
||||
debugPrint("Fetched ${contacts.length} contacts");
|
||||
|
||||
// Find selfContact before filtering
|
||||
_selfContact = contacts.firstWhere(
|
||||
(contact) => contact.displayName.toLowerCase() == "user",
|
||||
orElse: () => Contact(),
|
||||
);
|
||||
if (_selfContact!.phones.isEmpty) {
|
||||
debugPrint("Self contact has no phone numbers");
|
||||
_selfContact = null;
|
||||
}
|
||||
|
||||
contacts = contacts.where((contact) => contact.phones.isNotEmpty).toList();
|
||||
contacts.sort((a, b) => a.displayName.compareTo(b.displayName));
|
||||
setState(() {
|
||||
_contacts = contacts;
|
||||
_loading = false;
|
||||
_selfContact = _selfContact;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> addNewContact(Contact contact) async {
|
||||
await _contactService.addNewContact(contact);
|
||||
await _fetchContacts();
|
||||
}
|
||||
|
||||
void setScrollOffset(double offset) {
|
||||
setState(() {
|
||||
_scrollOffset = offset;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _InheritedContactState(
|
||||
data: this,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void setScrollOffset(double offset) {
|
||||
setState(() {
|
||||
_scrollOffset = offset;
|
||||
});
|
||||
class _InheritedContactState extends InheritedWidget {
|
||||
final _ContactStateState data;
|
||||
|
||||
const _InheritedContactState({required this.data, required super.child});
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(_InheritedContactState oldWidget) => true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _InheritedContactState(
|
||||
data: this,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InheritedContactState extends InheritedWidget {
|
||||
final _ContactStateState data;
|
||||
|
||||
const _InheritedContactState({required this.data, required super.child});
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(_InheritedContactState oldWidget) => true;
|
||||
}
|
||||
|
@ -3,12 +3,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:intl/intl.dart'; // For date formatting
|
||||
import 'package:url_launcher/url_launcher.dart'; // For launching URLs (phone calls, SMS)
|
||||
import 'package:dialer/features/contacts/contact_state.dart';
|
||||
|
||||
// Import the helper functions
|
||||
import 'package:dialer/widgets/username_color_generator.dart';
|
||||
import 'package:dialer/widgets/color_darkener.dart';
|
||||
|
||||
class History {
|
||||
final Contact contact;
|
||||
final DateTime date;
|
||||
final String callType; // 'incoming' or 'outgoing'
|
||||
final String callType; // 'incoming' or 'outgoing'
|
||||
final String callStatus; // 'missed' or 'answered'
|
||||
final int attempts;
|
||||
|
||||
@ -32,6 +37,9 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
List<History> histories = [];
|
||||
bool loading = true;
|
||||
|
||||
// Track expanded items
|
||||
int? _expandedIndex;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@ -116,34 +124,113 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
itemBuilder: (context, index) {
|
||||
final history = histories[index];
|
||||
final contact = history.contact;
|
||||
final isExpanded = _expandedIndex == index;
|
||||
|
||||
return ListTile(
|
||||
leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
|
||||
? CircleAvatar(
|
||||
backgroundImage: MemoryImage(contact.thumbnail!),
|
||||
)
|
||||
: CircleAvatar(
|
||||
child: Text(
|
||||
contact.displayName.isNotEmpty
|
||||
? contact.displayName[0]
|
||||
: '?',
|
||||
// Generate the avatar color using the same logic as the contacts page
|
||||
Color avatarColor = generateColorFromName(contact.displayName);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: (contact.thumbnail != null && contact.thumbnail!.isNotEmpty)
|
||||
? CircleAvatar(
|
||||
backgroundImage: MemoryImage(contact.thumbnail!),
|
||||
)
|
||||
: CircleAvatar(
|
||||
backgroundColor: avatarColor,
|
||||
child: Text(
|
||||
contact.displayName.isNotEmpty
|
||||
? contact.displayName[0].toUpperCase()
|
||||
: '?',
|
||||
style: TextStyle(color: darken(avatarColor, 0.4)),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
contact.displayName,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
'${history.callType} - ${history.callStatus} - ${DateFormat('MMM dd, hh:mm a').format(history.date)}',
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${history.attempts}x',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.phone, color: Colors.green),
|
||||
onPressed: () async {
|
||||
if (contact.phones.isNotEmpty) {
|
||||
final Uri callUri =
|
||||
Uri(scheme: 'tel', path: contact.phones.first.number);
|
||||
if (await canLaunchUrl(callUri)) {
|
||||
await launchUrl(callUri);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Could not launch call')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Contact has no phone number')),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_expandedIndex = isExpanded ? null : index;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
contact.displayName,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
'${history.callType} - ${history.callStatus} - ${DateFormat('MMM dd, hh:mm a').format(history.date)}',
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Text(
|
||||
'${history.attempts}x',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
onTap: () {
|
||||
// Handle tap event if needed
|
||||
},
|
||||
if (isExpanded)
|
||||
Container(
|
||||
color: Colors.grey[850],
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (contact.phones.isNotEmpty) {
|
||||
final Uri smsUri =
|
||||
Uri(scheme: 'sms', path: contact.phones.first.number);
|
||||
if (await canLaunchUrl(smsUri)) {
|
||||
await launchUrl(smsUri);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Could not send message')),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Contact has no phone number')),
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.message, color: Colors.white),
|
||||
label:
|
||||
const Text('Message', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
// Implement block number functionality
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Number blocked (functionality not implemented)')),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.block, color: Colors.white),
|
||||
label: const Text('Block', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
|
@ -15,7 +15,8 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 4, vsync: this, initialIndex: 1);
|
||||
// Set the TabController length to 3
|
||||
_tabController = TabController(length: 3, vsync: this, initialIndex: 1);
|
||||
_tabController.addListener(_handleTabIndex);
|
||||
_fetchContacts();
|
||||
}
|
||||
@ -60,7 +61,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
backgroundColor: Colors.black,
|
||||
body: Column(
|
||||
children: [
|
||||
// Persistent Search Bar
|
||||
// Search Bar and 3-dot menu
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 24.0,
|
||||
@ -68,68 +69,97 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
left: 16.0,
|
||||
right: 16.0,
|
||||
),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromARGB(255, 30, 30, 30),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
left: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
right: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
bottom: BorderSide(color: Colors.grey.shade800, width: 2),
|
||||
),
|
||||
),
|
||||
child: SearchAnchor(
|
||||
builder: (BuildContext context, SearchController controller) {
|
||||
return SearchBar(
|
||||
controller: controller,
|
||||
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
|
||||
const EdgeInsets.only(
|
||||
top: 6.0,
|
||||
bottom: 6.0,
|
||||
left: 16.0,
|
||||
right: 16.0,
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromARGB(255, 30, 30, 30),
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
left: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
right: BorderSide(color: Colors.grey.shade800, width: 1),
|
||||
bottom:
|
||||
BorderSide(color: Colors.grey.shade800, width: 2),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
controller.openView();
|
||||
_onSearchChanged('');
|
||||
},
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
const Color.fromARGB(255, 30, 30, 30)),
|
||||
hintText: 'Search contacts',
|
||||
hintStyle: MaterialStateProperty.all(
|
||||
const TextStyle(color: Colors.grey, fontSize: 16.0),
|
||||
),
|
||||
leading: const Icon(
|
||||
Icons.search,
|
||||
color: Colors.grey,
|
||||
size: 24.0,
|
||||
),
|
||||
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
viewOnChanged: (query) {
|
||||
_onSearchChanged(query);
|
||||
},
|
||||
suggestionsBuilder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return _contactSuggestions.map((contact) {
|
||||
return ListTile(
|
||||
key: ValueKey(contact.id),
|
||||
title: Text(contact.displayName,
|
||||
style: const TextStyle(color: Colors.white)),
|
||||
onTap: () {
|
||||
controller.closeView(contact.displayName);
|
||||
child: SearchAnchor(
|
||||
builder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return SearchBar(
|
||||
controller: controller,
|
||||
padding:
|
||||
MaterialStateProperty.all<EdgeInsetsGeometry>(
|
||||
const EdgeInsets.only(
|
||||
top: 6.0,
|
||||
bottom: 6.0,
|
||||
left: 16.0,
|
||||
right: 16.0,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
controller.openView();
|
||||
_onSearchChanged('');
|
||||
},
|
||||
backgroundColor: MaterialStateProperty.all(
|
||||
const Color.fromARGB(255, 30, 30, 30)),
|
||||
hintText: 'Search contacts',
|
||||
hintStyle: MaterialStateProperty.all(
|
||||
const TextStyle(color: Colors.grey, fontSize: 16.0),
|
||||
),
|
||||
leading: const Icon(
|
||||
Icons.search,
|
||||
color: Colors.grey,
|
||||
size: 24.0,
|
||||
),
|
||||
shape:
|
||||
MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
viewOnChanged: (query) {
|
||||
_onSearchChanged(query);
|
||||
},
|
||||
suggestionsBuilder:
|
||||
(BuildContext context, SearchController controller) {
|
||||
return _contactSuggestions.map((contact) {
|
||||
return ListTile(
|
||||
key: ValueKey(contact.id),
|
||||
title: Text(contact.displayName,
|
||||
style: const TextStyle(color: Colors.white)),
|
||||
onTap: () {
|
||||
controller.closeView(contact.displayName);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
// 3-dot menu
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert, color: Colors.white),
|
||||
itemBuilder: (BuildContext context) => [
|
||||
const PopupMenuItem<String>(
|
||||
value: 'settings',
|
||||
child: Text('Settings'),
|
||||
),
|
||||
],
|
||||
onSelected: (String value) {
|
||||
if (value == 'settings') {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SettingsPage()),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Main content with TabBarView
|
||||
@ -142,7 +172,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
FavoritePage(),
|
||||
HistoryPage(),
|
||||
ContactPage(),
|
||||
SettingsPage(), // Add your SettingsPage here
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
@ -186,10 +215,6 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
icon: Icon(_tabController.index == 2
|
||||
? Icons.contacts
|
||||
: Icons.contacts_outlined)),
|
||||
Tab(
|
||||
icon: Icon(_tabController.index == 3 // Corrected index
|
||||
? Icons.settings
|
||||
: Icons.settings_outlined)),
|
||||
],
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: const Color.fromARGB(255, 158, 158, 158),
|
||||
|
@ -1,20 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'key_storage.dart';
|
||||
|
||||
class DeleteKeyPairPage extends StatelessWidget {
|
||||
const DeleteKeyPairPage({super.key});
|
||||
|
||||
void _deleteKeyPair(BuildContext context) {
|
||||
// Key deletion logic (not implemented here)
|
||||
// ...
|
||||
Future<void> _deleteKeyPair(BuildContext context) async {
|
||||
final keyStorage = KeyStorage();
|
||||
await keyStorage.deleteKeys();
|
||||
|
||||
// Show confirmation message
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('The key pair has been deleted.'),
|
||||
),
|
||||
);
|
||||
|
||||
// Navigate back or update the UI as needed
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ import 'dart:typed_data';
|
||||
import 'dart:convert';
|
||||
import 'package:pointycastle/export.dart' as crypto;
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'dart:io';
|
||||
import 'key_storage.dart';
|
||||
|
||||
class ExportPrivateKeyPage extends StatefulWidget {
|
||||
const ExportPrivateKeyPage({super.key});
|
||||
@ -15,55 +17,81 @@ class _ExportPrivateKeyPageState extends State<ExportPrivateKeyPage> {
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
|
||||
Future<void> _exportPrivateKey() async {
|
||||
// Replace with your actual private key retrieval logic
|
||||
final String privateKeyPem = 'Your private key here';
|
||||
final keyStorage = KeyStorage();
|
||||
final privateKeyPem = await keyStorage.getPrivateKey();
|
||||
|
||||
// Get the password from the user input
|
||||
final password = _passwordController.text;
|
||||
if (password.isEmpty) {
|
||||
// Show error message
|
||||
if (privateKeyPem == null) {
|
||||
// Show error message if there's no key
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('No private key found to export.'),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final password = _passwordController.text;
|
||||
if (password.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Please enter a password.'),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Encrypt the private key using AES-256
|
||||
final encryptedData = _encryptPrivateKey(privateKeyPem, password);
|
||||
|
||||
// Let the user pick a file location
|
||||
final outputFile = await FilePicker.platform.saveFile(
|
||||
dialogTitle: 'Save encrypted private key',
|
||||
fileName: 'private_key_encrypted.aes',
|
||||
);
|
||||
|
||||
if (outputFile != null) {
|
||||
// Write the encrypted data to the file
|
||||
// Use appropriate file I/O methods (not shown here)
|
||||
// ...
|
||||
// Show a confirmation dialog or message
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Key Exported'),
|
||||
content: const Text('The encrypted private key has been exported successfully.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
try {
|
||||
final file = File(outputFile);
|
||||
await file.writeAsBytes(encryptedData);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Key Exported'),
|
||||
content: const Text('The encrypted private key has been exported successfully.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Failed to write file: $e'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Uint8List _encryptPrivateKey(String privateKey, String password) {
|
||||
// Encryption logic using AES-256
|
||||
final key = crypto.PBKDF2KeyDerivator(crypto.HMac(crypto.SHA256Digest(), 64))
|
||||
.process(Uint8List.fromList(utf8.encode(password)));
|
||||
// Derive a key from the password using PBKDF2
|
||||
final derivator = crypto.PBKDF2KeyDerivator(
|
||||
crypto.HMac(crypto.SHA256Digest(), 64),
|
||||
);
|
||||
|
||||
final params = crypto.PaddedBlockCipherParameters(
|
||||
crypto.ParametersWithIV(crypto.KeyParameter(key), Uint8List(16)), // Initialization Vector
|
||||
final salt = Uint8List.fromList(utf8.encode('some_salt')); // In production, use a random salt and store it securely
|
||||
derivator.init(crypto.Pbkdf2Parameters(salt, 1000, 32));
|
||||
final key = derivator.process(Uint8List.fromList(utf8.encode(password)));
|
||||
|
||||
// Initialize AES-CBC cipher with PKCS7 padding
|
||||
final iv = Uint8List(16); // zero IV for example, in production use random IV and store it
|
||||
final params = crypto.PaddedBlockCipherParameters<crypto.ParametersWithIV<crypto.KeyParameter>, Null>(
|
||||
crypto.ParametersWithIV<crypto.KeyParameter>(crypto.KeyParameter(key), iv),
|
||||
null,
|
||||
);
|
||||
|
||||
final cipher = crypto.PaddedBlockCipher('AES/CBC/PKCS7');
|
||||
cipher.init(true, params);
|
||||
|
||||
|
@ -4,12 +4,12 @@ import 'dart:math';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'package:asn1lib/asn1lib.dart';
|
||||
import 'key_storage.dart';
|
||||
|
||||
class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
const GenerateNewKeyPairPage({super.key});
|
||||
|
||||
Future<Map<String, String>> _generateKeyPair() async {
|
||||
// Key generation logic using pointycastle
|
||||
final keyParams = crypto.RSAKeyGeneratorParameters(
|
||||
BigInt.parse('65537'),
|
||||
2048,
|
||||
@ -17,8 +17,6 @@ class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
);
|
||||
|
||||
final secureRandom = crypto.FortunaRandom();
|
||||
|
||||
// Seed the random number generator
|
||||
final random = Random.secure();
|
||||
final seeds = List<int>.generate(32, (_) => random.nextInt(256));
|
||||
secureRandom.seed(crypto.KeyParameter(Uint8List.fromList(seeds)));
|
||||
@ -31,11 +29,12 @@ class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
final publicKey = pair.publicKey as crypto.RSAPublicKey;
|
||||
final privateKey = pair.privateKey as crypto.RSAPrivateKey;
|
||||
|
||||
// Convert keys to PEM format
|
||||
final publicKeyPem = _encodePublicKeyToPemPKCS1(publicKey);
|
||||
final privateKeyPem = _encodePrivateKeyToPemPKCS1(privateKey);
|
||||
|
||||
// Save keys securely (not implemented here)
|
||||
// Save keys securely
|
||||
final keyStorage = KeyStorage();
|
||||
await keyStorage.saveKeys(publicKey: publicKeyPem, privateKey: privateKeyPem);
|
||||
|
||||
return {'publicKey': publicKeyPem, 'privateKey': privateKeyPem};
|
||||
}
|
||||
@ -52,7 +51,8 @@ class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
|
||||
Uint8List _encodePublicKeyToDer(crypto.RSAPublicKey publicKey) {
|
||||
final algorithmSeq = ASN1Sequence();
|
||||
algorithmSeq.add(ASN1ObjectIdentifier.fromName('rsaEncryption'));
|
||||
// Create the OID directly with the arcs
|
||||
algorithmSeq.add(ASN1ObjectIdentifier([1, 2, 840, 113549, 1, 1, 1]));
|
||||
algorithmSeq.add(ASN1Null());
|
||||
|
||||
final publicKeySeq = ASN1Sequence();
|
||||
@ -84,8 +84,8 @@ class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
}
|
||||
|
||||
String _formatPem(Uint8List bytes, String label) {
|
||||
final base64 = base64Encode(bytes);
|
||||
final chunks = RegExp('.{1,64}').allMatches(base64).map((m) => m.group(0)!);
|
||||
final base64Data = base64Encode(bytes);
|
||||
final chunks = RegExp('.{1,64}').allMatches(base64Data).map((m) => m.group(0)!);
|
||||
return '-----BEGIN $label-----\n${chunks.join('\n')}\n-----END $label-----';
|
||||
}
|
||||
|
||||
@ -99,13 +99,12 @@ class GenerateNewKeyPairPage extends StatelessWidget {
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
final keys = await _generateKeyPair();
|
||||
// Display a confirmation dialog or message
|
||||
await _generateKeyPair();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Keys Generated'),
|
||||
content: const Text('The new key pair has been generated successfully.'),
|
||||
content: const Text('The new key pair has been generated and stored securely.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
|
28
dialer/lib/features/settings/key/key_storage.dart
Normal file
28
dialer/lib/features/settings/key/key_storage.dart
Normal file
@ -0,0 +1,28 @@
|
||||
// key_storage.dart
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class KeyStorage {
|
||||
static const _publicKeyKey = 'public_key';
|
||||
static const _privateKeyKey = 'private_key';
|
||||
|
||||
final FlutterSecureStorage _storage = const FlutterSecureStorage();
|
||||
|
||||
Future<void> saveKeys({required String publicKey, required String privateKey}) async {
|
||||
await _storage.write(key: _publicKeyKey, value: publicKey);
|
||||
await _storage.write(key: _privateKeyKey, value: privateKey);
|
||||
}
|
||||
|
||||
Future<String?> getPublicKey() async {
|
||||
return await _storage.read(key: _publicKeyKey);
|
||||
}
|
||||
|
||||
Future<String?> getPrivateKey() async {
|
||||
return await _storage.read(key: _privateKeyKey);
|
||||
}
|
||||
|
||||
Future<void> deleteKeys() async {
|
||||
await _storage.delete(key: _publicKeyKey);
|
||||
await _storage.delete(key: _privateKeyKey);
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dialer/features/settings/key/show_public_key_qr.dart';
|
||||
import 'package:dialer/features/settings/key/show_public_key_text.dart';
|
||||
import 'package:dialer/features/settings/key/generate_new_key_pair.dart';
|
||||
import 'package:dialer/features/settings/key/export_private_key.dart';
|
||||
import 'package:dialer/features/settings/key/delete_key_pair.dart';
|
||||
import 'show_public_key_qr.dart';
|
||||
import 'show_public_key_text.dart';
|
||||
import 'generate_new_key_pair.dart';
|
||||
import 'export_private_key.dart';
|
||||
import 'delete_key_pair.dart';
|
||||
|
||||
class KeyManagementPage extends StatelessWidget {
|
||||
const KeyManagementPage({super.key});
|
||||
@ -41,7 +41,6 @@ class KeyManagementPage extends StatelessWidget {
|
||||
);
|
||||
break;
|
||||
default:
|
||||
// Handle default or unknown options
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pretty_qr_code/pretty_qr_code.dart';
|
||||
import 'key_storage.dart';
|
||||
|
||||
class DisplayPublicKeyQRCodePage extends StatelessWidget {
|
||||
const DisplayPublicKeyQRCodePage({super.key});
|
||||
|
||||
Future<String?> _loadPublicKey() async {
|
||||
final keyStorage = KeyStorage();
|
||||
return keyStorage.getPublicKey();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Replace with your actual public key retrieval logic
|
||||
final String publicKey = 'Your public key here';
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
title: const Text('Public Key in QR Code'),
|
||||
),
|
||||
body: Center(
|
||||
child: PrettyQr(
|
||||
data: publicKey,
|
||||
size: 250,
|
||||
roundEdges: true,
|
||||
elementColor: Colors.white,
|
||||
),
|
||||
body: FutureBuilder<String?>(
|
||||
future: _loadPublicKey(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
final publicKey = snapshot.data;
|
||||
if (publicKey == null) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'No public key found.',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: PrettyQr(
|
||||
data: publicKey,
|
||||
size: 250,
|
||||
roundEdges: true,
|
||||
elementColor: Colors.white,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,27 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'key_storage.dart';
|
||||
|
||||
class DisplayPublicKeyTextPage extends StatelessWidget {
|
||||
const DisplayPublicKeyTextPage({super.key});
|
||||
|
||||
Future<String?> _loadPublicKey() async {
|
||||
final keyStorage = KeyStorage();
|
||||
return await keyStorage.getPublicKey();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Replace with your actual public key retrieval logic
|
||||
final String publicKey = 'Your public key here';
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
title: const Text('Public Key as Text'),
|
||||
),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SelectableText(
|
||||
publicKey,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
body: FutureBuilder<String?>(
|
||||
future: _loadPublicKey(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
final publicKey = snapshot.data;
|
||||
if (publicKey == null) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'No public key found.',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SelectableText(
|
||||
publicKey,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class SettingsPage extends StatelessWidget {
|
||||
MaterialPageRoute(builder: (context) => const SettingsAccountsPage()),
|
||||
);
|
||||
break;
|
||||
case 'Gestion de clés':
|
||||
case 'Key management':
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const KeyManagementPage()),
|
||||
|
@ -44,9 +44,11 @@ dependencies:
|
||||
mobile_scanner: ^6.0.2
|
||||
pretty_qr_code: ^3.3.0
|
||||
pointycastle: ^3.4.0
|
||||
file_picker: ^5.2.5
|
||||
file_picker: ^8.1.6
|
||||
asn1lib: ^1.0.0
|
||||
intl_utils: ^2.0.7
|
||||
url_launcher: ^6.3.1
|
||||
flutter_secure_storage: ^9.0.0
|
||||
mobile_number:
|
||||
path: packages/mobile_number
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user