mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
// 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);
|
|
}
|