personal_page.dart 16 KB

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