-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1153 Boost接管handleAppLifecycleStateChanged,让Flutter生命周期与应用前后台对齐
- Loading branch information
1 parent
aa02956
commit 173c910
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
import 'logger.dart'; | ||
|
||
mixin BoostFlutterBinding on WidgetsFlutterBinding { | ||
|
||
bool _appLifecycleStateLocked = true; | ||
|
||
@override | ||
void initInstances() { | ||
super.initInstances(); | ||
_instance = this; | ||
changeAppLifecycleState(AppLifecycleState.resumed); | ||
} | ||
|
||
static BoostFlutterBinding get instance => _instance; | ||
static BoostFlutterBinding _instance; | ||
|
||
@override | ||
void handleAppLifecycleStateChanged(AppLifecycleState state) { | ||
if (_appLifecycleStateLocked) { | ||
return; | ||
} | ||
Logger.log('boost_flutter_binding: handleAppLifecycleStateChanged ${state.toString()}'); | ||
super.handleAppLifecycleStateChanged(state); | ||
} | ||
|
||
void changeAppLifecycleState(AppLifecycleState state) { | ||
if (SchedulerBinding.instance.lifecycleState == state) { | ||
return; | ||
} | ||
_appLifecycleStateLocked = false; | ||
handleAppLifecycleStateChanged(state); | ||
_appLifecycleStateLocked = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters