-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix app UI latency due to MethodChannels by adding timeStamps
- Loading branch information
1 parent
cf35307
commit ad72876
Showing
7 changed files
with
76 additions
and
38 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
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
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,31 @@ | ||
class Timer { | ||
Timer(Duration totalTimerDuration, Duration elapsedTimerDuration, | ||
DateTime timeStamp) | ||
: _totalTimerDuration = totalTimerDuration, | ||
_elapsedTimerDuration = elapsedTimerDuration, | ||
_timeStamp = timeStamp; | ||
|
||
static Timer emptyTimer() => | ||
Timer(Duration.zero, Duration.zero, DateTime.now()); | ||
|
||
Duration getElapsed() => _totalTimerDuration != Duration.zero | ||
? DateTime.now().difference(_timeStamp) + _elapsedTimerDuration | ||
: Duration.zero; | ||
|
||
Duration getDuration() => _totalTimerDuration; | ||
|
||
bool isRunning() => (getDuration() - getElapsed()).inMilliseconds > 0; | ||
|
||
Timer increaseTimerDuration(Duration increase) { | ||
if (!isRunning()) return this; | ||
return Timer( | ||
_totalTimerDuration + increase, | ||
_elapsedTimerDuration, | ||
_timeStamp, | ||
); | ||
} | ||
|
||
final Duration _totalTimerDuration; | ||
final Duration _elapsedTimerDuration; | ||
final DateTime _timeStamp; | ||
} |
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