team_create_page.dart 10 KB

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