game_bg.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_redux/flutter_redux.dart';
  3. import '../store/game_state.dart';
  4. import '../utils/screen.dart';
  5. /// 游戏格子背景
  6. class GameBg extends StatefulWidget {
  7. @override
  8. State<StatefulWidget> createState() => GameBgState();
  9. }
  10. class GameBgState extends State<StatefulWidget> {
  11. @override
  12. Widget build(BuildContext context) {
  13. return StoreConnector<GameState, GameBgProps>(
  14. converter: (store) => GameBgProps(
  15. borderWidth: Screen.getBorderWidth(store.state.mode),
  16. blockWidth: Screen.getBlockWidth(store.state.mode),
  17. mode: store.state.mode,
  18. ),
  19. builder: (context, vm) {
  20. return Container(
  21. padding: EdgeInsets.fromLTRB(vm.borderWidth, vm.borderWidth, 0, 0),
  22. decoration: BoxDecoration(
  23. color: const Color(0xffbbada0),
  24. border: Border.all(color: Colors.transparent, width: 0),
  25. borderRadius: BorderRadius.circular(5),
  26. ),
  27. child: getGrid(vm),
  28. );
  29. },
  30. );
  31. }
  32. getGrid(GameBgProps props) {
  33. var rows = <Widget>[];
  34. for (var i = 0; i < props.mode; i++) {
  35. var columns = <Widget>[];
  36. for (var j = 0; j < props.mode; j++) {
  37. columns.add(Container(
  38. width: props.blockWidth,
  39. height: props.blockWidth,
  40. decoration: BoxDecoration(
  41. color: Color.fromRGBO(238, 228, 218, 0.35),
  42. border: Border.all(color: Colors.transparent, width: 0),
  43. borderRadius: BorderRadius.circular(5),
  44. ),
  45. margin:
  46. EdgeInsets.fromLTRB(0, 0, props.borderWidth, props.borderWidth),
  47. ));
  48. }
  49. rows.add(Row(
  50. textDirection: TextDirection.ltr,
  51. crossAxisAlignment: CrossAxisAlignment.center,
  52. children: columns,
  53. ));
  54. }
  55. return Column(
  56. children: rows,
  57. crossAxisAlignment: CrossAxisAlignment.center,
  58. );
  59. }
  60. }
  61. class GameBgProps {
  62. double borderWidth;
  63. double blockWidth;
  64. int mode;
  65. GameBgProps({this.borderWidth, this.blockWidth, this.mode});
  66. }