mirror of
https://github.com/flutter/samples.git
synced 2026-04-03 18:22:45 +00:00
Add flutter_web samples (#75)
This commit is contained in:
committed by
Andrew Brogdon
parent
42f2dce01b
commit
3fe927cb29
43
web/slide_puzzle/lib/src/puzzle_flow_delegate.dart
Normal file
43
web/slide_puzzle/lib/src/puzzle_flow_delegate.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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_animator.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);
|
||||
}
|
||||
Reference in New Issue
Block a user