NewBlock.dart 989 B

123456789101112131415161718192021222324252627282930313233
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_2048/views/NumberText.dart';
  3. import 'package:flutter_2048/views/block/BaseBlock.dart';
  4. import 'package:flutter_2048/model/BlockInfo.dart';
  5. class NewBlock extends BaseBlock {
  6. final BlockInfo info;
  7. NewBlock({
  8. Key key,
  9. this.info,
  10. AnimationController controller,
  11. }) : super(
  12. key: key,
  13. animation: new Tween<double>(begin: 0.1, end: 1.0).animate(controller),
  14. );
  15. @override
  16. Widget buildBlock(BuildContext context, BlockProps props) {
  17. Animation<double> animation = listenable;
  18. return Positioned(
  19. top:
  20. (info.current ~/ props.mode) * (props.blockWidth + props.borderWidth),
  21. left:
  22. (info.current % props.mode) * (props.blockWidth + props.borderWidth),
  23. child: Transform.scale(
  24. scale: animation.value,
  25. origin: Offset(0.5, 0.5),
  26. child: NumberText(value: this.info.value, size: props.blockWidth),
  27. ),
  28. );
  29. }
  30. }