base_block.dart 955 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. abstract class BaseBlock extends AnimatedWidget {
  6. BaseBlock({Key key, Animation animation})
  7. : super(
  8. key: key,
  9. listenable: animation,
  10. );
  11. @override
  12. Widget build(BuildContext context) {
  13. return StoreConnector<GameState, BlockProps>(
  14. converter: (store) => BlockProps(
  15. blockWidth: Screen.getBlockWidth(store.state.mode),
  16. borderWidth: Screen.getBorderWidth(store.state.mode),
  17. mode: store.state.mode,
  18. ),
  19. builder: buildBlock,
  20. );
  21. }
  22. @protected
  23. Widget buildBlock(
  24. BuildContext context,
  25. BlockProps props,
  26. );
  27. }
  28. class BlockProps {
  29. double blockWidth;
  30. double borderWidth;
  31. int mode;
  32. BlockProps({this.blockWidth, this.borderWidth, this.mode});
  33. }