personal_page.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:liftmanager/res/gaps.dart';
  4. import 'package:liftmanager/net/api_service.dart';
  5. import 'package:liftmanager/utils/toast.dart';
  6. import 'package:liftmanager/widgets/app_bar.dart';
  7. import 'package:liftmanager/internal/search/search_router.dart';
  8. import 'package:liftmanager/widgets/app_search_bar.dart';
  9. import 'package:liftmanager/utils/image_utils.dart';
  10. import 'package:liftmanager/res/resources.dart';
  11. import 'package:liftmanager/routers/fluro_navigator.dart';
  12. import 'package:liftmanager/widgets/load_image.dart';
  13. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  14. import 'package:liftmanager/widgets/click_item.dart';
  15. import 'package:flutter_screenutil/flutter_screenutil.dart';
  16. import 'package:provider/provider.dart';
  17. import 'package:liftmanager/internal/account/account_router.dart';
  18. import 'package:liftmanager/common/common.dart';
  19. import 'package:liftmanager/internal/account/provider/user_provider.dart';
  20. import 'package:liftmanager/internal/account/model/user_info_entity.dart';
  21. import 'package:liftmanager/internal/team/team_router.dart';
  22. import 'package:liftmanager/common/user_db.dart';
  23. import 'package:liftmanager/internal/wode/page/edit_text_page.dart';
  24. import 'package:image_picker/image_picker.dart';
  25. import 'package:liftmanager/utils/utils.dart';
  26. import 'package:liftmanager/internal/wode/wode_router.dart';
  27. import 'package:flustars/flustars.dart' as FlutterStars;
  28. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  29. class PersonalPage extends StatefulWidget {
  30. // BuyService(this.id);
  31. // final String id;
  32. @override
  33. State<StatefulWidget> createState() {
  34. return PersonalPageState();
  35. }
  36. }
  37. class PersonalPageState extends State<PersonalPage>
  38. with AutomaticKeepAliveClientMixin {
  39. // PersonalPageState({Key key}) : super(key: key);
  40. UserProvider provider = UserProvider();
  41. var _unameController = new TextEditingController();
  42. FocusNode blankNode = FocusNode();
  43. @override
  44. void initState() {
  45. UmengCommonSdk.onPageStart("我的-个人资料");
  46. super.initState();
  47. // User().getCurrentUser().then((res){
  48. // setUser(res);
  49. // });
  50. getUserInfo();
  51. }
  52. ///获取用户信息
  53. void getUserInfo() {
  54. ApiService().userInfo(
  55. onSuccess: (data) {
  56. print(data);
  57. setUser(data);
  58. _unameController.text = provider.user?.signature;
  59. },
  60. onError: (code, msg) {});
  61. }
  62. void setUser(UserInfoEntity user) {
  63. print(user.userName);
  64. print(user.avatarUrl);
  65. print("8653555------------");
  66. provider.setUser(user);
  67. FlutterStars.SpUtil.putString('username', user.nickName);
  68. FlutterStars.SpUtil.putString('avatarUrl', user.avatarUrl);
  69. }
  70. ///选择图片
  71. void selectPicker() {
  72. showDialog(
  73. context: context,
  74. builder: (BuildContext context) {
  75. return SimpleDialog(
  76. title: Text("修改头像"),
  77. children: ["拍照", '从手机相册选择'].map((String value) {
  78. print("$value");
  79. return SimpleDialogOption(
  80. child: Text(
  81. "${value}",
  82. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  83. ),
  84. onPressed: () {
  85. _getImage(value == '拍照' ? 1 : 0);
  86. Navigator.of(context).pop();
  87. },
  88. );
  89. }).toList());
  90. });
  91. }
  92. void _getImage(int key) async {
  93. try {
  94. var _imageFile = await ImagePicker.pickImage(
  95. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  96. maxWidth: 800,
  97. imageQuality: 95);
  98. if (_imageFile != null) {
  99. updateAvatar(_imageFile);
  100. setState(() {});
  101. }
  102. } catch (e) {
  103. toasts("没有权限,无法打开相册!");
  104. }
  105. }
  106. void updateAvatar(File imageFile) {
  107. List<File> list = [imageFile];
  108. ApiService(context: context).uploadMore(list, onSuccess: (imgs) {
  109. ApiService(context: context).modifyAvatar(imgs[0], onSuccess: (res) {
  110. if (res != null) {
  111. getUserInfo();
  112. }
  113. }, onError: (code, msg) {
  114. toasts(msg);
  115. });
  116. });
  117. }
  118. // 修改用户昵称
  119. void _modifyName(value) {
  120. ApiService(context: context).userUpdate(value, onSuccess: (res) {
  121. // if (res != null) {
  122. getUserInfo();
  123. // }
  124. }, onError: (code, msg) {
  125. toasts(msg);
  126. });
  127. }
  128. // 修改用户名
  129. void _modifyNames(value) {
  130. ApiService(context: context).userUpdates(value, onSuccess: (res) {
  131. // if (res != null) {
  132. getUserInfo();
  133. // }
  134. }, onError: (code, msg) {
  135. toasts(msg);
  136. });
  137. }
  138. // 修改简介
  139. void _submit(value) {
  140. ApiService(context: context).userUpdateJj(value, onSuccess: (res) {
  141. // if (res != null) {
  142. toasts("保存成功");
  143. getUserInfo();
  144. // }
  145. }, onError: (code, msg) {
  146. toasts(msg);
  147. });
  148. }
  149. @override
  150. void dispose() {
  151. UmengCommonSdk.onPageEnd("我的-个人资料");
  152. // provider.dispose();
  153. super.dispose();
  154. }
  155. @override
  156. Widget build(BuildContext context) {
  157. double width = MediaQuery.of(context).size.width;
  158. double height = MediaQuery.of(context).size.height;
  159. return ChangeNotifierProvider<UserProvider>(
  160. create: (_) => provider,
  161. child: Container(
  162. child: Scaffold(
  163. resizeToAvoidBottomPadding: false,
  164. appBar: MyAppBar(
  165. centerTitle: "个人资料",
  166. actions: <Widget>[
  167. Utils.getAuthByRouter(context, 'people_nearby', false) &&
  168. FlutterStars.SpUtil.getInt("expertFlag") != 1
  169. ? FlatButton(
  170. child: Text("申请为专家"),
  171. textColor: Colours.text,
  172. highlightColor: Colors.transparent,
  173. onPressed: () {
  174. NavigatorUtils.push(context, WodeRouter.masterBecome);
  175. },
  176. )
  177. : Container()
  178. ],
  179. ),
  180. body: GestureDetector(
  181. onTap: () {
  182. // 点击空白页面关闭键盘
  183. FocusScope.of(context).requestFocus(blankNode);
  184. },
  185. child: Consumer<UserProvider>(builder: (_, provider, __) {
  186. return ListView(
  187. padding: EdgeInsets.all(0.0),
  188. children: <Widget>[
  189. ClickItem(
  190. title: "头像",
  191. hasPicRight: "${provider.user?.avatarUrl ?? ""}",
  192. onTap: () {
  193. selectPicker();
  194. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  195. },
  196. ),
  197. ClickItem(
  198. title: "昵称",
  199. content: "${provider.user?.nickName ?? ""}",
  200. onTap: () async {
  201. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  202. Navigator.push(context, MaterialPageRoute(
  203. builder: (context) {
  204. return EditTextPage(
  205. title: "编辑昵称",
  206. value: provider.user?.nickName ?? "",
  207. mType: 0,
  208. saveName: (val) {
  209. if (val != null) {
  210. _modifyName(val);
  211. // _modifyName(val);
  212. }
  213. },
  214. );
  215. },
  216. ));
  217. },
  218. ),
  219. ClickItem(
  220. title: "名称",
  221. content: "${provider.user?.userName ?? ""}",
  222. onTap: () {
  223. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  224. Navigator.of(context).push(
  225. MaterialPageRoute(
  226. builder: (context) {
  227. return EditTextPage(
  228. title: "编辑名称",
  229. value: provider.user?.userName ?? "",
  230. mType: 0,
  231. saveName: (val) {
  232. if (val != null) {
  233. _modifyNames(val);
  234. }
  235. },
  236. );
  237. },
  238. ),
  239. );
  240. },
  241. ),
  242. ClickItem(
  243. title: "手机号",
  244. content: "${provider.user?.mobile ?? ""}",
  245. // onTap: () {
  246. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  247. // },
  248. ),
  249. ClickItem(
  250. title: "我的团队",
  251. content: "${provider.user?.companyName ?? ""}",
  252. onTap: () {
  253. if (FlutterStars.SpUtil.getString(Constant.companyId)
  254. .length ==
  255. 0) {
  256. showAlert(
  257. context,
  258. "提示",
  259. "尚未加入团队,是否立即加入?",
  260. "确定",
  261. () {
  262. NavigatorUtils.goBack(context);
  263. // goToPage(TeamRouter.teamListPage);
  264. NavigatorUtils.pushResult(
  265. context, TeamRouter.teamListPage, (res) {
  266. // countDoing();
  267. });
  268. },
  269. txt2: "取消",
  270. onPre2: () {
  271. NavigatorUtils.goBack(context);
  272. });
  273. } else {
  274. NavigatorUtils.push(
  275. context, TeamRouter.teamCardPage);
  276. }
  277. },
  278. ),
  279. ClickItem(
  280. title: "团队角色",
  281. content: "${provider.user?.roleName ?? ""}"),
  282. ClickItem(
  283. title: "操作证",
  284. content: Constant.certificateStatus[
  285. provider.user?.certificateStatus ?? 0],
  286. onTap: () {
  287. NavigatorUtils.push(
  288. context, AccountRouter.certificatePage);
  289. },
  290. ),
  291. ClickItem(
  292. title: "团队管理",
  293. content: "",
  294. onTap: () {
  295. NavigatorUtils.push(context, TeamRouter.teamListPage);
  296. },
  297. ),
  298. Container(
  299. margin: EdgeInsets.only(bottom: 8),
  300. child: ClickItem(
  301. title: "团队名片",
  302. content: "",
  303. onTap: () {
  304. NavigatorUtils.push(
  305. context, "${TeamRouter.teamUserPage}");
  306. },
  307. ),
  308. ),
  309. ClickItem(
  310. title: "企业",
  311. content: "${provider.user?.companyName ?? ""}",
  312. onTap: () {
  313. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  314. },
  315. ),
  316. Row(
  317. crossAxisAlignment: CrossAxisAlignment.start,
  318. mainAxisAlignment: MainAxisAlignment.start,
  319. children: <Widget>[
  320. Container(
  321. padding: EdgeInsets.only(
  322. left: ScreenUtil().setWidth(15),
  323. top: ScreenUtil().setWidth(10),
  324. bottom: ScreenUtil().setWidth(5)),
  325. child: Text(
  326. "简介",
  327. style: TextStyle(
  328. // fontSize:ScreenUtil().setSp(14),
  329. ),
  330. textAlign: TextAlign.left,
  331. ),
  332. ),
  333. ],
  334. ),
  335. Container(
  336. height: 120,
  337. // color:Colors.red,
  338. decoration: BoxDecoration(
  339. border: Border(
  340. bottom: BorderSide(width: 0.5, color: Colours.line),
  341. ),
  342. ),
  343. padding: EdgeInsets.only(
  344. left: ScreenUtil().setWidth(15),
  345. right: ScreenUtil().setWidth(15),
  346. bottom: ScreenUtil().setWidth(20)),
  347. child: TextFormField(
  348. // autofocus: true,
  349. // maxLength: 500,
  350. cursorColor: Color(0xffcccccc),
  351. controller: _unameController,
  352. maxLines: 5,
  353. decoration: InputDecoration(
  354. contentPadding: EdgeInsets.all(0),
  355. hintText: '请输入您的简介',
  356. hintStyle: TextStyle(color: Color(0xffcccccc)),
  357. focusedBorder: InputBorder.none,
  358. border: InputBorder.none,
  359. // filled: true, // 背景色
  360. // fillColor: Colors.cyan.withAlpha(35),
  361. // icon: Icon(Icons.person)
  362. ),
  363. // 校验
  364. validator: (val) {
  365. return val.trim().length > 0 ? null : "不能为空";
  366. }),
  367. ),
  368. Container(
  369. margin: EdgeInsets.only(
  370. top: ScreenUtil().setWidth(15),
  371. bottom: ScreenUtil().setWidth(15),
  372. left: ScreenUtil().setWidth(25),
  373. right: ScreenUtil().setWidth(25),
  374. ),
  375. height: ScreenUtil().setWidth(44),
  376. decoration: BoxDecoration(
  377. color: Colours.blue_app_main,
  378. borderRadius:
  379. BorderRadius.circular(ScreenUtil().setWidth(22)),
  380. // gradient: const LinearGradient(
  381. // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  382. // ),
  383. ),
  384. child: FlatButton(
  385. // padding: EdgeInsets.all(15.0),
  386. child: Text("保存"),
  387. textColor: Colors.white,
  388. onPressed: () {
  389. print(_unameController.text == "");
  390. if (_unameController.text == "") {
  391. toasts('请输入简介信息');
  392. } else {
  393. _submit(_unameController.text);
  394. }
  395. // if ((_formKey.currentState as FormState).validate()) {
  396. // submit();
  397. // }
  398. },
  399. ),
  400. ),
  401. ]);
  402. }),
  403. ),
  404. ),
  405. ));
  406. }
  407. @override
  408. bool get wantKeepAlive => true;
  409. }