StudyInfoDetailsPage.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_habit/common/I18N.dart';
  3. import 'package:flutter_habit/provider/DataProvider.dart';
  4. import 'package:flutter_habit/database/entity/StudyInfo.dart';
  5. import 'package:flutter_habit/database/mapper/StudyInfoMapper.dart';
  6. import 'package:provider/provider.dart';
  7. class StudyInfoDetailsPage extends StatelessWidget {
  8. final StudyInfo studyInfo;
  9. StudyInfoDetailsPage(this.studyInfo);
  10. @override
  11. Widget build(BuildContext context) {
  12. return Scaffold(
  13. appBar: AppBar(
  14. title: Text(I18N.of("课程学习详情")),
  15. ),
  16. body: Padding(
  17. padding: EdgeInsets.all(16),
  18. child: ListView(
  19. children: <Widget>[
  20. Text(
  21. studyInfo.getCourseName()!,
  22. style: Theme.of(context).textTheme.titleLarge,
  23. ),
  24. Divider(),
  25. Row(
  26. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  27. children: <Widget>[
  28. Text(I18N.of("是否迟到")),
  29. Row(
  30. children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
  31. if (i is int) {
  32. return Radio<int>(
  33. value: i,
  34. groupValue: studyInfo.getIsLate(),
  35. onChanged: null,
  36. );
  37. } else if (i is String) {
  38. return Text(i);
  39. }
  40. return Container();
  41. }).toList(),
  42. )
  43. ],
  44. ),
  45. Row(
  46. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  47. children: <Widget>[
  48. Text(I18N.of("是否缺席")),
  49. Row(
  50. children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
  51. if (i is int) {
  52. return Radio<int>(
  53. value: i,
  54. groupValue: studyInfo.getIsAbsent(),
  55. onChanged: null,
  56. );
  57. } else if (i is String) {
  58. return Text(i);
  59. }
  60. return Container();
  61. }).toList(),
  62. )
  63. ],
  64. ),
  65. Row(
  66. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  67. children: <Widget>[
  68. Text(I18N.of("作业是否完成")),
  69. Row(
  70. children: [I18N.of("是"), 1, I18N.of("否"), 0].map((i) {
  71. if (i is int) {
  72. return Radio<int>(
  73. value: i,
  74. groupValue: studyInfo.getIsHomeWorkDone(),
  75. onChanged: null,
  76. );
  77. } else if (i is String) {
  78. return Text(i);
  79. }
  80. return Container();
  81. }).toList(),
  82. )
  83. ],
  84. ),
  85. Row(
  86. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  87. children: <Widget>[
  88. Text(I18N.of("课程难度")),
  89. Row(
  90. children: [
  91. I18N.of("简单"),
  92. 0,
  93. I18N.of("一般"),
  94. 1,
  95. I18N.of("困难"),
  96. 2
  97. ].map((i) {
  98. if (i is int) {
  99. return Radio<int>(
  100. value: i,
  101. groupValue: studyInfo.getDifficulty(),
  102. onChanged: null,
  103. );
  104. } else if (i is String) {
  105. return Text(i);
  106. }
  107. return Container();
  108. }).toList(),
  109. )
  110. ],
  111. ),
  112. studyInfo.getIsHomeWorkDone() == 1
  113. ? Container()
  114. : Column(
  115. children: <Widget>[
  116. Divider(),
  117. TextField(
  118. maxLines: 5,
  119. readOnly: true,
  120. controller: TextEditingController(
  121. text: studyInfo.getHomeworks()),
  122. decoration: InputDecoration(
  123. border: OutlineInputBorder(),
  124. labelText: I18N.of("未完成的作业"),
  125. ),
  126. ),
  127. Row(
  128. mainAxisAlignment: MainAxisAlignment.end,
  129. children: <Widget>[
  130. ElevatedButton(
  131. style: ButtonStyle(
  132. backgroundColor: MaterialStateProperty.all(
  133. Theme.of(context).colorScheme.secondary),
  134. foregroundColor: MaterialStateProperty.all(
  135. Theme.of(context).cardColor)),
  136. child: Text(I18N.of("已解决")),
  137. onPressed: () => solveHomeWork(context),
  138. ),
  139. ],
  140. ),
  141. ],
  142. ),
  143. studyInfo.getIsTroublesSolved() == 1
  144. ? Container()
  145. : Column(
  146. children: <Widget>[
  147. Divider(),
  148. TextFormField(
  149. maxLines: 5,
  150. readOnly: true,
  151. controller: TextEditingController(
  152. text: studyInfo.getTroubles()),
  153. decoration: InputDecoration(
  154. border: OutlineInputBorder(),
  155. labelText: I18N.of("遇到的问题"),
  156. ),
  157. ),
  158. Row(
  159. mainAxisAlignment: MainAxisAlignment.end,
  160. children: <Widget>[
  161. ElevatedButton(
  162. style: ButtonStyle(
  163. backgroundColor: MaterialStateProperty.all(
  164. Theme.of(context).colorScheme.secondary),
  165. foregroundColor: MaterialStateProperty.all(
  166. Theme.of(context).cardColor)),
  167. child: Text(I18N.of("已解决")),
  168. onPressed: () => solveTroubles(context),
  169. ),
  170. ],
  171. ),
  172. ],
  173. ),
  174. Divider(),
  175. Center(
  176. child: Text(
  177. DateTime.fromMillisecondsSinceEpoch(studyInfo.getDate()!)
  178. .toString()
  179. .substring(0, 16),
  180. style: Theme.of(context).textTheme.bodySmall,
  181. ),
  182. ),
  183. ],
  184. ),
  185. ),
  186. );
  187. }
  188. Future<void> solveTroubles(BuildContext context) async {
  189. StudyInfo s = StudyInfo();
  190. s.setId(studyInfo.getId());
  191. s.setIsTroublesSolved(1);
  192. await StudyInfoMapper().updateByFirstKeySelective(s);
  193. await Provider.of<DataProvider>(context, listen: false).loadStudyInfoData();
  194. Navigator.of(context).pop();
  195. }
  196. Future<void> solveHomeWork(BuildContext context) async {
  197. StudyInfo s = StudyInfo();
  198. s.setId(studyInfo.getId());
  199. s.setIsHomeWorkDone(1);
  200. await StudyInfoMapper().updateByFirstKeySelective(s);
  201. await Provider.of<DataProvider>(context, listen: false).loadStudyInfoData();
  202. Navigator.of(context).pop();
  203. }
  204. }