Browse Source
Merge pull request 'add: app life cycle observer' (#47) from fix/changes into develop
Merge pull request 'add: app life cycle observer' (#47) from fix/changes into develop
Reviewed-on: https://git.nwhco.ir/amirreza.chegini/hade_hoda_flutter/pulls/47pull/48/head
4 changed files with 66 additions and 1 deletions
-
32lib/core/utils/app_life_cycle.dart
-
12lib/features/question/presentation/bloc/question_bloc.dart
-
21lib/features/question/presentation/ui/screens/question_screen.dart
-
2lib/main.dart
@ -0,0 +1,32 @@ |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; |
|||
import 'package:hadi_hoda_flutter/core/services/audio_service.dart'; |
|||
import 'package:hadi_hoda_flutter/init_bindings.dart'; |
|||
|
|||
class AppLifeCycleController extends WidgetsBindingObserver { |
|||
AppLifeCycleController() { |
|||
WidgetsBinding.instance.addObserver(this); |
|||
} |
|||
|
|||
void dispose() { |
|||
WidgetsBinding.instance.removeObserver(this); |
|||
} |
|||
|
|||
@override |
|||
void didChangeAppLifecycleState(AppLifecycleState state) { |
|||
final AudioService mainAudio = locator( |
|||
instanceName: MyConstants.mainAudioService, |
|||
); |
|||
final AudioService effect = locator( |
|||
instanceName: MyConstants.effectAudioService, |
|||
); |
|||
|
|||
if (state == AppLifecycleState.paused || state == AppLifecycleState.inactive) { |
|||
mainAudio.pause(); |
|||
effect.pause(); |
|||
} else if (state == AppLifecycleState.resumed) { |
|||
mainAudio.play(); |
|||
effect.play(); |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue