Skip to content
Draft
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
22 changes: 22 additions & 0 deletions STML/stml_application/lib/localization/locales.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter_localization/flutter_localization.dart';

const List<MapLocale> LOCALES = [
MapLocale("en", LocaleData.EN),
MapLocale("es", LocaleData.ES),
];

mixin LocaleData {
static const String title = 'title';
static const String body = 'body';

static const Map<String, dynamic> EN = {
title: 'Localization',
body: 'Welcome to this localized Flutter application %a'
};

static const Map<String, dynamic> ES = {
title: 'Localización',
body: 'Bienvenido a esta aplicación Flutter localizada %a'
};

}
21 changes: 21 additions & 0 deletions STML/stml_application/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ import 'package:memoryminder/features/caregiver_task_management/caregiver_task_s
import 'package:memoryminder/src/features/wearable-integration/health_dashboard.dart';
import 'package:memoryminder/src/features/wearable-integration/fitbit_login.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_localization/flutter_localization.dart';
import 'package:memoryminder/localization/locales.dart';



final storage = FlutterSecureStorage();
final FlutterLocalization localization = FlutterLocalization.instance;

void main() async {
initializeLogging();
Expand All @@ -40,6 +45,12 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Localization for multi language support
supportedLocales: [
Locale('en', ''), // English
Locale('es', '') // Spanish
],
localizationsDelegates: localization.localizationsDelegates,
debugShowCheckedModeBanner: false,
title: 'MemoryMinder',
theme: ThemeData(
Expand Down Expand Up @@ -81,13 +92,23 @@ void initializeData() async {
await PermissionManager.requestInitialPermissions();
await cm.initializeCamera();
NotificationService().initialize();
configureLocalization();
}

// Handle notifications when the app is in the background
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("⚠️ Background message: ${message.notification?.title}");
}

void configureLocalization() {
localization.init(mapLocales: LOCALES, initLanguageCode: "en");
// localization.onTranslatedLanguage = onTranslatedLanguage;
}

// void onTranslatedLanguage(Locale? locale) {
// setState(() {});
// }

Future<FitbitCredentials?> _loadFitbitCredentials() async {
String? storedAccessToken = await storage.read(key: 'fitbitAccessToken');
String? storedRefreshToken = await storage.read(key: 'fitbitRefreshToken');
Expand Down
78 changes: 78 additions & 0 deletions STML/stml_application/lib/pages/home_pages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import 'package:flutter/material.dart';
import 'package:flutter_localization/flutter_localization.dart';
import 'package:memoryminder/localization/locales.dart';

class HomePage extends StatefulWidget {
const HomePage({super.key});

@override
State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
late FlutterLocalization _flutterLocalization;

late String _currentLocale;
@override
void initState() {
super.initState();
_flutterLocalization = FlutterLocalization.instance;
_currentLocale = _flutterLocalization.currentLocale!.languageCode;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
LocaleData.title.getString(context),
),
actions: [
DropdownButton(
value: _currentLocale,
items: const [
DropdownMenuItem(
value: "en",
child: Text("English"),
),
DropdownMenuItem(
value: "es",
child: Text("Spanish"),
),

],
onChanged: (value) {
_setLocale(value);
},
)
],
),
body: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 50,
),
child: Text(
context.formatString(LocaleData.body, ["TeamC"]),
style: const TextStyle(
fontSize: 21,
),
),
),
);
}

void _setLocale(String? value) {
if (value == null) return;
if (value == "en") {
_flutterLocalization.translate("en");
} else if (value == "de") {
_flutterLocalization.translate("es");
} else {
return;
}
setState(() {
_currentLocale = value;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: avoid_print, prefer_const_constructors
// Imported libraries and packages

import 'package:memoryminder/pages/home_pages.dart';
import 'package:memoryminder/src/features/caregiver-dashboard/presentation/add_care_recipient.dart';
import 'package:memoryminder/src/features/caregiver-dashboard/presentation/app_bar.dart';
import 'package:memoryminder/src/features/caregiver-dashboard/presentation/caregiver-dashboard.dart';
Expand Down Expand Up @@ -122,6 +123,14 @@ class CareRecipientProfileScreenState extends State<CareRecipientProfileScreen>
screen: DementiaResourcesScreen(loc: careRecipientLocation),
keyName: "DementiaResourcesButtonKey",
),
_buildElevatedButton(
context: context,
icon: Icon(Icons.language,
size: iconSize, color: Color.fromARGB(255, 2, 63, 129)),
text: 'Set Language Preferences',
screen: HomePage(),
keyName: "DementiaResourcesButtonKey",
),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions STML/stml_application/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies:
flutter_secure_storage: ^8.0.0
http: ^0.13.6
fl_chart: ^0.64.0
flutter_localization: ^0.3.1
record: ^5.0.0
syncfusion_flutter_calendar: ^28.1.37

Expand Down