chore: if user L2 and system language match in user settings page, show base language dropdown (#2810)
This commit is contained in:
parent
261b737eae
commit
8bac7b8c51
5 changed files with 103 additions and 12 deletions
|
|
@ -97,9 +97,12 @@ class SettingsLearningController extends State<SettingsLearning> {
|
|||
}
|
||||
}
|
||||
|
||||
bool get hasIdenticalLanguages =>
|
||||
selectedSourceLanguage?.langCodeShort ==
|
||||
selectedTargetLanguage?.langCodeShort;
|
||||
|
||||
Future<void> submit() async {
|
||||
if (selectedSourceLanguage?.langCodeShort ==
|
||||
selectedTargetLanguage?.langCodeShort) {
|
||||
if (hasIdenticalLanguages) {
|
||||
setState(() {
|
||||
languageMatchError = L10n.of(context).noIdenticalLanguages;
|
||||
});
|
||||
|
|
@ -247,22 +250,29 @@ class SettingsLearningController extends State<SettingsLearning> {
|
|||
_profile.userSettings.targetLanguage != null && _targetLanguage != null;
|
||||
|
||||
LanguageModel? get selectedSourceLanguage {
|
||||
return userL1 ?? pangeaController.languageController.systemLanguage;
|
||||
return _selectedBaseLanguage ??
|
||||
pangeaController.languageController.systemLanguage;
|
||||
}
|
||||
|
||||
LanguageModel? get selectedTargetLanguage {
|
||||
return userL2 ??
|
||||
return _selectedTargetLanguage ??
|
||||
((selectedSourceLanguage?.langCode != 'en')
|
||||
? PLanguageStore.byLangCode('en')
|
||||
: PLanguageStore.byLangCode('es'));
|
||||
}
|
||||
|
||||
LanguageModel? get userL1 => _profile.userSettings.sourceLanguage != null
|
||||
? PLanguageStore.byLangCode(_profile.userSettings.sourceLanguage!)
|
||||
: null;
|
||||
LanguageModel? get userL2 => _profile.userSettings.targetLanguage != null
|
||||
? PLanguageStore.byLangCode(_profile.userSettings.targetLanguage!)
|
||||
: null;
|
||||
LanguageModel? get _selectedBaseLanguage =>
|
||||
_profile.userSettings.sourceLanguage != null
|
||||
? PLanguageStore.byLangCode(_profile.userSettings.sourceLanguage!)
|
||||
: null;
|
||||
|
||||
LanguageModel? get _selectedTargetLanguage =>
|
||||
_profile.userSettings.targetLanguage != null
|
||||
? PLanguageStore.byLangCode(_profile.userSettings.targetLanguage!)
|
||||
: null;
|
||||
|
||||
LanguageModel? get userL1 => pangeaController.languageController.userL1;
|
||||
LanguageModel? get userL2 => pangeaController.languageController.userL2;
|
||||
|
||||
bool get publicProfile => _profile.userSettings.publicProfile ?? true;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/widgets/language_level_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/common/constants/model_keys.dart';
|
||||
import 'package:fluffychat/pangea/common/widgets/full_width_dialog.dart';
|
||||
|
|
@ -173,6 +174,38 @@ class SettingsLearningView extends StatelessWidget {
|
|||
.colorScheme
|
||||
.surfaceContainerHigh,
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
curve: FluffyThemes.animationCurve,
|
||||
child: controller.userL1?.langCodeShort ==
|
||||
controller.userL2?.langCodeShort
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8.0,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.error,
|
||||
),
|
||||
Text(
|
||||
L10n.of(context)
|
||||
.noIdenticalLanguages,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.error,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
CountryPickerDropdown(controller),
|
||||
LanguageLevelDropdown(
|
||||
initialLevel: controller.cefrLevel,
|
||||
|
|
|
|||
|
|
@ -195,7 +195,6 @@ class PLanguageDropdownState extends State<PLanguageDropdown> {
|
|||
? const SizedBox.shrink()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 30,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Text(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
|
@ -28,6 +29,9 @@ class UserSettingsState extends State<UserSettingsPage> {
|
|||
PangeaController get _pangeaController => MatrixState.pangeaController;
|
||||
|
||||
LanguageModel? selectedTargetLanguage;
|
||||
LanguageModel? selectedBaseLanguage;
|
||||
bool showBaseLanguageDropdown = false;
|
||||
|
||||
LanguageLevelTypeEnum selectedCefrLevel = LanguageLevelTypeEnum.a1;
|
||||
|
||||
String? selectedLanguageError;
|
||||
|
|
@ -62,11 +66,16 @@ class UserSettingsState extends State<UserSettingsPage> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
selectedBaseLanguage =
|
||||
_pangeaController.languageController.userL1 ?? _systemLanguage;
|
||||
selectedTargetLanguage = _pangeaController.languageController.userL2;
|
||||
selectedAvatarPath = avatarPaths.first;
|
||||
|
||||
displayNameController.text = Matrix.of(context).client.userID?.localpart ??
|
||||
Matrix.of(context).client.userID ??
|
||||
"";
|
||||
|
||||
final random = Random();
|
||||
selectedAvatarPath = avatarPaths[random.nextInt(avatarPaths.length)];
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -79,10 +88,20 @@ class UserSettingsState extends State<UserSettingsPage> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void setSelectedBaseLanguage(LanguageModel? language) {
|
||||
setState(() {
|
||||
selectedBaseLanguage = language;
|
||||
selectedLanguageError = null;
|
||||
});
|
||||
}
|
||||
|
||||
void setSelectedTargetLanguage(LanguageModel? language) {
|
||||
setState(() {
|
||||
selectedTargetLanguage = language;
|
||||
selectedLanguageError = null;
|
||||
if (!showBaseLanguageDropdown && _hasIdenticalLanguages) {
|
||||
showBaseLanguageDropdown = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -174,6 +193,13 @@ class UserSettingsState extends State<UserSettingsPage> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (_hasIdenticalLanguages) {
|
||||
setState(() {
|
||||
selectedLanguageError = L10n.of(context).noIdenticalLanguages;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formKey.currentState!.validate()) return;
|
||||
setState(() => loading = true);
|
||||
|
||||
|
|
@ -229,6 +255,13 @@ class UserSettingsState extends State<UserSettingsPage> {
|
|||
List<LanguageModel> get targetOptions =>
|
||||
_pangeaController.pLanguageStore.targetOptions;
|
||||
|
||||
List<LanguageModel> get baseOptions =>
|
||||
MatrixState.pangeaController.pLanguageStore.baseOptions;
|
||||
|
||||
bool get _hasIdenticalLanguages =>
|
||||
_systemLanguage != null &&
|
||||
_systemLanguage?.langCodeShort == selectedTargetLanguage?.langCodeShort;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => UserSettingsView(controller: this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
|
|||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/pangea/chat_settings/widgets/language_level_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/learning_settings/widgets/p_language_dropdown.dart';
|
||||
import 'package:fluffychat/pangea/login/pages/pangea_login_scaffold.dart';
|
||||
|
|
@ -106,6 +107,21 @@ class UserSettingsView extends StatelessWidget {
|
|||
},
|
||||
controller: controller.displayNameController,
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
child: controller.showBaseLanguageDropdown
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: PLanguageDropdown(
|
||||
languages: controller.baseOptions,
|
||||
onChange: controller.setSelectedBaseLanguage,
|
||||
initialLanguage: controller.selectedBaseLanguage,
|
||||
hasError: controller.selectedLanguageError != null,
|
||||
decorationText: L10n.of(context).myBaseLanguage,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: PLanguageDropdown(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue