Add globals.dart and obfuscate_service.dart ; implementing obfuscation
This commit is contained in:
parent
475f432047
commit
38330f21e5
@ -4,7 +4,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../../services/contact_service.dart';
|
||||
import '../../services/obfuscate_service.dart'; // Import ObfuscateService
|
||||
import '../contacts/widgets/add_contact_button.dart';
|
||||
import '../../globals.dart' as globals;
|
||||
|
||||
class CompositionPage extends StatefulWidget {
|
||||
const CompositionPage({super.key});
|
||||
@ -19,6 +21,9 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
List<Contact> _filteredContacts = [];
|
||||
final ContactService _contactService = ContactService();
|
||||
|
||||
// Instantiate the ObfuscateService
|
||||
final ObfuscateService _obfuscateService = ObfuscateService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -114,16 +119,12 @@ class _CompositionPageState extends State<CompositionPage> {
|
||||
: 'No phone number';
|
||||
return ListTile(
|
||||
title: Text(
|
||||
'${contact.displayName.isNotEmpty ? contact.displayName[0] : ''}...${contact.displayName.isNotEmpty ? contact.displayName[contact.displayName.length - 1] : ''}',
|
||||
// contact.displayName
|
||||
style:
|
||||
const TextStyle(color: Colors.white),
|
||||
_obfuscateService.obfuscateData(contact.displayName),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
subtitle: Text(
|
||||
'${phoneNumber.isNotEmpty ? phoneNumber[0] : ''}...${phoneNumber.isNotEmpty ? phoneNumber[phoneNumber.length - 1] : ''}',
|
||||
// phoneNumber,
|
||||
style:
|
||||
const TextStyle(color: Colors.grey),
|
||||
_obfuscateService.obfuscateData(phoneNumber),
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
1
dialer/lib/globals.dart
Normal file
1
dialer/lib/globals.dart
Normal file
@ -0,0 +1 @@
|
||||
bool isStealthMode = false;
|
@ -1,13 +1,16 @@
|
||||
import 'package:dialer/features/home/home_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dialer/features/contacts/contact_state.dart';
|
||||
import 'globals.dart' as globals;
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
globals.isStealthMode = String.fromEnvironment('STEALTH', defaultValue: 'false') == 'true';
|
||||
|
||||
runApp(const Dialer());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
class Dialer extends StatelessWidget {
|
||||
const Dialer({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
38
dialer/lib/services/obfuscate_service.dart
Normal file
38
dialer/lib/services/obfuscate_service.dart
Normal file
@ -0,0 +1,38 @@
|
||||
// lib/services/obfuscate_service.dart
|
||||
|
||||
import '../../globals.dart' as globals;
|
||||
|
||||
class ObfuscateService {
|
||||
// Private constructor
|
||||
ObfuscateService._privateConstructor();
|
||||
|
||||
// Singleton instance
|
||||
static final ObfuscateService _instance = ObfuscateService._privateConstructor();
|
||||
|
||||
// Factory constructor to return the same instance
|
||||
factory ObfuscateService() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
// Public method to obfuscate data
|
||||
String obfuscateData(String data) {
|
||||
if (globals.isStealthMode) {
|
||||
return _obfuscateData(data);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
// Private helper method for obfuscation logic
|
||||
String _obfuscateData(String data) {
|
||||
if (data.isNotEmpty) {
|
||||
// Ensure the string has at least two characters to obfuscate
|
||||
if (data.length == 1) {
|
||||
return '${data[0]}';
|
||||
} else {
|
||||
return '${data[0]}...${data[data.length - 1]}';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import 'package:dialer/main.dart';
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(const MyApp());
|
||||
await tester.pumpWidget(const Dialer(stealthMode: false,));
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
Loading…
Reference in New Issue
Block a user