team_create_page.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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/my_button.dart';
  17. import 'package:liftmanager/widgets/selected_image.dart';
  18. import 'package:liftmanager/widgets/text_field_item.dart';
  19. class TeamCreatePage extends StatefulWidget{
  20. @override
  21. State<StatefulWidget> createState() {
  22. return TeamCreatePageState();
  23. }
  24. }
  25. class TeamCreatePageState extends State<TeamCreatePage>{
  26. File _imageFile;
  27. final FocusNode _nodeText1 = FocusNode();
  28. final FocusNode _nodeText2 = FocusNode();
  29. final FocusNode _nodeText3 = FocusNode();
  30. TextEditingController _teamNameController = TextEditingController();
  31. TextEditingController _nameController = TextEditingController();
  32. TextEditingController _phoneController = TextEditingController();
  33. String _remarks = "";
  34. void _getImage(int key) async{
  35. try {
  36. _imageFile = await ImagePicker.pickImage(source: key == 1 ? ImageSource.camera : ImageSource.gallery, maxWidth: 800, imageQuality: 95);
  37. setState(() {});
  38. } catch (e) {
  39. toasts("没有权限,无法打开相册!");
  40. }
  41. }
  42. void selectPicker() {
  43. showDialog(
  44. context: context,
  45. builder: (BuildContext context) {
  46. return SimpleDialog(
  47. title: Text("选择方式"),
  48. children: ["拍照", '从手机相册选择'].map((String value) {
  49. print("$value");
  50. return SimpleDialogOption(
  51. child: Text(
  52. "${value}",
  53. style: TextStyle(
  54. fontSize:16, fontWeight: FontWeight.w500),
  55. ),
  56. onPressed: () {
  57. _getImage(value == '拍照' ? 1 : 0);
  58. Navigator.of(context).pop();
  59. },
  60. );
  61. }).toList());
  62. });
  63. }
  64. ///创建团队
  65. createTeamAction(){
  66. var team_name = _teamNameController.text.toString().trim();
  67. var name = _nameController.text.toString().trim();
  68. var phone = _phoneController.text.toString().trim();
  69. if(_imageFile == null){
  70. toasts("请上传团队logo");
  71. return;
  72. }
  73. if(team_name.isEmpty){
  74. toasts("请填写团队名称");
  75. return;
  76. }
  77. if(name.isEmpty){
  78. toasts("请填写联系人姓名");
  79. return;
  80. }
  81. if(phone.isEmpty){
  82. toasts("请填写联系电话");
  83. return;
  84. }
  85. print(_imageFile.path);
  86. showLoading(context, "正在创建...");
  87. ApiService(context: context).upload(_imageFile.path,onSuccess: (data){
  88. ApiService(context: context).teamCreate(data, team_name, _remarks, name, phone,onSuccess: (data){
  89. showAlert(context, "提示", "创建成功", "确定", (){
  90. dismissLoading(context);
  91. NavigatorUtils.goBack(context);
  92. NavigatorUtils.goBackWithParams(context,true);
  93. });
  94. },onError: (code,msg){
  95. dismissLoading(context);
  96. toasts(msg);
  97. });
  98. },onError: (code,msg){
  99. toasts(msg);
  100. });
  101. }
  102. @override
  103. Widget build(BuildContext context) {
  104. return Scaffold(
  105. //resizeToAvoidBottomPadding: false,
  106. appBar: const MyAppBar(
  107. centerTitle: "创建团队",
  108. // actions: <Widget>[
  109. // FlatButton(
  110. // child: Text("保存", key: const Key('actionName'),style: TextStyle(color: Colors.white),),
  111. // textColor: Colours.material_bg,
  112. // color: Colours.material_bg
  113. // )
  114. // ],
  115. ),
  116. body: SafeArea(
  117. child: Column(
  118. children: <Widget>[
  119. Expanded(
  120. flex: 1,
  121. child: defaultTargetPlatform == TargetPlatform.iOS ? FormKeyboardActions(
  122. child:Container(
  123. color: ThemeUtils.getTabsBg(context),
  124. child: _buildBody(),
  125. )
  126. ) : SingleChildScrollView(
  127. child: Container(
  128. color: ThemeUtils.getTabsBg(context),
  129. child: _buildBody(),
  130. )
  131. ),
  132. )
  133. ],
  134. ),
  135. ),
  136. );
  137. }
  138. _buildBody(){
  139. return Padding(
  140. padding: const EdgeInsets.symmetric(vertical: 16.0),
  141. child: Column(
  142. crossAxisAlignment: CrossAxisAlignment.start,
  143. children: <Widget>[
  144. Gaps.vGap5,
  145. const Padding(
  146. padding: const EdgeInsets.only(left: 16.0),
  147. child: const Text("团队资料", style: TextStyles.textBold18),
  148. ),
  149. Gaps.vGap16,
  150. Center(
  151. child: SelectedImage(
  152. image: _imageFile,
  153. onTap: selectPicker
  154. ),
  155. ),
  156. Gaps.vGap10,
  157. Center(
  158. child: Text(
  159. "团队logo",
  160. style: Theme.of(context).textTheme.subtitle.copyWith(fontSize: Dimens.font_sp14),
  161. ),
  162. ),
  163. Gaps.vGap16,
  164. TextFieldItem(
  165. focusNode: _nodeText1,
  166. controller: _teamNameController,
  167. title: "团队名称",
  168. hintText: "填写团队名称"
  169. ),
  170. ClickItem(
  171. title: "团队简介",
  172. content: _remarks,
  173. onTap: (){
  174. AppNavigator.pushResult(context,
  175. InputTextPage(
  176. title: "团队简介",
  177. hintText: "请填写...",
  178. content: _remarks,
  179. ), (result){
  180. setState(() {
  181. _remarks =result.toString();
  182. });
  183. });
  184. },
  185. ),
  186. Gaps.vGap16,
  187. Gaps.vGap16,
  188. const Padding(
  189. padding: const EdgeInsets.only(left: 16.0),
  190. child: const Text("联系人信息", style: TextStyles.textBold18),
  191. ),
  192. TextFieldItem(
  193. focusNode: _nodeText2,
  194. title: "联系人",
  195. controller: _nameController,
  196. hintText: "填写联系人姓名"
  197. ),
  198. TextFieldItem(
  199. focusNode: _nodeText3,
  200. title: "联系电话",
  201. controller: _phoneController,
  202. hintText: "填写联系电话号码"
  203. ),
  204. Padding(
  205. padding: const EdgeInsets.all(16),
  206. child: MyButton(
  207. onPressed: (){
  208. createTeamAction();
  209. },
  210. text: "提交",
  211. ),
  212. )
  213. ],
  214. ),
  215. );
  216. }
  217. }