You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-08 23:07:06 +02:00
handle context null
This commit is contained in:
@ -3,13 +3,13 @@ import 'package:intl/message_format.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension StringTranslateExtension on String {
|
||||
String t(BuildContext context, [Map<String, Object>? args]) {
|
||||
String t({BuildContext? context, Map<String, Object>? args}) {
|
||||
return _translateHelper(context, this, args);
|
||||
}
|
||||
}
|
||||
|
||||
extension TextTranslateExtension on Text {
|
||||
Text t(BuildContext context, [Map<String, Object>? args]) {
|
||||
Text t({BuildContext? context, Map<String, Object>? args}) {
|
||||
return Text(
|
||||
_translateHelper(context, data ?? '', args),
|
||||
key: key,
|
||||
@ -30,7 +30,7 @@ extension TextTranslateExtension on Text {
|
||||
}
|
||||
|
||||
String _translateHelper(
|
||||
BuildContext context,
|
||||
BuildContext? context,
|
||||
String key, [
|
||||
Map<String, Object>? args,
|
||||
]) {
|
||||
@ -38,7 +38,7 @@ String _translateHelper(
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
final translatedMessage = context.tr(key);
|
||||
final translatedMessage = context != null ? context.tr(key) : key.tr();
|
||||
return args != null
|
||||
? MessageFormat(translatedMessage, locale: Intl.defaultLocale ?? 'en')
|
||||
.format(args)
|
||||
|
@ -165,7 +165,7 @@ class _LanguageSearchBar extends StatelessWidget {
|
||||
child: SearchField(
|
||||
autofocus: false,
|
||||
contentPadding: const EdgeInsets.all(12),
|
||||
hintText: 'language_search_hint'.t(context),
|
||||
hintText: 'language_search_hint'.t(context: context),
|
||||
prefixIcon: const Icon(Icons.search_rounded),
|
||||
suffixIcon: controller.text.isNotEmpty
|
||||
? IconButton(
|
||||
@ -199,14 +199,14 @@ class _LanguageNotFound extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'language_no_results_title'.t(context),
|
||||
'language_no_results_title'.t(context: context),
|
||||
style: context.textTheme.titleMedium?.copyWith(
|
||||
color: context.colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'language_no_results_subtitle'.t(context),
|
||||
'language_no_results_subtitle'.t(context: context),
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: context.colorScheme.onSurface.withValues(alpha: 0.8),
|
||||
),
|
||||
@ -254,7 +254,7 @@ class _LanguageApplyButton extends StatelessWidget {
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 16.0,
|
||||
),
|
||||
).t(context),
|
||||
).t(context: context),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user