base_block.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/widgets.dart';
  2. import 'package:flutter_2048/store/game_state.dart';
  3. import 'package:flutter_2048/utils/screen.dart';
  4. import 'package:flutter_redux/flutter_redux.dart';
  5. /// AnimatedWidget 是一个抽象类,它继承自 StatefulWidget,它的作用是根据监听的动画的变化来刷新 UI。
  6. abstract class BaseBlock extends AnimatedWidget {
  7. BaseBlock({Key? key, required Animation animation})
  8. : super(
  9. key: key,
  10. listenable: animation,
  11. );
  12. @override
  13. Widget build(BuildContext context) {
  14. return StoreConnector<GameState, BlockProps>(
  15. converter: (store) => BlockProps(
  16. blockWidth: Screen.getBlockWidth(store.state.mode),
  17. borderWidth: Screen.getBorderWidth(store.state.mode),
  18. mode: store.state.mode,
  19. ),
  20. builder: buildBlock,
  21. );
  22. }
  23. @protected
  24. Widget buildBlock(
  25. BuildContext context,
  26. BlockProps props,
  27. );
  28. }
  29. class BlockProps {
  30. double blockWidth;
  31. double borderWidth;
  32. int mode;
  33. BlockProps(
  34. {required this.blockWidth,
  35. required this.borderWidth,
  36. required this.mode});
  37. }