monorepo/dialer/lib/main.dart
AlexisDanlos 664dd4bb38
All checks were successful
/ mirror (push) Successful in 5s
/ build-stealth (push) Successful in 8m55s
/ build (push) Successful in 8m58s
WIP: app rework
2025-03-26 22:27:02 +01:00

87 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'core/config/app_config.dart';
import 'core/navigation/app_router.dart';
import 'domain/services/call_service.dart';
import 'domain/services/cryptography/asymmetric_crypto_service.dart';
import 'presentation/common/theme/app_theme.dart';
import 'presentation/features/contacts/contact_state.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize app configuration
await AppConfig.initialize();
// Initialize cryptography service with error handling
final AsymmetricCryptoService cryptoService = AsymmetricCryptoService();
try {
await cryptoService.initializeDefaultKeyPair();
} catch (e) {
debugPrint('Error initializing cryptography: $e');
// Continue app initialization even if crypto fails
}
// Request permissions before running the app
await _requestPermissions();
// Initialize call service
CallService();
runApp(
MultiProvider(
providers: [
Provider<AsymmetricCryptoService>(
create: (_) => cryptoService,
),
],
child: const DialerApp(),
),
);
}
Future<void> _requestPermissions() async {
try {
Map<Permission, PermissionStatus> statuses = await [
Permission.phone,
Permission.contacts,
Permission.microphone,
].request();
if (statuses.values.every((status) => status.isGranted)) {
debugPrint("All required permissions granted");
const channel = MethodChannel('call_service');
await channel.invokeMethod('permissionsGranted');
} else {
debugPrint("Permissions denied: ${statuses.entries.where((e) => !e.value.isGranted).map((e) => e.key).join(', ')}");
}
} catch (e) {
debugPrint("Error requesting permissions: $e");
}
}
class DialerApp extends StatelessWidget {
const DialerApp({super.key});
@override
Widget build(BuildContext context) {
return ContactState(
child: MaterialApp(
title: 'Dialer App',
navigatorKey: CallService.navigatorKey,
theme: AppTheme.darkTheme,
onGenerateRoute: AppRouter.generateRoute,
initialRoute: '/',
// Add a builder to wrap all routes with SafeArea
builder: (context, child) {
return SafeArea(
child: child ?? const SizedBox.shrink(),
);
},
),
);
}
}