simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -9,6 +9,7 @@ import '../../../storage/chat_background_settings.dart';
|
||||
import '../../../storage/settings.dart' as model;
|
||||
import '../../../utils/app_paths.dart';
|
||||
import '../../../utils/haptics.dart';
|
||||
import '../../../utils/json_equality.dart';
|
||||
import '../../../widget/async_action_button.dart';
|
||||
import '../../../widget/chat_background.dart';
|
||||
import '../../../widget/chat_background_picker_sheet.dart';
|
||||
@@ -43,9 +44,10 @@ class ChatBackgroundSettingsPage extends StatelessWidget {
|
||||
builder: (context, _) {
|
||||
final settings = context.read<SettingsCubit>();
|
||||
final s = settings.val().chatBackgroundSettings;
|
||||
final isModified =
|
||||
s.toJson().toString() !=
|
||||
DefaultSettings.get().chatBackgroundSettings.toJson().toString();
|
||||
final isModified = !sameJson(
|
||||
s,
|
||||
DefaultSettings.get().chatBackgroundSettings,
|
||||
);
|
||||
final showImageControls =
|
||||
s.type == ChatBackgroundType.pattern ||
|
||||
s.type == ChatBackgroundType.image;
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../state/app/modules/app_modules.dart';
|
||||
import '../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
||||
import '../../../storage/settings.dart' as model;
|
||||
import '../../../utils/haptics.dart';
|
||||
import '../../../utils/json_equality.dart';
|
||||
import '../../../widget/confirm_dialog.dart';
|
||||
import 'data/default_settings.dart';
|
||||
|
||||
@@ -147,9 +148,10 @@ class ModulesSettingsPage extends StatelessWidget {
|
||||
BlocBuilder<SettingsCubit, model.Settings>(
|
||||
builder: (context, _) {
|
||||
final settings = context.read<SettingsCubit>();
|
||||
final isModified =
|
||||
settings.val().modulesSettings.toJson().toString() !=
|
||||
DefaultSettings.get().modulesSettings.toJson().toString();
|
||||
final isModified = !sameJson(
|
||||
settings.val().modulesSettings,
|
||||
DefaultSettings.get().modulesSettings,
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Module'),
|
||||
|
||||
@@ -50,10 +50,7 @@ class AboutSection extends StatelessWidget {
|
||||
_toggleDeveloperMode(context, settings, state),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: settings.val().devToolsEnabled,
|
||||
child: DevToolsSection(settings: settings),
|
||||
),
|
||||
if (settings.val().devToolsEnabled) DevToolsSection(settings: settings),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -104,7 +101,9 @@ class AboutSection extends StatelessWidget {
|
||||
Icon(Icons.send_time_extension_outlined),
|
||||
),
|
||||
title: const Text('Infos zu mhsl'),
|
||||
subtitle: const Text('Für Push, Kalendertermine, Marianum Message und mehr'),
|
||||
subtitle: const Text(
|
||||
'Für Push, Kalendertermine, Marianum Message und mehr',
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () => PrivacyInfo(
|
||||
providerText: 'mhsl',
|
||||
|
||||
@@ -22,21 +22,14 @@ import '../../../../widget/user_avatar.dart';
|
||||
String? _cachedDisplayName;
|
||||
String? _cachedDisplayNameFor;
|
||||
|
||||
class AccountSection extends StatelessWidget {
|
||||
class AccountSection extends StatefulWidget {
|
||||
const AccountSection({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const _SchoolAccount();
|
||||
State<AccountSection> createState() => _AccountSectionState();
|
||||
}
|
||||
|
||||
class _SchoolAccount extends StatefulWidget {
|
||||
const _SchoolAccount();
|
||||
|
||||
@override
|
||||
State<_SchoolAccount> createState() => _SchoolAccountState();
|
||||
}
|
||||
|
||||
class _SchoolAccountState extends State<_SchoolAccount> {
|
||||
class _AccountSectionState extends State<AccountSection> {
|
||||
int _avatarVersion = 0;
|
||||
bool _avatarBusy = false;
|
||||
String? _displayName;
|
||||
|
||||
@@ -41,25 +41,15 @@ class AppearanceSection extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
IconData _hapticIcon(HapticLevel level) {
|
||||
switch (level) {
|
||||
case HapticLevel.off:
|
||||
return Icons.notifications_off_outlined;
|
||||
case HapticLevel.reduced:
|
||||
return Icons.notifications_paused_outlined;
|
||||
case HapticLevel.full:
|
||||
return Icons.notifications_active_outlined;
|
||||
}
|
||||
}
|
||||
IconData _hapticIcon(HapticLevel level) => switch (level) {
|
||||
HapticLevel.off => Icons.notifications_off_outlined,
|
||||
HapticLevel.reduced => Icons.notifications_paused_outlined,
|
||||
HapticLevel.full => Icons.notifications_active_outlined,
|
||||
};
|
||||
|
||||
String _hapticLabel(HapticLevel level) {
|
||||
switch (level) {
|
||||
case HapticLevel.off:
|
||||
return 'Aus';
|
||||
case HapticLevel.reduced:
|
||||
return 'Reduziert';
|
||||
case HapticLevel.full:
|
||||
return 'Vollständig';
|
||||
}
|
||||
}
|
||||
String _hapticLabel(HapticLevel level) => switch (level) {
|
||||
HapticLevel.off => 'Aus',
|
||||
HapticLevel.reduced => 'Reduziert',
|
||||
HapticLevel.full => 'Vollständig',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -26,15 +26,10 @@ import '../widgets/endpoint_picker.dart';
|
||||
import '../widgets/settings_checkbox_tile.dart';
|
||||
import '../widgets/settings_dropdown_tile.dart';
|
||||
|
||||
class DevToolsSection extends StatefulWidget {
|
||||
class DevToolsSection extends StatelessWidget {
|
||||
final SettingsCubit settings;
|
||||
const DevToolsSection({required this.settings, super.key});
|
||||
|
||||
@override
|
||||
State<DevToolsSection> createState() => _DevToolsSectionState();
|
||||
}
|
||||
|
||||
class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
@override
|
||||
Widget build(BuildContext context) => Column(
|
||||
children: [
|
||||
@@ -54,11 +49,11 @@ class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
context,
|
||||
children: (sheetCtx) => [
|
||||
BlocBuilder<SettingsCubit, model.Settings>(
|
||||
bloc: widget.settings,
|
||||
bloc: settings,
|
||||
builder: (_, _) {
|
||||
final dev = widget.settings.val().devToolsSettings;
|
||||
final dev = settings.val().devToolsSettings;
|
||||
DevToolsSettings write() =>
|
||||
widget.settings.val(write: true).devToolsSettings;
|
||||
settings.val(write: true).devToolsSettings;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -122,17 +117,17 @@ class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
title: const Text('Marianum-Connect-Server'),
|
||||
subtitle: Text(
|
||||
MarianumConnectEndpointPicker.labelFor(
|
||||
widget.settings.val().devToolsSettings,
|
||||
settings.val().devToolsSettings,
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () =>
|
||||
MarianumConnectEndpointPicker.show(context, widget.settings),
|
||||
MarianumConnectEndpointPicker.show(context, settings),
|
||||
),
|
||||
BlocBuilder<SettingsCubit, model.Settings>(
|
||||
bloc: widget.settings,
|
||||
bloc: settings,
|
||||
builder: (_, _) {
|
||||
final override = widget.settings
|
||||
final override = settings
|
||||
.val()
|
||||
.devToolsSettings
|
||||
.emergencyNoticeUrl
|
||||
@@ -143,7 +138,7 @@ class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
subtitle: Text(override.isEmpty ? 'Standardquelle' : override),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () =>
|
||||
_EmergencyNoticeUrlEditor.show(context, widget.settings),
|
||||
_EmergencyNoticeUrlEditor.show(context, settings),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -152,18 +147,18 @@ class _DevToolsSectionState extends State<DevToolsSection> {
|
||||
icon: Icons.settings_applications_outlined,
|
||||
title: 'Einstellungen',
|
||||
describe: () async => filesize(
|
||||
utf8.encode(jsonEncode(widget.settings.val().toJson())).length,
|
||||
utf8.encode(jsonEncode(settings.val().toJson())).length,
|
||||
),
|
||||
onOpen: (_) async => AppRoutes.openJsonViewer(
|
||||
context,
|
||||
widget.settings.val().toJson(),
|
||||
settings.val().toJson(),
|
||||
title: 'Einstellungen',
|
||||
),
|
||||
clearTitle: 'Einstellungen zurücksetzen',
|
||||
clearContent:
|
||||
'Alle Einstellungen gehen verloren! Accountdaten sowie App-Daten '
|
||||
'sind nicht betroffen.',
|
||||
onClear: widget.settings.reset,
|
||||
onClear: settings.reset,
|
||||
),
|
||||
_StorageTile(
|
||||
icon: Icons.account_tree_outlined,
|
||||
|
||||
@@ -5,11 +5,11 @@ import '../../../../widget/confirm_dialog.dart';
|
||||
import '../../../../widget/details_bottom_sheet.dart';
|
||||
|
||||
class PrivacyInfo {
|
||||
String providerText;
|
||||
String privacyUrl;
|
||||
String imprintUrl;
|
||||
final String providerText;
|
||||
final String privacyUrl;
|
||||
final String imprintUrl;
|
||||
|
||||
PrivacyInfo({
|
||||
const PrivacyInfo({
|
||||
required this.providerText,
|
||||
required this.imprintUrl,
|
||||
required this.privacyUrl,
|
||||
|
||||
@@ -228,11 +228,7 @@ class _PushStatusBodyState extends State<_PushStatusBody>
|
||||
/// otherwise re-registering IS the primary next step and the test action is
|
||||
/// omitted (it could not succeed and the checklist explains why).
|
||||
Widget _actions(PushStatusReport report) {
|
||||
const spinner = SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
);
|
||||
const spinner = AppProgressIndicator.small();
|
||||
final ready = report.readyForTestNotification;
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
Reference in New Issue
Block a user