mirror of https://github.com/flutter/samples.git
update slide_puzzle for beta channel (#419)
includes PR: https://github.com/kevmoo/slide_puzzle/pull/5pull/422/head
parent
ed284c78bd
commit
ef0114c210
Before Width: | Height: | Size: 17 KiB |
@ -1,29 +1,9 @@
|
||||
import 'core/puzzle_animator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'shared_theme.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
abstract class AppState {
|
||||
TabController get tabController;
|
||||
|
||||
Animation<Offset> get shuffleOffsetAnimation;
|
||||
import 'core/puzzle_proxy.dart';
|
||||
|
||||
abstract class AppState {
|
||||
PuzzleProxy get puzzle;
|
||||
|
||||
bool get autoPlay;
|
||||
|
||||
void setAutoPlay(bool newValue);
|
||||
|
||||
AnimationNotifier get animationNotifier;
|
||||
|
||||
Iterable<SharedTheme> get themeData;
|
||||
|
||||
SharedTheme get currentTheme;
|
||||
|
||||
set currentTheme(SharedTheme theme);
|
||||
}
|
||||
|
||||
abstract class AnimationNotifier implements Listenable {
|
||||
void animate();
|
||||
|
||||
void dispose();
|
||||
Listenable get animationNotifier;
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
import 'dart:collection';
|
||||
|
||||
class FrameNanny {
|
||||
static const _bufferSize = 200;
|
||||
static const _maxFrameDuration = Duration(milliseconds: 34);
|
||||
final _buffer = ListQueue<Duration>(_bufferSize);
|
||||
final _watch = Stopwatch();
|
||||
|
||||
Duration tick(Duration source) {
|
||||
_watch.start();
|
||||
_buffer.add(source);
|
||||
|
||||
while (_buffer.length > _bufferSize) {
|
||||
_buffer.removeFirst();
|
||||
}
|
||||
|
||||
if (source > _maxFrameDuration) {
|
||||
source = _maxFrameDuration;
|
||||
}
|
||||
|
||||
if (_watch.elapsed > const Duration(seconds: 2)) {
|
||||
var goodCount = 0;
|
||||
var sum = const Duration();
|
||||
Duration best, worst;
|
||||
|
||||
for (var e in _buffer) {
|
||||
sum += e;
|
||||
if (e <= _maxFrameDuration) {
|
||||
goodCount++;
|
||||
}
|
||||
|
||||
if (best == null || e < best) {
|
||||
best = e;
|
||||
}
|
||||
|
||||
if (worst == null || e > worst) {
|
||||
worst = e;
|
||||
}
|
||||
}
|
||||
|
||||
_watch.reset();
|
||||
print([
|
||||
'**Nanny**',
|
||||
'${(100 * goodCount / _buffer.length).toStringAsFixed(1)}%',
|
||||
'<= ${_maxFrameDuration.inMilliseconds}ms',
|
||||
'best:',
|
||||
best?.inMilliseconds,
|
||||
'avg:',
|
||||
_safeDivide(sum, _buffer.length),
|
||||
'worst',
|
||||
worst?.inMilliseconds
|
||||
].join(' '));
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
Object _safeDivide(Duration source, int divisor) {
|
||||
if (divisor == 0) {
|
||||
return double.nan;
|
||||
}
|
||||
return (source ~/ divisor).inMilliseconds;
|
||||
}
|
Loading…
Reference in new issue