1
0
mirror of https://github.com/flutter/samples.git synced 2026-03-25 13:51:35 +00:00
Files
samples/web/slide_puzzle/lib/src/puzzle_flow_delegate.dart
2019-05-25 22:12:58 -07:00

44 lines
1.3 KiB
Dart

// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'core/puzzle_proxy.dart';
import 'flutter.dart';
class PuzzleFlowDelegate extends FlowDelegate {
final Size _tileSize;
final PuzzleProxy _puzzleProxy;
PuzzleFlowDelegate(this._tileSize, this._puzzleProxy, Listenable repaint)
: super(repaint: repaint);
@override
Size getSize(BoxConstraints constraints) => Size(
_tileSize.width * _puzzleProxy.width,
_tileSize.height * _puzzleProxy.height);
@override
BoxConstraints getConstraintsForChild(int i, BoxConstraints constraints) =>
BoxConstraints.tight(_tileSize);
@override
void paintChildren(FlowPaintingContext context) {
for (var i = 0; i < _puzzleProxy.length; i++) {
final tileLocation = _puzzleProxy.location(i);
context.paintChild(
i,
transform: Matrix4.translationValues(
tileLocation.x * _tileSize.width,
tileLocation.y * _tileSize.height,
i.toDouble(),
),
);
}
}
@override
bool shouldRepaint(covariant PuzzleFlowDelegate oldDelegate) =>
_tileSize != oldDelegate._tileSize ||
!identical(oldDelegate._puzzleProxy, _puzzleProxy);
}