Skip to content

Commit 15357e2

Browse files
committed
fix: include autoCloseAppAfterAcceptingPushRequest in equality check for SettingsState
1 parent 80babb9 commit 15357e2

File tree

2 files changed

+150
-70
lines changed

2 files changed

+150
-70
lines changed

lib/model/riverpod_states/settings_state.dart

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ class SettingsState {
3232
static bool get hideOtpsDefault => false;
3333
static bool get enablePollingDefault => false;
3434
static Set<String> get crashReportRecipientsDefault => {};
35-
static Locale get localeDefault => AppLocalizations.supportedLocales
36-
.firstWhere((locale) => locale.languageCode == (!kIsWeb ? Platform.localeName.substring(0, 2) : 'en'), orElse: () => const Locale('en'));
35+
static Locale get localeDefault =>
36+
AppLocalizations.supportedLocales.firstWhere(
37+
(locale) =>
38+
locale.languageCode ==
39+
(!kIsWeb ? Platform.localeName.substring(0, 2) : 'en'),
40+
orElse: () => const Locale('en'),
41+
);
3742

3843
static bool get useSystemLocaleDefault => true;
3944
static bool get verboseLoggingDefault => false;
@@ -50,8 +55,12 @@ class SettingsState {
5055
final Set<String> crashReportRecipients;
5156
final Locale localePreference;
5257
Locale get currentLocale => useSystemLocale
53-
? AppLocalizations.supportedLocales
54-
.firstWhere((locale) => locale.languageCode == (!kIsWeb ? Platform.localeName.substring(0, 2) : 'en'), orElse: () => const Locale('en'))
58+
? AppLocalizations.supportedLocales.firstWhere(
59+
(locale) =>
60+
locale.languageCode ==
61+
(!kIsWeb ? Platform.localeName.substring(0, 2) : 'en'),
62+
orElse: () => const Locale('en'),
63+
)
5564
: localePreference;
5665
final bool useSystemLocale;
5766
final bool verboseLogging;
@@ -75,19 +84,23 @@ class SettingsState {
7584
bool? showBackgroundImage,
7685
bool? allowScreenshots,
7786
bool? autoCloseAppAfterAcceptingPushRequest,
78-
}) : isFirstRun = isFirstRun ?? isFirstRunDefault,
79-
showGuideOnStart = showGuideOnStart ?? showGuideOnStartDefault,
80-
hideOpts = hideOpts ?? hideOtpsDefault,
81-
enablePolling = enablePolling ?? enablePollingDefault,
82-
crashReportRecipients = crashReportRecipients ?? crashReportRecipientsDefault,
83-
localePreference = localePreference ?? localeDefault,
84-
useSystemLocale = useSystemLocale ?? useSystemLocaleDefault,
85-
verboseLogging = verboseLogging ?? verboseLoggingDefault,
86-
hidePushTokens = hidePushTokens ?? hidePushTokensDefault,
87-
latestStartedVersion = latestStartedVersion ?? latestStartedVersionDefault,
88-
showBackgroundImage = showBackgroundImage ?? showBackgroundImageDefault,
89-
allowScreenshots = allowScreenshots ?? allowScreenshotsDefault,
90-
autoCloseAppAfterAcceptingPushRequest = autoCloseAppAfterAcceptingPushRequest ?? autoCloseAppAfterAcceptingPushRequestDefault;
87+
}) : isFirstRun = isFirstRun ?? isFirstRunDefault,
88+
showGuideOnStart = showGuideOnStart ?? showGuideOnStartDefault,
89+
hideOpts = hideOpts ?? hideOtpsDefault,
90+
enablePolling = enablePolling ?? enablePollingDefault,
91+
crashReportRecipients =
92+
crashReportRecipients ?? crashReportRecipientsDefault,
93+
localePreference = localePreference ?? localeDefault,
94+
useSystemLocale = useSystemLocale ?? useSystemLocaleDefault,
95+
verboseLogging = verboseLogging ?? verboseLoggingDefault,
96+
hidePushTokens = hidePushTokens ?? hidePushTokensDefault,
97+
latestStartedVersion =
98+
latestStartedVersion ?? latestStartedVersionDefault,
99+
showBackgroundImage = showBackgroundImage ?? showBackgroundImageDefault,
100+
allowScreenshots = allowScreenshots ?? allowScreenshotsDefault,
101+
autoCloseAppAfterAcceptingPushRequest =
102+
autoCloseAppAfterAcceptingPushRequest ??
103+
autoCloseAppAfterAcceptingPushRequestDefault;
91104

92105
SettingsState copyWith({
93106
bool? isFirstRun,
@@ -109,20 +122,24 @@ class SettingsState {
109122
hideOpts: hideOpts ?? this.hideOpts,
110123
enablePolling: enablePolling ?? this.enablePolling,
111124
showGuideOnStart: showGuideOnStart ?? this.showGuideOnStart,
112-
crashReportRecipients: crashReportRecipients ?? this.crashReportRecipients,
125+
crashReportRecipients:
126+
crashReportRecipients ?? this.crashReportRecipients,
113127
localePreference: localePreference ?? this.localePreference,
114128
useSystemLocale: useSystemLocale ?? this.useSystemLocale,
115129
verboseLogging: verboseLogging ?? this.verboseLogging,
116130
hidePushTokens: hidePushTokens ?? this.hidePushTokens,
117131
latestStartedVersion: latestStartedVersion ?? this.latestStartedVersion,
118132
showBackgroundImage: showBackgroundImage ?? this.showBackgroundImage,
119133
allowScreenshots: allowScreenshots ?? this.allowScreenshots,
120-
autoCloseAppAfterAcceptingPushRequest: autoCloseAppAfterAcceptingPushRequest ?? this.autoCloseAppAfterAcceptingPushRequest,
134+
autoCloseAppAfterAcceptingPushRequest:
135+
autoCloseAppAfterAcceptingPushRequest ??
136+
this.autoCloseAppAfterAcceptingPushRequest,
121137
);
122138
}
123139

124140
@override
125-
String toString() => 'SettingsState(isFirstRun: $isFirstRun, showGuideOnStart: $showGuideOnStart, hideOpts: $hideOpts, enablePolling: $enablePolling, '
141+
String toString() =>
142+
'SettingsState(isFirstRun: $isFirstRun, showGuideOnStart: $showGuideOnStart, hideOpts: $hideOpts, enablePolling: $enablePolling, '
126143
'crashReportRecipients: $crashReportRecipients, localePreference: $localePreference, useSystemLocale: $useSystemLocale, verboseLogging: $verboseLogging, '
127144
'hidePushTokens: $hidePushTokens, latestStartedVersion: $latestStartedVersion, showBackgroundImage: $showBackgroundImage, allowScreenshots: $allowScreenshots, autoCloseAppAfterAcceptingPushRequestDefault: $autoCloseAppAfterAcceptingPushRequest)';
128145

@@ -136,14 +153,17 @@ class SettingsState {
136153
other.showGuideOnStart == showGuideOnStart &&
137154
other.hideOpts == hideOpts &&
138155
other.enablePolling == enablePolling &&
139-
other.crashReportRecipients.toString() == crashReportRecipients.toString() &&
156+
other.crashReportRecipients.toString() ==
157+
crashReportRecipients.toString() &&
140158
other.localePreference.toString() == localePreference.toString() &&
141159
other.useSystemLocale == useSystemLocale &&
142160
other.verboseLogging == verboseLogging &&
143161
other.hidePushTokens == hidePushTokens &&
144162
other.latestStartedVersion == latestStartedVersion &&
145163
other.showBackgroundImage == showBackgroundImage &&
146-
other.allowScreenshots == allowScreenshots;
164+
other.allowScreenshots == allowScreenshots &&
165+
other.autoCloseAppAfterAcceptingPushRequest ==
166+
autoCloseAppAfterAcceptingPushRequest;
147167
}
148168

149169
static String encodeLocale(Locale locale) {

lib/views/settings_view/settings_groups/settings_group_push_token/dialogs/settings_group_push_token_dialog.dart

Lines changed: 108 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,81 +33,134 @@ import '../../../settings_view_widgets/update_firebase_token_dialog.dart';
3333

3434
class SettingsGroupPushTokenDialog extends ConsumerWidget {
3535
final List<PushToken> unsupportedPushTokens;
36-
const SettingsGroupPushTokenDialog({super.key, required this.unsupportedPushTokens});
36+
const SettingsGroupPushTokenDialog({
37+
super.key,
38+
required this.unsupportedPushTokens,
39+
});
3740

3841
@override
3942
Widget build(BuildContext context, WidgetRef ref) {
40-
final settingsState = ref.watch(settingsProvider).whenOrNull(data: (data) => data);
41-
final needsFirebaseMessaging = ref.watch(tokenProvider).value?.pushTokensNotPollOnly.isNotEmpty ?? false;
43+
final settingsState = ref
44+
.watch(settingsProvider)
45+
.whenOrNull(data: (data) => data);
46+
final needsFirebaseMessaging =
47+
ref.watch(tokenProvider).value?.pushTokensNotPollOnly.isNotEmpty ??
48+
false;
4249
return DefaultDialog(
4350
title: Text(AppLocalizations.of(context)!.pushToken),
4451
content: Column(
4552
mainAxisSize: MainAxisSize.min,
4653
children: [
4754
if (deviceHasFirebaseMessaging && needsFirebaseMessaging)
4855
ListTile(
49-
title: Text(AppLocalizations.of(context)!.synchronizePushTokens, style: Theme.of(context).textTheme.bodyMedium),
50-
subtitle: Text(AppLocalizations.of(context)!.synchronizesTokensWithServer, overflow: TextOverflow.fade),
56+
title: Text(
57+
AppLocalizations.of(context)!.synchronizePushTokens,
58+
style: Theme.of(context).textTheme.bodyMedium,
59+
),
60+
subtitle: Text(
61+
AppLocalizations.of(context)!.synchronizesTokensWithServer,
62+
overflow: TextOverflow.fade,
63+
),
5164
trailing: ElevatedButton(
5265
onPressed: () => showDialog(
5366
useRootNavigator: false,
5467
context: context,
5568
barrierDismissible: false,
56-
builder: (context) => UpdateFirebaseTokenDialog(AppLocalizations.of(context)!),
69+
builder: (context) =>
70+
UpdateFirebaseTokenDialog(AppLocalizations.of(context)!),
71+
),
72+
child: Text(
73+
AppLocalizations.of(context)!.sync,
74+
overflow: TextOverflow.fade,
75+
softWrap: false,
5776
),
58-
child: Text(AppLocalizations.of(context)!.sync, overflow: TextOverflow.fade, softWrap: false),
5977
),
6078
),
6179
ListTile(
6280
title: RichText(
6381
text: TextSpan(
6482
children: [
65-
TextSpan(text: AppLocalizations.of(context)!.enablePolling, style: Theme.of(context).textTheme.bodyMedium),
83+
TextSpan(
84+
text: AppLocalizations.of(context)!.enablePolling,
85+
style: Theme.of(context).textTheme.bodyMedium,
86+
),
6687
// Add clickable icon to inform user of unsupported push tokens (for polling)
6788
WidgetSpan(
6889
child: Padding(
6990
padding: const EdgeInsets.only(left: 10),
7091
child: unsupportedPushTokens.isNotEmpty
7192
? GestureDetector(
72-
onTap: () => _showPollingInfo(context, unsupportedPushTokens),
73-
child: const Icon(Icons.info_outline, color: Colors.red),
93+
onTap: () => _showPollingInfo(
94+
context,
95+
unsupportedPushTokens,
96+
),
97+
child: const Icon(
98+
Icons.info_outline,
99+
color: Colors.red,
100+
),
74101
)
75102
: null,
76103
),
77104
),
78105
],
79106
),
80107
),
81-
subtitle: Text(AppLocalizations.of(context)!.requestPushChallengesPeriodically, overflow: TextOverflow.fade),
108+
subtitle: Text(
109+
AppLocalizations.of(context)!.requestPushChallengesPeriodically,
110+
overflow: TextOverflow.fade,
111+
),
82112
trailing: Switch(
83-
value: settingsState?.enablePolling ?? SettingsState.enablePollingDefault,
84-
onChanged: (value) => ref.read(settingsProvider.notifier).setPolling(value),
113+
value:
114+
settingsState?.enablePolling ??
115+
SettingsState.enablePollingDefault,
116+
onChanged: (value) =>
117+
ref.read(settingsProvider.notifier).setPolling(value),
85118
),
86119
),
87120
ListTile(
88121
title: RichText(
89122
text: TextSpan(
90-
children: [TextSpan(text: AppLocalizations.of(context)!.hidePushTokens, style: Theme.of(context).textTheme.bodyMedium)],
123+
children: [
124+
TextSpan(
125+
text: AppLocalizations.of(context)!.hidePushTokens,
126+
style: Theme.of(context).textTheme.bodyMedium,
127+
),
128+
],
91129
),
92130
),
93-
subtitle: Text(AppLocalizations.of(context)!.hidePushTokensDescription, overflow: TextOverflow.fade),
131+
subtitle: Text(
132+
AppLocalizations.of(context)!.hidePushTokensDescription,
133+
overflow: TextOverflow.fade,
134+
),
94135
trailing: Switch(
95-
value: settingsState?.hidePushTokens ?? SettingsState.hidePushTokensDefault,
96-
onChanged: (value) => ref.read(settingsProvider.notifier).setHidePushTokens(value),
136+
value:
137+
settingsState?.hidePushTokens ??
138+
SettingsState.hidePushTokensDefault,
139+
onChanged: (value) =>
140+
ref.read(settingsProvider.notifier).setHidePushTokens(value),
97141
),
98142
),
99143
if (Platform.isAndroid)
100144
ListTile(
101-
title: Text(AppLocalizations.of(context)!.autoCloseAppAfterAcceptingPushRequestTitle, style: Theme.of(context).textTheme.bodyMedium),
102-
subtitle: Text(AppLocalizations.of(context)!.autoCloseAppAfterAcceptingPushRequestDescription, overflow: TextOverflow.fade),
145+
title: Text(
146+
AppLocalizations.of(
147+
context,
148+
)!.autoCloseAppAfterAcceptingPushRequestTitle,
149+
style: Theme.of(context).textTheme.bodyMedium,
150+
),
151+
subtitle: Text(
152+
AppLocalizations.of(
153+
context,
154+
)!.autoCloseAppAfterAcceptingPushRequestDescription,
155+
overflow: TextOverflow.fade,
156+
),
103157
trailing: Switch(
104-
value: ref.watch(settingsProvider).value?.autoCloseAppAfterAcceptingPushRequest ?? false,
105-
onChanged: (value) async {
106-
final currentSettings = ref.read(settingsProvider).value;
107-
if (currentSettings != null) {
108-
(await ref.read(settingsProvider.notifier).setAutoCloseAppAfterAcceptingPushRequest(value));
109-
}
110-
},
158+
value:
159+
settingsState?.autoCloseAppAfterAcceptingPushRequest ??
160+
false,
161+
onChanged: (value) => ref
162+
.read(settingsProvider.notifier)
163+
.setAutoCloseAppAfterAcceptingPushRequest(value),
111164
),
112165
),
113166
],
@@ -117,27 +170,34 @@ class SettingsGroupPushTokenDialog extends ConsumerWidget {
117170

118171
/// Shows a dialog to the user that displays all push tokens that do not
119172
/// support polling.
120-
void _showPollingInfo(BuildContext context, List<PushToken> unsupported) => showDialog(
121-
useRootNavigator: false,
122-
context: context,
123-
builder: (BuildContext context) {
124-
return AlertDialog(
125-
title: Text('${AppLocalizations.of(context)!.someTokensDoNotSupportPolling}:'),
126-
content: Scrollbar(
127-
child: ListView.separated(
128-
shrinkWrap: true,
129-
itemCount: unsupported.length,
130-
itemBuilder: (context, index) => Text(unsupported[index].label.toString()),
131-
separatorBuilder: (context, index) => const Divider(),
132-
),
133-
),
134-
actions: <Widget>[
135-
TextButton(
136-
child: Text(AppLocalizations.of(context)!.dismiss, style: Theme.of(context).textTheme.titleMedium),
137-
onPressed: () => Navigator.of(context).pop(),
138-
),
139-
],
173+
void _showPollingInfo(BuildContext context, List<PushToken> unsupported) =>
174+
showDialog(
175+
useRootNavigator: false,
176+
context: context,
177+
builder: (BuildContext context) {
178+
return AlertDialog(
179+
title: Text(
180+
'${AppLocalizations.of(context)!.someTokensDoNotSupportPolling}:',
181+
),
182+
content: Scrollbar(
183+
child: ListView.separated(
184+
shrinkWrap: true,
185+
itemCount: unsupported.length,
186+
itemBuilder: (context, index) =>
187+
Text(unsupported[index].label.toString()),
188+
separatorBuilder: (context, index) => const Divider(),
189+
),
190+
),
191+
actions: <Widget>[
192+
TextButton(
193+
child: Text(
194+
AppLocalizations.of(context)!.dismiss,
195+
style: Theme.of(context).textTheme.titleMedium,
196+
),
197+
onPressed: () => Navigator.of(context).pop(),
198+
),
199+
],
200+
);
201+
},
140202
);
141-
},
142-
);
143203
}

0 commit comments

Comments
 (0)