scores.dart 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_2048/service/gameInit.dart';
  3. import 'package:flutter_2048/store/game_state.dart';
  4. import 'package:flutter_redux/flutter_redux.dart';
  5. class Scores extends StatelessWidget {
  6. @override
  7. Widget build(BuildContext context) {
  8. return StoreConnector<GameState, ScoresProps>(
  9. converter: (store) => ScoresProps(
  10. scores: store.state.status.scores,
  11. total: store.state.status.total,
  12. isEnd: store.state.status.end,
  13. reset: () {
  14. gameInit(store, store.state.mode);
  15. },
  16. ),
  17. // onDidChange: (props) {
  18. // if (props.isEnd && props.scores > props.total) {
  19. // SharedPreferences.getInstance().then((refs) {
  20. // refs.setInt('total_' + props.mode.toString(), props.scores);
  21. // });
  22. // }
  23. // },
  24. builder: (context, props) {
  25. return Column(
  26. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  27. children: <Widget>[
  28. Row(
  29. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  30. children: <Widget>[
  31. Text(
  32. '2048',
  33. style: TextStyle(
  34. fontSize: 50,
  35. color: Color(0xff776e65),
  36. fontWeight: FontWeight.bold),
  37. ),
  38. Row(
  39. mainAxisAlignment: MainAxisAlignment.end,
  40. children: <Widget>[
  41. Container(
  42. padding: EdgeInsets.fromLTRB(23, 5, 23, 5),
  43. margin: EdgeInsets.only(right: 5),
  44. decoration: BoxDecoration(
  45. color: Color(0xffbbada0),
  46. border: Border.all(color: Colors.transparent, width: 0),
  47. borderRadius: BorderRadius.circular(5),
  48. ),
  49. child: Column(
  50. children: <Widget>[
  51. Text(
  52. 'SCORE',
  53. style: TextStyle(
  54. color: Color(0xffeee4da),
  55. fontWeight: FontWeight.bold),
  56. ),
  57. Text(
  58. props.scores.toString(),
  59. style: TextStyle(
  60. color: Colors.white,
  61. fontWeight: FontWeight.bold),
  62. )
  63. ],
  64. ),
  65. ),
  66. Container(
  67. padding: EdgeInsets.fromLTRB(23, 5, 23, 5),
  68. decoration: BoxDecoration(
  69. color: Color(0xffbbada0),
  70. border: Border.all(color: Colors.transparent, width: 0),
  71. borderRadius: BorderRadius.circular(5),
  72. ),
  73. child: Column(
  74. children: <Widget>[
  75. Text(
  76. 'BEST',
  77. style: TextStyle(
  78. color: Color(0xffeee4da),
  79. fontWeight: FontWeight.bold),
  80. ),
  81. Text(
  82. props.total.toString(),
  83. style: TextStyle(
  84. color: Colors.white,
  85. fontWeight: FontWeight.bold),
  86. )
  87. ],
  88. ),
  89. )
  90. ],
  91. ),
  92. ],
  93. ),
  94. Row(
  95. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  96. children: <Widget>[
  97. Column(
  98. crossAxisAlignment: CrossAxisAlignment.start,
  99. children: <Widget>[
  100. Text(
  101. 'Play 2048 Game flutter',
  102. style: TextStyle(
  103. color: Color(0xff776e65),
  104. fontWeight: FontWeight.bold),
  105. ),
  106. Text(
  107. 'Join and get to the 2048 tile!',
  108. style: TextStyle(color: Color(0xff776e65)),
  109. ),
  110. ],
  111. ),
  112. FlatButton(
  113. color: Color(0xff8f7a66),
  114. textColor: Colors.white,
  115. onPressed: () => props.reset(),
  116. child: Text(
  117. 'New Game',
  118. style: TextStyle(fontWeight: FontWeight.bold),
  119. ),
  120. )
  121. ],
  122. ),
  123. ],
  124. );
  125. },
  126. );
  127. }
  128. }
  129. class ScoresProps {
  130. ScoresProps({this.mode, this.total, this.scores, this.isEnd, this.reset});
  131. int mode;
  132. int total;
  133. int scores;
  134. bool isEnd;
  135. Function reset;
  136. }