Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
arb-dir: lib/l10n
template-arb-file: app_en.arb
output-localization-file: app_localizations.dart
output-class: AppLocalizations
output-dir: lib/l10n
nullable-getter: false
80 changes: 80 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"@@locale": "en",
"appTitle": "Ell-ena",
"@appTitle": {
"description": "The application title shown in the task switcher and browser tab."
},
"login": "Sign In",
"@login": {
"description": "Primary authentication action on the login screen."
},
"signUp": "Sign Up",
"@signUp": {
"description": "Registration action on the authentication screens."
},
"logout": "Logout",
"@logout": {
"description": "Logout action label."
},
"logoutTitle": "Log out?",
"@logoutTitle": {
"description": "Title for the logout confirmation dialog."
},
"logoutMessage": "You will need to log in again to access your account.",
"@logoutMessage": {
"description": "Body text for the logout confirmation dialog."
},
"dashboard": "Dashboard",
"@dashboard": {
"description": "Dashboard navigation label."
},
"tasks": "Tasks",
"@tasks": {
"description": "Tasks section label."
},
"tickets": "Tickets",
"@tickets": {
"description": "Tickets section label."
},
"meetings": "Meetings",
"@meetings": {
"description": "Meetings section label."
},
"settings": "Settings",
"@settings": {
"description": "Settings section label."
},
"cancel": "Cancel",
"@cancel": {
"description": "Generic cancel action."
},
"save": "Save",
"@save": {
"description": "Generic save action."
},
"loading": "Loading...",
"@loading": {
"description": "Generic loading indicator label."
},
"search": "Search",
"@search": {
"description": "Generic search placeholder label."
},
"language": "Language",
"@language": {
"description": "Language preference setting label."
},
"languageName": "{localeCode, select, en{English} hi{हिन्दी} other{{localeCode}}}",
"@languageName": {
"description": "Display name for a language identified by locale code.",
"placeholders": {
"localeCode": {
"type": "String"
}
}
},
"selectLanguage": "Select Language",
"@selectLanguage": {
"description": "Title for the language selection sheet."
}
}
21 changes: 21 additions & 0 deletions lib/l10n/app_hi.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"@@locale": "hi",
"appTitle": "Ell-ena",
"login": "साइन इन",
"signUp": "साइन अप",
"logout": "लॉग आउट",
"logoutTitle": "लॉग आउट करें?",
"logoutMessage": "अपने खाते तक पहुँचने के लिए आपको दोबारा लॉग इन करना होगा।",
"dashboard": "डैशबोर्ड",
"tasks": "कार्य",
"tickets": "टिकट",
"meetings": "मीटिंग",
"settings": "सेटिंग्स",
"cancel": "रद्द करें",
"save": "सहेजें",
"loading": "लोड हो रहा है...",
"search": "खोजें",
"language": "भाषा",
"languageName": "{localeCode, select, en{अंग्रेज़ी} hi{हिन्दी} other{{localeCode}}}",
"selectLanguage": "भाषा चुनें"
}
44 changes: 30 additions & 14 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'
hide ChangeNotifierProvider;
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'l10n/app_localizations.dart';
import 'screens/splash_screen.dart';
import 'screens/home/home_screen.dart';
import 'screens/chat/chat_screen.dart';
import 'services/navigation_service.dart';
import 'services/supabase_service.dart';
import 'services/ai_service.dart';
import 'providers/locale_provider.dart';
import 'providers/shared_preferences_provider.dart';
import 'providers/theme_provider.dart';
import 'theme/theme_controller.dart';
import 'theme/app_themes.dart';
Expand All @@ -21,33 +26,44 @@ void main() async {
} catch (e) {
debugPrint('Error initializing services: $e');
}


final prefs = await SharedPreferences.getInstance();
final themeController = await ThemeController.create();

runApp(
WidgetsBindingObserverWidget(
child: ProviderScope(
overrides: [
themeControllerProvider.overrideWith((ref) => themeController),
],
child: ChangeNotifierProvider<ThemeController>.value(
value: themeController,
child: const MyApp(),
runApp(
WidgetsBindingObserverWidget(
child: ProviderScope(
overrides: [
sharedPreferencesProvider.overrideWithValue(prefs),
themeControllerProvider.overrideWith((ref) => themeController),
],
child: ChangeNotifierProvider<ThemeController>.value(
value: themeController,
child: const MyApp(),
),
),
),
),
);

);
}

class MyApp extends ConsumerWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final themeController = ref.watch(themeControllerProvider);
final locale = ref.watch(localeControllerProvider);
return MaterialApp(
title: 'Ell-ena',
onGenerateTitle: (context) => AppLocalizations.of(context).appTitle,
debugShowCheckedModeBanner: false,
locale: locale,
localizationsDelegates: const [
Comment thread
dhruvi-16-me marked this conversation as resolved.
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
navigatorKey: NavigationService().navigatorKey,
navigatorObservers: <NavigatorObserver>[AppRouteObserver.instance],
theme: lightTheme,
Expand Down
35 changes: 35 additions & 0 deletions lib/providers/locale_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../l10n/app_localizations.dart';
import 'shared_preferences_provider.dart';

part 'locale_provider.g.dart';

const String _localeStorageKey = 'app_locale';
const Locale _defaultLocale = Locale('en');

/// Manages the active app [Locale] with SharedPreferences persistence.
@Riverpod(keepAlive: true)
class LocaleController extends _$LocaleController {
@override
Locale build() {
final prefs = ref.watch(sharedPreferencesProvider);
final code = prefs.getString(_localeStorageKey);
if (code != null && code.isNotEmpty) {
for (final locale in AppLocalizations.supportedLocales) {
if (locale.languageCode == code) {
return locale;
}
}
}
return _defaultLocale;
}

/// Updates locale and persists the language code.
Future<void> setLocale(Locale locale) async {
final prefs = ref.read(sharedPreferencesProvider);
await prefs.setString(_localeStorageKey, locale.languageCode);
state = locale;
}
}
28 changes: 28 additions & 0 deletions lib/providers/locale_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/providers/shared_preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// SharedPreferences instance overridden at app startup.
final sharedPreferencesProvider = Provider<SharedPreferences>((ref) {
throw StateError(
'sharedPreferencesProvider must be overridden in ProviderScope',
);
});
6 changes: 4 additions & 2 deletions lib/screens/auth/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import '../../l10n/app_localizations.dart';
import '../../widgets/custom_widgets.dart';
import '../../services/navigation_service.dart';
import '../../services/supabase_service.dart';
Expand Down Expand Up @@ -159,6 +160,7 @@ class _LoginScreenState extends State<LoginScreen>

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return AuthScreenWrapper(
title: 'Welcome Back',
subtitle: 'Sign in to continue with Ell-ena',
Expand Down Expand Up @@ -221,7 +223,7 @@ class _LoginScreenState extends State<LoginScreen>
),
const SizedBox(height: 24),
CustomButton(
text: 'Sign In',
text: l10n.login,
onPressed: _isLoading ? null : _handleLogin,
isLoading: _isLoading,
),
Expand Down Expand Up @@ -292,7 +294,7 @@ class _LoginScreenState extends State<LoginScreen>
NavigationService().navigateTo(const SignupScreen());
},
child: Text(
'Sign Up',
l10n.signUp,
style: TextStyle(
color: Colors.green.shade400,
fontWeight: FontWeight.w600,
Expand Down
8 changes: 5 additions & 3 deletions lib/screens/home/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../../l10n/app_localizations.dart';
import '../../widgets/custom_widgets.dart';
import '../../services/navigation_service.dart';
import '../workspace/workspace_screen.dart';
Expand Down Expand Up @@ -140,6 +141,7 @@ class _HomeScreenState extends State<HomeScreen>
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l10n = AppLocalizations.of(context);
return Scaffold(
body: IndexedStack(index: _selectedIndex, children: _screens),
bottomNavigationBar: BottomNavigationBar(
Expand All @@ -148,10 +150,10 @@ class _HomeScreenState extends State<HomeScreen>
type: BottomNavigationBarType.fixed,
selectedItemColor: theme.colorScheme.primary,
unselectedItemColor: theme.colorScheme.onSurfaceVariant,
items: const [
items: [
BottomNavigationBarItem(
icon: Icon(Icons.dashboard),
label: 'Dashboard',
icon: const Icon(Icons.dashboard),
label: l10n.dashboard,
),
BottomNavigationBarItem(
icon: Icon(Icons.calendar_today),
Expand Down
9 changes: 6 additions & 3 deletions lib/screens/profile/edit_profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../../l10n/app_localizations.dart';
import '../../services/supabase_service.dart';

class EditProfileScreen extends StatefulWidget {
Expand Down Expand Up @@ -120,6 +121,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
appBar: AppBar(
Expand All @@ -136,9 +138,10 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
strokeWidth: 2, color: Colors.white))
: Icon(Icons.save,
color: Theme.of(context).colorScheme.onSurface),
label: Text('Save',
style:
TextStyle(color: Theme.of(context).colorScheme.onSurface)),
label: Text(
l10n.save,
style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
),
),
],
),
Expand Down
Loading