team_create_page.dart 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import 'dart:io';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:image_picker/image_picker.dart';
  6. import 'package:keyboard_actions/keyboard_actions.dart';
  7. import 'package:liftmanager/internal/team/page/input_text_page.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/app_navigator.dart';
  12. import 'package:liftmanager/utils/theme_utils.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_bar.dart';
  15. import 'package:liftmanager/widgets/click_item.dart';
  16. import 'package:liftmanager/widgets/load_image.dart';
  17. import 'package:liftmanager/widgets/my_button.dart';
  18. import 'package:liftmanager/widgets/selected_image.dart';
  19. import 'package:liftmanager/widgets/text_field_item.dart';
  20. class TeamCreatePage extends StatefulWidget {
  21. @override
  22. State<StatefulWidget> createState() {
  23. return TeamCreatePageState();
  24. }
  25. }
  26. class TeamCreatePageState extends State<TeamCreatePage> {
  27. File _imageFile;
  28. final FocusNode _nodeText1 = FocusNode();
  29. final FocusNode _nodeText2 = FocusNode();
  30. final FocusNode _nodeText3 = FocusNode();
  31. TextEditingController _teamNameController = TextEditingController();
  32. TextEditingController _nameController = TextEditingController();
  33. TextEditingController _phoneController = TextEditingController();
  34. String _remarks = "";
  35. void _getImage(int key) async {
  36. try {
  37. _imageFile = await ImagePicker.pickImage(
  38. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  39. maxWidth: 800,
  40. imageQuality: 30);
  41. setState(() {});
  42. } catch (e) {
  43. toasts("没有权限,无法打开相册!");
  44. }
  45. }
  46. void selectPicker() {
  47. showDialog(
  48. context: context,
  49. builder: (BuildContext context) {
  50. return SimpleDialog(
  51. title: Text("选择方式"),
  52. children: ["拍照", '从手机相册选择'].map((String value) {
  53. print("$value");
  54. return SimpleDialogOption(
  55. child: Text(
  56. "${value}",
  57. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  58. ),
  59. onPressed: () {
  60. _getImage(value == '拍照' ? 1 : 0);
  61. Navigator.of(context).pop();
  62. },
  63. );
  64. }).toList());
  65. });
  66. }
  67. ///创建团队
  68. createTeamAction() {
  69. var team_name = _teamNameController.text.toString().trim();
  70. var name = _nameController.text.toString().trim();
  71. var phone = _phoneController.text.toString().trim();
  72. if (_imageFile == null) {
  73. toasts("请上传团队logo");
  74. return;
  75. }
  76. if (team_name.isEmpty) {
  77. toasts("请填写团队名称");
  78. return;
  79. }
  80. if (name.isEmpty) {
  81. toasts("请填写联系人姓名");
  82. return;
  83. }
  84. if (phone.isEmpty) {
  85. toasts("请填写联系电话");
  86. return;
  87. }
  88. print(_imageFile.path);
  89. showLoading(context, "正在创建...");
  90. NewApiService().upload(_imageFile.path, onSuccess: (data) {
  91. ApiService(context: context).teamCreate(
  92. data.pathUrl, team_name, _remarks, name, phone, onSuccess: (data) {
  93. showAlert(context, "提示", "创建成功", "确定", () {
  94. dismissLoading(context);
  95. NavigatorUtils.goBack(context);
  96. NavigatorUtils.goBackWithParams(context, true);
  97. });
  98. }, onError: (code, msg) {
  99. dismissLoading(context);
  100. toasts(msg);
  101. });
  102. }, onError: (code, msg) {
  103. toasts(msg);
  104. });
  105. }
  106. @override
  107. Widget build(BuildContext context) {
  108. return Scaffold(
  109. //resizeToAvoidBottomPadding: false,
  110. appBar: const MyAppBar(
  111. centerTitle: "创建团队",
  112. // actions: <Widget>[
  113. // FlatButton(
  114. // child: Text("保存", key: const Key('actionName'),style: TextStyle(color: Colors.white),),
  115. // textColor: Colours.material_bg,
  116. // color: Colours.material_bg
  117. // )
  118. // ],
  119. ),
  120. body: SafeArea(
  121. child: Column(
  122. children: <Widget>[
  123. Expanded(
  124. flex: 1,
  125. child: defaultTargetPlatform == TargetPlatform.iOS
  126. ? FormKeyboardActions(
  127. child: Container(
  128. color: ThemeUtils.getTabsBg(context),
  129. child: _buildBody(),
  130. ))
  131. : SingleChildScrollView(
  132. child: Container(
  133. color: ThemeUtils.getTabsBg(context),
  134. child: _buildBody(),
  135. )),
  136. )
  137. ],
  138. ),
  139. ),
  140. );
  141. }
  142. _buildBody() {
  143. return Padding(
  144. padding: const EdgeInsets.symmetric(vertical: 10.0),
  145. child: Stack(
  146. children: [
  147. Column(
  148. // crossAxisAlignment: CrossAxisAlignment.start,
  149. children: <Widget>[
  150. Gaps.vGap5,
  151. Row(
  152. children: [
  153. Container(
  154. height: 13,
  155. width: 2,
  156. color: Colours.blue_app_main,
  157. ),
  158. SizedBox(
  159. width: 10,
  160. ),
  161. Text("团队资料", style: TextStyles.textBold18),
  162. ],
  163. ),
  164. // const Padding(
  165. // padding: const EdgeInsets.only(left: 16.0),
  166. // child: const Text("团队资料", style: TextStyles.textBold18),
  167. // ),
  168. // Gaps.vGap16,
  169. // Center(
  170. // child: SelectedImage(
  171. // image: _imageFile,
  172. // onTap: selectPicker
  173. // ),
  174. // ),
  175. // Gaps.vGap10,
  176. // Center(
  177. // child: Text(
  178. // "团队logo",
  179. // style: Theme.of(context).textTheme.subtitle.copyWith(fontSize: Dimens.font_sp14),
  180. // ),
  181. // ),
  182. // Gaps.vGap16,體育
  183. ClickItem(
  184. title: '团队LOGO',
  185. // subwidget: Container(
  186. // padding: EdgeInsets.only(right: 10),
  187. // child: ClipRRect(
  188. // borderRadius: BorderRadius.circular(15),
  189. // child: Container(
  190. // width: 30,
  191. // height: 30,
  192. // color: Color(0xffFAF7FA),
  193. // // padding: EdgeInsets.all(2),
  194. // child: LoadAssetImage(
  195. // _imageFile?.path ?? "",
  196. // // fit: BoxFit.cover,
  197. // // width: 100,
  198. // // height: 100,
  199. // ),
  200. // ),
  201. // ),
  202. // ),
  203. hasPicRight: "${_imageFile?.path ?? ""}",
  204. rightPicIsAsset: true,
  205. onTap: () {
  206. selectPicker();
  207. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  208. },
  209. ),
  210. TextFieldItem(
  211. focusNode: _nodeText1,
  212. controller: _teamNameController,
  213. title: "团队名称",
  214. hintText: "填写团队名称"),
  215. ClickItem(
  216. title: "团队简介",
  217. content: _remarks,
  218. onTap: () {
  219. AppNavigator.pushResult(
  220. context,
  221. InputTextPage(
  222. title: "团队简介",
  223. hintText: "请填写...",
  224. content: _remarks,
  225. ), (result) {
  226. setState(() {
  227. _remarks = result.toString();
  228. });
  229. });
  230. },
  231. ),
  232. Gaps.vGap16,
  233. Gaps.vGap16,
  234. Row(
  235. children: [
  236. Container(
  237. height: 13,
  238. width: 2,
  239. color: Colours.blue_app_main,
  240. ),
  241. SizedBox(
  242. width: 10,
  243. ),
  244. Text("联系人信息", style: TextStyles.textBold18),
  245. ],
  246. ),
  247. // const Padding(
  248. // padding: const EdgeInsets.only(left: 16.0),
  249. // child: const Text("联系人信息", style: TextStyles.textBold18),
  250. // ),
  251. TextFieldItem(
  252. focusNode: _nodeText2,
  253. title: "联系人",
  254. controller: _nameController,
  255. hintText: "填写联系人姓名"),
  256. TextFieldItem(
  257. focusNode: _nodeText3,
  258. title: "联系电话",
  259. controller: _phoneController,
  260. hintText: "填写联系电话号码"),
  261. // Expanded(child: Container()),
  262. SizedBox(
  263. height: 100,
  264. ),
  265. ],
  266. ),
  267. Positioned(
  268. bottom: 5,
  269. left: 5,
  270. right: 5,
  271. child: MyButton(
  272. backColor: Colours.blue_app_main,
  273. onPressed: () {
  274. createTeamAction();
  275. },
  276. text: "提交",
  277. ),
  278. )
  279. ],
  280. ));
  281. }
  282. }