Skip to content

Commit 443f138

Browse files
committed
fix: avoid schedule tick router refreshes
1 parent 616fb54 commit 443f138

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

lib/presentation/app/screens/app.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class _AppRouterViewState extends State<_AppRouterView>
6161

6262
late final _router = goRouterConfig(
6363
context.read<AuthBloc>(),
64-
context.read<ScheduleBloc>(),
6564
context.read<NotificationGateCubit>(),
6665
context.read<AlarmGateCubit>(),
6766
);

lib/presentation/shared/router/go_router.dart

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey();
3434

3535
GoRouter goRouterConfig(
3636
AuthBloc authBloc,
37-
ScheduleBloc scheduleBloc,
3837
NotificationGateCubit notificationGateCubit,
3938
AlarmGateCubit alarmGateCubit,
4039
) {
4140
return GoRouter(
42-
refreshListenable: StreamToListenable([
43-
scheduleBloc.stream,
44-
authBloc.stream,
45-
notificationGateCubit.stream,
46-
alarmGateCubit.stream,
47-
]),
41+
refreshListenable: appRouterRefreshListenable(
42+
authStream: authBloc.stream,
43+
notificationGateStream: notificationGateCubit.stream,
44+
alarmGateStream: alarmGateCubit.stream,
45+
),
4846
navigatorKey: getIt.get<NavigationService>().navigatorKey,
4947
redirect: (BuildContext context, GoRouterState state) {
5048
return appRedirectLocation(
@@ -220,6 +218,19 @@ GoRouter goRouterConfig(
220218
);
221219
}
222220

221+
@visibleForTesting
222+
StreamToListenable appRouterRefreshListenable({
223+
required Stream<AuthState> authStream,
224+
required Stream<NotificationGateState> notificationGateStream,
225+
required Stream<AlarmGateState> alarmGateStream,
226+
}) {
227+
return StreamToListenable([
228+
authStream,
229+
notificationGateStream,
230+
alarmGateStream,
231+
]);
232+
}
233+
223234
@visibleForTesting
224235
String? appRedirectLocation({
225236
required AuthStatus authStatus,

test/presentation/shared/router/go_router_redirect_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
1+
import 'dart:async';
2+
13
import 'package:flutter_test/flutter_test.dart';
24
import 'package:on_time_front/presentation/app/bloc/auth/auth_bloc.dart';
5+
import 'package:on_time_front/presentation/app/bloc/schedule/schedule_bloc.dart';
36
import 'package:on_time_front/presentation/app/cubit/alarm_gate_cubit.dart';
47
import 'package:on_time_front/presentation/app/cubit/notification_gate_cubit.dart';
58
import 'package:on_time_front/presentation/shared/router/go_router.dart';
69

710
void main() {
11+
test(
12+
'router refresh listenable ignores schedule progress but refreshes for route gates',
13+
() async {
14+
final scheduleController = StreamController<ScheduleState>.broadcast();
15+
final authController = StreamController<AuthState>.broadcast();
16+
final notificationGateController =
17+
StreamController<NotificationGateState>.broadcast();
18+
final alarmGateController = StreamController<AlarmGateState>.broadcast();
19+
final listenable = appRouterRefreshListenable(
20+
authStream: authController.stream,
21+
notificationGateStream: notificationGateController.stream,
22+
alarmGateStream: alarmGateController.stream,
23+
);
24+
addTearDown(() async {
25+
listenable.dispose();
26+
await scheduleController.close();
27+
await authController.close();
28+
await notificationGateController.close();
29+
await alarmGateController.close();
30+
});
31+
32+
var refreshCount = 0;
33+
listenable.addListener(() => refreshCount++);
34+
35+
scheduleController.add(const ScheduleState.initial());
36+
await pumpEventQueue();
37+
38+
expect(refreshCount, 0);
39+
40+
authController.add(const AuthState.loading());
41+
notificationGateController.add(const NotificationGateState.required());
42+
alarmGateController.add(const AlarmGateState.required());
43+
await pumpEventQueue();
44+
45+
expect(refreshCount, 3);
46+
},
47+
);
48+
849
test(
950
'authenticated user goes directly to notification prompt while alarm gate is unresolved',
1051
() {

0 commit comments

Comments
 (0)