Skip to content

Commit 4c4bd78

Browse files
authored
chore: add learning settings to general settings (#2187)
1 parent fae97c0 commit 4c4bd78

File tree

4 files changed

+163
-136
lines changed

4 files changed

+163
-136
lines changed

lib/config/routes.dart

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import 'package:fluffychat/pangea/activity_planner/activity_planner_page.dart';
3333
import 'package:fluffychat/pangea/activity_suggestions/suggestions_page.dart';
3434
import 'package:fluffychat/pangea/guard/p_vguard.dart';
3535
import 'package:fluffychat/pangea/layouts/bottom_nav_layout.dart';
36+
import 'package:fluffychat/pangea/learning_settings/pages/settings_learning.dart';
3637
import 'package:fluffychat/pangea/login/pages/login_or_signup_view.dart';
3738
import 'package:fluffychat/pangea/login/pages/signup.dart';
3839
import 'package:fluffychat/pangea/login/pages/user_settings.dart';
@@ -492,6 +493,17 @@ abstract class AppRoutes {
492493
],
493494
),
494495
// #Pangea
496+
GoRoute(
497+
path: 'learning',
498+
pageBuilder: (context, state) => defaultPageBuilder(
499+
context,
500+
state,
501+
const SettingsLearning(
502+
isDialog: false,
503+
),
504+
),
505+
redirect: loggedOutRedirect,
506+
),
495507
GoRoute(
496508
path: 'subscription',
497509
pageBuilder: (context, state) => defaultPageBuilder(

lib/pages/settings/settings_view.dart

+9
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ class SettingsView extends StatelessWidget {
188188
// Divider(
189189
// color: theme.dividerColor,
190190
// ),
191+
ListTile(
192+
leading: const Icon(Icons.language_outlined),
193+
title: Text(L10n.of(context).learningSettings),
194+
tileColor:
195+
activeRoute.startsWith('/rooms/settings/learning')
196+
? theme.colorScheme.surfaceContainerHigh
197+
: null,
198+
onTap: () => context.go('/rooms/settings/learning'),
199+
),
191200
// Pangea#
192201
ListTile(
193202
leading: const Icon(Icons.format_paint_outlined),

lib/pangea/learning_settings/pages/settings_learning.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ import 'package:fluffychat/widgets/future_loading_dialog.dart';
1616
import 'package:fluffychat/widgets/matrix.dart';
1717

1818
class SettingsLearning extends StatefulWidget {
19-
const SettingsLearning({super.key});
19+
final bool isDialog;
20+
21+
const SettingsLearning({
22+
this.isDialog = true,
23+
super.key,
24+
});
2025

2126
@override
2227
SettingsLearningController createState() => SettingsLearningController();

lib/pangea/learning_settings/pages/settings_learning_view.dart

+136-135
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:fluffychat/pangea/learning_settings/widgets/country_picker_tile.
1717
import 'package:fluffychat/pangea/learning_settings/widgets/p_language_dropdown.dart';
1818
import 'package:fluffychat/pangea/learning_settings/widgets/p_settings_switch_list_tile.dart';
1919
import 'package:fluffychat/pangea/spaces/models/space_model.dart';
20+
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021
import 'package:fluffychat/widgets/matrix.dart';
2122

2223
class SettingsLearningView extends StatelessWidget {
@@ -105,158 +106,156 @@ class SettingsLearningView extends StatelessWidget {
105106
builder: (context, _) {
106107
final dialogContent = Scaffold(
107108
appBar: AppBar(
109+
automaticallyImplyLeading: false,
108110
centerTitle: true,
109111
title: Text(
110112
L10n.of(context).learningSettings,
111113
),
112-
leading: IconButton(
113-
icon: const Icon(Icons.close),
114-
onPressed: controller.onSettingsClose,
115-
),
114+
leading: controller.widget.isDialog
115+
? IconButton(
116+
icon: const Icon(Icons.close),
117+
onPressed: controller.onSettingsClose,
118+
)
119+
: null,
116120
),
117-
body: ListTileTheme(
118-
iconColor: Theme.of(context).textTheme.bodyLarge!.color,
119-
child: Form(
120-
key: controller.formKey,
121-
child: Padding(
122-
padding: const EdgeInsets.symmetric(
123-
vertical: 16.0,
124-
horizontal: 8.0,
125-
),
121+
body: Form(
122+
key: controller.formKey,
123+
child: ListTileTheme(
124+
iconColor: Theme.of(context).textTheme.bodyLarge!.color,
125+
child: MaxWidthBody(
126126
child: Column(
127127
children: [
128-
Expanded(
129-
child: SingleChildScrollView(
130-
child: Padding(
131-
padding: const EdgeInsets.all(16.0),
132-
child: Column(
133-
spacing: 16.0,
134-
children: [
135-
PLanguageDropdown(
136-
onChange: (lang) =>
137-
controller.setSelectedLanguage(
138-
sourceLanguage: lang,
139-
),
140-
initialLanguage:
141-
controller.selectedSourceLanguage ??
142-
LanguageModel.unknown,
143-
languages: MatrixState.pangeaController
144-
.pLanguageStore.baseOptions,
145-
isL2List: false,
146-
decorationText: L10n.of(context).myBaseLanguage,
147-
hasError: controller.languageMatchError != null,
148-
backgroundColor: Theme.of(context)
149-
.colorScheme
150-
.surfaceContainerHigh,
128+
SingleChildScrollView(
129+
child: Padding(
130+
padding: const EdgeInsets.all(16.0),
131+
child: Column(
132+
spacing: 16.0,
133+
children: [
134+
PLanguageDropdown(
135+
onChange: (lang) =>
136+
controller.setSelectedLanguage(
137+
sourceLanguage: lang,
151138
),
152-
PLanguageDropdown(
153-
onChange: (lang) =>
154-
controller.setSelectedLanguage(
155-
targetLanguage: lang,
156-
),
157-
initialLanguage:
158-
controller.selectedTargetLanguage,
159-
languages: MatrixState.pangeaController
160-
.pLanguageStore.targetOptions,
161-
isL2List: true,
162-
decorationText: L10n.of(context).iWantToLearn,
163-
error: controller.languageMatchError,
164-
backgroundColor: Theme.of(context)
165-
.colorScheme
166-
.surfaceContainerHigh,
139+
initialLanguage:
140+
controller.selectedSourceLanguage ??
141+
LanguageModel.unknown,
142+
languages: MatrixState
143+
.pangeaController.pLanguageStore.baseOptions,
144+
isL2List: false,
145+
decorationText: L10n.of(context).myBaseLanguage,
146+
hasError: controller.languageMatchError != null,
147+
backgroundColor: Theme.of(context)
148+
.colorScheme
149+
.surfaceContainerHigh,
150+
),
151+
PLanguageDropdown(
152+
onChange: (lang) =>
153+
controller.setSelectedLanguage(
154+
targetLanguage: lang,
167155
),
168-
CountryPickerDropdown(controller),
169-
LanguageLevelDropdown(
170-
initialLevel: controller.cefrLevel,
171-
onChanged: controller.setCefrLevel,
156+
initialLanguage:
157+
controller.selectedTargetLanguage,
158+
languages: MatrixState.pangeaController
159+
.pLanguageStore.targetOptions,
160+
isL2List: true,
161+
decorationText: L10n.of(context).iWantToLearn,
162+
error: controller.languageMatchError,
163+
backgroundColor: Theme.of(context)
164+
.colorScheme
165+
.surfaceContainerHigh,
166+
),
167+
CountryPickerDropdown(controller),
168+
LanguageLevelDropdown(
169+
initialLevel: controller.cefrLevel,
170+
onChanged: controller.setCefrLevel,
171+
),
172+
Container(
173+
decoration: BoxDecoration(
174+
border: Border.all(
175+
color: Colors.white54,
176+
),
177+
borderRadius: BorderRadius.circular(8.0),
172178
),
173-
Container(
174-
decoration: BoxDecoration(
175-
border: Border.all(
176-
color: Colors.white54,
179+
padding: const EdgeInsets.all(8.0),
180+
child: Column(
181+
children: [
182+
ProfileSettingsSwitchListTile.adaptive(
183+
defaultValue: controller.getToolSetting(
184+
ToolSetting.autoIGC,
185+
),
186+
title:
187+
ToolSetting.autoIGC.toolName(context),
188+
subtitle: ToolSetting.autoIGC
189+
.toolDescription(context),
190+
onChange: (bool value) =>
191+
controller.updateToolSetting(
192+
ToolSetting.autoIGC,
193+
value,
194+
),
195+
enabled: true,
177196
),
178-
borderRadius: BorderRadius.circular(8.0),
179-
),
180-
padding: const EdgeInsets.all(8.0),
181-
child: Column(
182-
children: [
183-
ProfileSettingsSwitchListTile.adaptive(
184-
defaultValue: controller
185-
.getToolSetting(ToolSetting.autoIGC),
186-
title:
187-
ToolSetting.autoIGC.toolName(context),
188-
subtitle: ToolSetting.autoIGC
189-
.toolDescription(context),
190-
onChange: (bool value) =>
191-
controller.updateToolSetting(
192-
ToolSetting.autoIGC,
193-
value,
194-
),
195-
enabled: true,
197+
ProfileSettingsSwitchListTile.adaptive(
198+
defaultValue: controller.getToolSetting(
199+
ToolSetting.enableAutocorrect,
196200
),
197-
ProfileSettingsSwitchListTile.adaptive(
198-
defaultValue: controller.getToolSetting(
201+
title: ToolSetting.enableAutocorrect
202+
.toolName(context),
203+
subtitle: ToolSetting.enableAutocorrect
204+
.toolDescription(context),
205+
onChange: (bool value) {
206+
controller.updateToolSetting(
199207
ToolSetting.enableAutocorrect,
200-
),
201-
title: ToolSetting.enableAutocorrect
202-
.toolName(context),
203-
subtitle: ToolSetting.enableAutocorrect
204-
.toolDescription(context),
205-
onChange: (bool value) {
206-
controller.updateToolSetting(
207-
ToolSetting.enableAutocorrect,
208-
value,
208+
value,
209+
);
210+
if (value) {
211+
_showKeyboardSettingsDialog(
212+
context,
209213
);
210-
if (value) {
211-
_showKeyboardSettingsDialog(context);
212-
}
213-
},
214-
enabled: true,
215-
),
216-
],
217-
),
214+
}
215+
},
216+
enabled: true,
217+
),
218+
],
218219
),
219-
for (final toolSetting
220-
in ToolSetting.values.where(
221-
(tool) =>
222-
tool.isAvailableSetting &&
223-
tool != ToolSetting.autoIGC &&
224-
tool != ToolSetting.enableAutocorrect,
225-
))
226-
Column(
227-
children: [
228-
ProfileSettingsSwitchListTile.adaptive(
229-
defaultValue: controller
230-
.getToolSetting(toolSetting),
231-
title: toolSetting.toolName(context),
232-
subtitle: toolSetting ==
233-
ToolSetting.enableTTS &&
234-
!controller.isTTSSupported
235-
? null
236-
: toolSetting
237-
.toolDescription(context),
238-
onChange: (bool value) =>
239-
controller.updateToolSetting(
240-
toolSetting,
241-
value,
242-
),
220+
),
221+
for (final toolSetting in ToolSetting.values.where(
222+
(tool) =>
223+
tool.isAvailableSetting &&
224+
tool != ToolSetting.autoIGC &&
225+
tool != ToolSetting.enableAutocorrect,
226+
))
227+
Column(
228+
children: [
229+
ProfileSettingsSwitchListTile.adaptive(
230+
defaultValue:
231+
controller.getToolSetting(toolSetting),
232+
title: toolSetting.toolName(context),
233+
subtitle: toolSetting ==
234+
ToolSetting.enableTTS &&
235+
!controller.isTTSSupported
236+
? null
237+
: toolSetting.toolDescription(context),
238+
onChange: (bool value) =>
239+
controller.updateToolSetting(
240+
toolSetting,
241+
value,
243242
),
244-
],
245-
),
246-
SwitchListTile.adaptive(
247-
value: controller.publicProfile,
248-
onChanged: controller.setPublicProfile,
249-
title: Text(
250-
L10n.of(context).publicProfileTitle,
251-
),
252-
subtitle: Text(
253-
L10n.of(context).publicProfileDesc,
254-
),
255-
activeColor: AppConfig.activeToggleColor,
256-
contentPadding: EdgeInsets.zero,
243+
),
244+
],
257245
),
258-
],
259-
),
246+
SwitchListTile.adaptive(
247+
value: controller.publicProfile,
248+
onChanged: controller.setPublicProfile,
249+
title: Text(
250+
L10n.of(context).publicProfileTitle,
251+
),
252+
subtitle: Text(
253+
L10n.of(context).publicProfileDesc,
254+
),
255+
activeColor: AppConfig.activeToggleColor,
256+
contentPadding: EdgeInsets.zero,
257+
),
258+
],
260259
),
261260
),
262261
),
@@ -277,6 +276,8 @@ class SettingsLearningView extends StatelessWidget {
277276
),
278277
);
279278

279+
if (!controller.widget.isDialog) return dialogContent;
280+
280281
return FullWidthDialog(
281282
dialogContent: dialogContent,
282283
maxWidth: 600,

0 commit comments

Comments
 (0)