scores.dart 4.9 KB

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