基础组件库
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:image_picker/image_picker.dart';
  6. import 'package:permission_handler/permission_handler.dart';
  7. import 'package:zhiying_base_widget/pages/feedback_page/feedback_record_page.dart';
  8. import 'package:zhiying_base_widget/pages/feedback_page/widgets/feedback_image.dart';
  9. import 'package:zhiying_base_widget/pages/feedback_page/widgets/feedback_tab_widget.dart';
  10. import 'package:zhiying_base_widget/widgets/others/action_selected_alert/action_selected_alert.dart';
  11. import 'package:zhiying_comm/util/log/let_log.dart';
  12. class FeedbackPage extends StatefulWidget {
  13. @override
  14. _FeedbackPageState createState() => _FeedbackPageState();
  15. }
  16. class _FeedbackPageState extends State<FeedbackPage> {
  17. List<File> _images = List();
  18. bool _submitable = false;
  19. TextEditingController _feedback = TextEditingController();
  20. @override
  21. void dispose() {
  22. _feedback.dispose();
  23. super.dispose();
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. return Scaffold(
  28. resizeToAvoidBottomInset: false,
  29. appBar: _createNav(),
  30. body: GestureDetector(
  31. onTap: () {
  32. FocusScope.of(context).requestFocus(FocusNode());
  33. },
  34. child: SafeArea(
  35. child: Column(
  36. children: <Widget>[
  37. Expanded(
  38. child: SingleChildScrollView(
  39. child: Column(
  40. children: <Widget>[
  41. Container(
  42. width: double.infinity,
  43. margin: EdgeInsets.only(
  44. top: 10, bottom: 10, left: 12.5, right: 12.5),
  45. padding: EdgeInsets.all(12.5),
  46. decoration: BoxDecoration(
  47. color: Colors.white,
  48. borderRadius: BorderRadius.circular(7.5)),
  49. child: Column(
  50. crossAxisAlignment: CrossAxisAlignment.start,
  51. mainAxisAlignment: MainAxisAlignment.start,
  52. children: <Widget>[
  53. _createTitle(),
  54. _createUpload(),
  55. _createSubmit(),
  56. ],
  57. ),
  58. )
  59. ],
  60. ),
  61. ),
  62. ),
  63. Center(
  64. child: GestureDetector(
  65. behavior: HitTestBehavior.opaque,
  66. onTap: () {
  67. Navigator.push(
  68. context,
  69. CupertinoPageRoute(
  70. builder: (_) => FeedbackRecordPage(),
  71. ),
  72. );
  73. },
  74. child: Container(
  75. width: 120,
  76. height: 30,
  77. margin: EdgeInsets.all(10),
  78. decoration: BoxDecoration(
  79. color: Colors.white,
  80. borderRadius: BorderRadius.circular(15)),
  81. child: Row(
  82. mainAxisAlignment: MainAxisAlignment.center,
  83. crossAxisAlignment: CrossAxisAlignment.center,
  84. children: <Widget>[
  85. Padding(
  86. padding: EdgeInsets.only(right: 6),
  87. child: Icon(
  88. Icons.list,
  89. size: 12,
  90. ),
  91. ),
  92. Text(
  93. '反馈记录',
  94. style:
  95. TextStyle(fontSize: 13, color: Color(0xff333333)),
  96. )
  97. ],
  98. ),
  99. ),
  100. ),
  101. ),
  102. ],
  103. ),
  104. ),
  105. ),
  106. );
  107. }
  108. // 导航栏
  109. Widget _createNav() {
  110. return CupertinoNavigationBar(
  111. border: Border(
  112. bottom: BorderSide(
  113. width: 0.0, // One physical pixel.
  114. style: BorderStyle.none,
  115. ),
  116. ),
  117. backgroundColor: Colors.white,
  118. leading: Navigator.canPop(context)
  119. ? GestureDetector(
  120. child: Container(
  121. padding: EdgeInsets.zero,
  122. child: Icon(
  123. Icons.arrow_back_ios,
  124. size: 20,
  125. ),
  126. ),
  127. onTap: () {
  128. if (Navigator.canPop(context)) {
  129. Navigator.pop(context);
  130. }
  131. },
  132. )
  133. : Container(),
  134. middle: Text(
  135. '意见反馈',
  136. style: TextStyle(
  137. fontSize: 15,
  138. color: Color(0xff333333),
  139. ),
  140. ),
  141. );
  142. }
  143. Widget _createTitle() {
  144. return Column(
  145. crossAxisAlignment: CrossAxisAlignment.start,
  146. mainAxisAlignment: MainAxisAlignment.start,
  147. children: <Widget>[
  148. Text(
  149. '反馈描述',
  150. style: TextStyle(
  151. fontSize: 14,
  152. color: Color(0xff333333),
  153. fontWeight: FontWeight.bold,
  154. ),
  155. ),
  156. Padding(
  157. padding: EdgeInsets.only(top: 4, bottom: 4),
  158. child: Row(
  159. children: List.generate(
  160. 3,
  161. (index) => Expanded(
  162. child: Container(
  163. margin: EdgeInsets.only(left: 2, right: 2),
  164. height: 28,
  165. child: FeedbackTabWidget('功能异常')),
  166. )),
  167. ),
  168. ),
  169. Container(
  170. height: 118,
  171. margin: EdgeInsets.only(left: 2, right: 2, top: 4, bottom: 4),
  172. child: CupertinoTextField(
  173. controller: _feedback,
  174. textAlignVertical: TextAlignVertical.top,
  175. style: TextStyle(fontSize: 12, color: Color(0xff333333)),
  176. maxLines: null,
  177. placeholder: '请输入您的意见(最多100个字)',
  178. placeholderStyle: TextStyle(
  179. fontSize: 12,
  180. color: Color(0xff999999),
  181. ),
  182. decoration: BoxDecoration(
  183. color: Color(0xfff9f9f9),
  184. borderRadius: BorderRadius.circular(7.5)),
  185. onChanged: (value) {
  186. if (value == null || value == '') {
  187. _submitable = false;
  188. } else {
  189. _submitable = true;
  190. }
  191. setState(() {});
  192. },
  193. ),
  194. ),
  195. ],
  196. );
  197. }
  198. Widget _createUpload() {
  199. List<Widget> images = List();
  200. _images.forEach((file) {
  201. images.add(Container(
  202. margin: EdgeInsets.only(top: 4, bottom: 4, right: 8),
  203. width: 80,
  204. height: 80,
  205. child: FeedbackImageWidget(
  206. file: file,
  207. onDelete: () {
  208. _images.remove(file);
  209. setState(() {});
  210. },
  211. ),
  212. ));
  213. });
  214. if (images.length < 4) {
  215. images.add(GestureDetector(
  216. child: Container(
  217. margin: EdgeInsets.only(top: 4, bottom: 4),
  218. decoration: BoxDecoration(
  219. borderRadius: BorderRadius.circular(7.5),
  220. color: Color(0xfff9f9f9)),
  221. height: 80,
  222. width: 80,
  223. child: Icon(
  224. Icons.add,
  225. size: 60,
  226. color: Color(0xffd8d8d8),
  227. ),
  228. ),
  229. onTap: _onAddImage,
  230. ));
  231. }
  232. return Column(
  233. children: <Widget>[
  234. Row(
  235. children: <Widget>[
  236. Padding(
  237. padding: EdgeInsets.only(right: 10, top: 4, bottom: 4),
  238. child: Text(
  239. '上传图片',
  240. style: TextStyle(
  241. fontSize: 14,
  242. color: Color(0xff333333),
  243. fontWeight: FontWeight.bold,
  244. ),
  245. ),
  246. ),
  247. Text(
  248. '最多上传4张,大小不超过1M/张',
  249. style: TextStyle(
  250. fontSize: 12,
  251. color: Color(0xff999999),
  252. ),
  253. ),
  254. ],
  255. ),
  256. Row(
  257. children: images,
  258. )
  259. ],
  260. );
  261. }
  262. Widget _createSubmit() {
  263. return GestureDetector(
  264. onTap: () {
  265. if (!_submitable) {
  266. return;
  267. }
  268. Logger.debug('提交:${_feedback.text.toString()}');
  269. },
  270. child: Container(
  271. margin: EdgeInsets.only(top: 24, bottom: 4),
  272. height: 45,
  273. decoration: BoxDecoration(
  274. color: _submitable ? Colors.redAccent : Color(0xffffe1e1),
  275. borderRadius: BorderRadius.circular(7.5),
  276. ),
  277. child: Center(
  278. child: Text(
  279. '提交意见',
  280. style: TextStyle(
  281. fontSize: 14,
  282. color: Colors.white,
  283. ),
  284. ),
  285. ),
  286. ),
  287. );
  288. }
  289. void _onAddImage() async {
  290. if (_images.length >= 4) {
  291. Fluttertoast.showToast(msg: '最多上传4张图片');
  292. return;
  293. }
  294. var status = await Permission.photos.status;
  295. if (status != PermissionStatus.granted) {
  296. status = await Permission.photos.request();
  297. }
  298. if (status == PermissionStatus.denied) {
  299. Fluttertoast.showToast(msg: '暂无权限,图片选择失败');
  300. return null;
  301. }
  302. final picker = ImagePicker();
  303. PickedFile file;
  304. int index = await showModalBottomSheet(
  305. context: context,
  306. builder: (context) {
  307. return ActionSelectedAlert(
  308. // title: '拍照/选择图片',
  309. actions: ['拍照', '从相册选择图片'],
  310. );
  311. },
  312. isScrollControlled: false,
  313. backgroundColor: Colors.transparent);
  314. if (index != null) {
  315. if (index == 0) {
  316. file = await picker.getImage(source: ImageSource.camera);
  317. } else {
  318. file = await picker.getImage(source: ImageSource.gallery);
  319. }
  320. if (file == null) return;
  321. setState(() {
  322. _images.add(File(file.path));
  323. });
  324. // File resultFile = await EncodeUtil.compressImage(file, 800);
  325. }
  326. }
  327. }