// Import Dart and Flutter dependencies
import 'dart:async';
import 'package:cometchat_calls_uikit/cometchat_calls_uikit.dart';
import 'package:cometchat_calls_uikit/cometchat_calls_uikit.dart' as cc;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:master_app/guard_screen.dart';
import 'package:master_app/utils/page_manager.dart';
import 'prefs/shared_preferences.dart';
// Entry point of the Flutter application
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized(); // Ensures Flutter engine is initialized
SharedPreferencesClass.init(); // Initialize shared preferences for app storage
Get.put(PageManager()); // Register PageManager using GetX dependency injection
runApp(const MyApp()); // Launch the main app widget
}
// Main application widget
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// Root of the application
@override
Widget build(BuildContext context) {
return MaterialApp(
// Set the default locale to Telugu
locale: Locale('te'),
// List of all supported locales including the new Telugu support
supportedLocales: const [
Locale('en'),
Locale('en', 'GB'),
Locale('ar'),
Locale('de'),
Locale('es'),
Locale('fr'),
Locale('hi'),
Locale('hu'),
Locale('ja'),
Locale('ko'),
Locale('lt'),
Locale('ms'),
Locale('nl'),
Locale('pt'),
Locale('ru'),
Locale('sv'),
Locale('tr'),
Locale('zh'),
Locale('zh', 'TW'),
Locale('te'), // Newly added Telugu locale
],
// Localization delegates used to load translations
localizationsDelegates: const [
MmCCLocalization.delegate, // Custom Telugu localization delegate
cc.Translations.delegate, // CometChat UI Kit default translations
GlobalMaterialLocalizations.delegate, // Flutter built-in material localization
GlobalWidgetsLocalizations.delegate, // Flutter built-in widget localization
GlobalCupertinoLocalizations.delegate, // Flutter built-in Cupertino localization
],
// Define app theme (e.g., AppBar style)
theme: ThemeData(
appBarTheme: AppBarTheme(
scrolledUnderElevation: 0.0, // Remove shadow when scrolling under AppBar
),
),
title: 'CometChat Flutter Sample App', // App title
navigatorKey: CallNavigationContext.navigatorKey, // Navigator key for CometChat call handling
home: GuardScreen(), // Entry screen of the app
debugShowCheckedModeBanner: false, // Disable debug banner in release mode
);
}
}
// Custom localization delegate for Telugu language
class _NnCometChatLocalizationsDelegate
extends LocalizationsDelegate<cc.Translations> {
const _NnCometChatLocalizationsDelegate();
// Checks if the provided locale is supported (only 'te' in this case)
@override
bool isSupported(Locale locale) => locale.languageCode == 'te';
// Load the custom Telugu translation class
@override
Future<cc.Translations> load(Locale locale) =>
SynchronousFuture(MmCCLocalization());
// Determines whether to reload the delegate (not needed here)
@override
bool shouldReload(_NnCometChatLocalizationsDelegate old) => false;
}
// NOTE:
// Only "chats" and "calls" have been overridden in this example.
// To fully localize the UI for the Telugu language, you should override
// all relevant strings provided by the CometChat UI Kit's Translations class.
// This ensures a consistent and complete user experience across the app.
// Custom Telugu translation class for CometChat UI Kit
class MmCCLocalization extends cc.Translations {
MmCCLocalization([super.locale = "te"]);
// Register the delegate for use in MaterialApp
static const delegate = _NnCometChatLocalizationsDelegate();
// Override specific UI Kit strings in Telugu
@override
String get chats => "సందేశాలు"; // Telugu for "Chats"
@override
String get calls => "ఫోన్ కాల్స్"; // Telugu for "Calls"
// Note: Add more overrides here to fully localize the UI
}