combin_block.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_2048/views/number_text.dart';
  3. import 'package:flutter_2048/views/block/base_block.dart';
  4. import 'package:flutter_2048/views/block/move_block.dart';
  5. import 'package:flutter_2048/model/block_info.dart';
  6. class CombinBlock extends BaseBlock {
  7. final BlockInfo info;
  8. final int mode;
  9. final AnimationController moveController;
  10. CombinBlock({
  11. Key key,
  12. this.info,
  13. this.mode,
  14. this.moveController,
  15. AnimationController combinController,
  16. }) : super(
  17. key: key,
  18. animation:
  19. Tween<double>(begin: 1, end: 1.25).animate(combinController),
  20. );
  21. @override
  22. Widget buildBlock(BuildContext context, BlockProps props) {
  23. Animation<double> animation = listenable;
  24. return Stack(
  25. fit: StackFit.expand,
  26. children: <Widget>[
  27. MoveBlock(
  28. info: BlockInfo(
  29. isNew: false,
  30. value: info.value ~/ 2,
  31. before: info.before,
  32. current: info.current,
  33. ),
  34. mode: mode,
  35. controller: moveController,
  36. ),
  37. Positioned(
  38. top: (info.current ~/ props.mode) *
  39. (props.blockWidth + props.borderWidth),
  40. left: (info.current % props.mode) *
  41. (props.blockWidth + props.borderWidth),
  42. child: Transform.scale(
  43. scale: animation.value,
  44. origin: Offset(0.5, 0.5),
  45. child: NumberText(value: this.info.value, size: props.blockWidth),
  46. ),
  47. )
  48. ],
  49. );
  50. }
  51. }