feedback_detail_page.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:intl/intl.dart';
  4. import 'package:sport/application.dart';
  5. import 'package:sport/bean/feed_back.dart';
  6. import 'package:sport/provider/feed_back_model.dart';
  7. import 'package:sport/services/api/inject_api.dart';
  8. import 'package:sport/utils/toast.dart';
  9. import 'package:sport/widgets/appbar.dart';
  10. import 'package:sport/widgets/button_primary.dart';
  11. import 'package:sport/widgets/dialog/request_dialog.dart';
  12. import 'package:sport/widgets/space.dart';
  13. class FeedbackDetailPage extends StatefulWidget {
  14. final FeedTypeInfoData data;
  15. FeedbackDetailPage(this.data);
  16. @override
  17. State<StatefulWidget> createState() => _PageState();
  18. }
  19. class _PageState extends State<FeedbackDetailPage> with InjectApi {
  20. // List<String> tags;
  21. // List<String> tagsId;
  22. String? tag;
  23. String? tagId;
  24. String? _content;
  25. @override
  26. void initState() {
  27. super.initState();
  28. }
  29. postFeedBackpostFeedBack(String content, {String? typeId}) async {
  30. await api.postFeedback(typeId ?? "", content, extra: await Application.getDeviceInfo());
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. // String tag = "数据不同步";
  35. return Scaffold(
  36. backgroundColor: Colors.white,
  37. body: CustomScrollView(
  38. slivers: <Widget>[
  39. buildSliverAppBar(context, "${widget.data.groupName}"),
  40. SliverToBoxAdapter(
  41. child: Padding(
  42. padding: const EdgeInsets.all(12.0),
  43. child: Column(
  44. crossAxisAlignment: CrossAxisAlignment.start,
  45. children: <Widget>[
  46. Text("请选择问题类型", style: Theme.of(context).textTheme.headline3),
  47. Padding(
  48. padding: const EdgeInsets.symmetric(vertical: 6.0),
  49. child: Wrap(
  50. alignment: WrapAlignment.start,
  51. spacing: 12,
  52. children: (widget.data.types ?? []).map<Widget>((e) {
  53. return ChoiceChip(
  54. labelPadding: const EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
  55. pressElevation: 0,
  56. //未选定的时候背景
  57. selectedColor: Theme.of(context).accentColor,
  58. //被禁用得时候背景
  59. backgroundColor: Colors.white,
  60. disabledColor: Color(0xfff1f1f1),
  61. shape: StadiumBorder(
  62. side: BorderSide(color: Color(tag == e.typeName ? 0xffffffff : 0xffcecece), width: 0.5),
  63. ),
  64. selected: tag == e.typeName,
  65. label: Text("${e.typeName}"),
  66. onSelected: (value) {
  67. // if (tags.indexOf(e['typeName']) >= 0) {
  68. // tags.remove(e['typeName']);
  69. // tagsId.remove(e['typeId']);
  70. // setState(() {
  71. // tags = tags;
  72. // tagsId = tagsId;
  73. // });
  74. // } else {
  75. // tags.add(e['typeName']);
  76. // tagsId.add(e['typeId']);
  77. // setState(() {
  78. // tags = tags;
  79. // tagsId = tagsId;
  80. // });
  81. // }
  82. setState(() {
  83. tag = e.typeName;
  84. tagId = e.typeId!;
  85. });
  86. },
  87. );
  88. }).toList()),
  89. ),
  90. Space(
  91. height: 10,
  92. ),
  93. // Text("问题发生时间", style: Theme.of(context).textTheme.subtitle1!),
  94. // InkWell(
  95. // onTap: () async {
  96. // var result = await showDatePicker(
  97. // context: context,
  98. // initialDate: DateTime.now(),
  99. // firstDate: DateTime(1900),
  100. // lastDate: DateTime.now());
  101. // print('$result');
  102. // var time = await showTimePicker(
  103. // context: context, initialTime: TimeOfDay.now());
  104. // print('$time');
  105. // if (time != null) {
  106. // DateFormat.yM().format(result);
  107. // }
  108. // },
  109. // child: Container(
  110. // height: 30,
  111. // margin: const EdgeInsets.symmetric(vertical: 6.0),
  112. // decoration: BoxDecoration(
  113. // border: Border(
  114. // bottom: Divider.createBorderSide(context),
  115. // )),
  116. // ),
  117. // ),
  118. Space(
  119. height: 10,
  120. ),
  121. Text("问题详述", style: Theme.of(context).textTheme.subtitle1!),
  122. Space(
  123. height: 6,
  124. ),
  125. TextField(
  126. maxLines: 5,
  127. decoration: InputDecoration(
  128. enabledBorder: OutlineInputBorder(borderSide: BorderSide(width: 0.5, color: Theme.of(context).dividerTheme.color!)),
  129. hintText: '问题详述...',
  130. focusedBorder: OutlineInputBorder(borderSide: BorderSide(width: 0.5, color: Theme.of(context).accentColor)),
  131. ),
  132. onChanged: (value) {
  133. setState(() {
  134. _content = value;
  135. });
  136. },
  137. ),
  138. Space(
  139. height: 24,
  140. ),
  141. PrimaryButton(
  142. height: 40.0,
  143. content: "提交",
  144. callback: () async {
  145. if (tagId == null) {
  146. ToastUtil.show("请选择问题类型");
  147. return;
  148. }
  149. if ((_content?.isEmpty ?? true) == true) {
  150. ToastUtil.show("请详述反馈内容");
  151. return;
  152. }
  153. if (_content?.isNotEmpty == true) {
  154. await request(context, () async {
  155. postFeedBackpostFeedBack(_content!, typeId: tagId);
  156. });
  157. ToastUtil.show("感谢你的建议,我们会第一时间解决");
  158. Navigator.pop(context);
  159. }
  160. },
  161. )
  162. ],
  163. ),
  164. )),
  165. ],
  166. ));
  167. }
  168. }