personal_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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('people_nearby', false) && FlutterStars.SpUtil.getInt("expertFlag") != 1
  165. ? FlatButton(
  166. child: Text("申请为专家"),
  167. textColor: Colours.dark_text,
  168. highlightColor: Colors.transparent,
  169. onPressed: () {
  170. NavigatorUtils.push(context, WodeRouter.masterBecome);
  171. },
  172. )
  173. : Container()
  174. ],
  175. ),
  176. body: GestureDetector(
  177. onTap: () {
  178. // 点击空白页面关闭键盘
  179. FocusScope.of(context).requestFocus(blankNode);
  180. },
  181. child: Consumer<UserProvider>(builder: (_, provider, __) {
  182. return ListView(
  183. padding: EdgeInsets.all(0.0),
  184. children: <Widget>[
  185. ClickItem(
  186. title: "头像",
  187. hasPicRight: "${provider.user?.avatarUrl ?? ""}",
  188. onTap: () {
  189. selectPicker();
  190. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  191. },
  192. ),
  193. ClickItem(
  194. title: "昵称",
  195. content: "${provider.user?.nickName ?? ""}",
  196. onTap: () {
  197. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  198. Navigator.of(context).push(
  199. MaterialPageRoute(
  200. builder: (context) {
  201. return EditTextPage(
  202. title: "编辑昵称",
  203. value: provider.user?.nickName ?? "",
  204. mType: 0,
  205. );
  206. },
  207. ),
  208. ).then(
  209. (value) {
  210. print(value);
  211. print(123333);
  212. if (value != null) {
  213. _modifyName(value);
  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. );
  232. },
  233. ),
  234. ).then(
  235. (value) {
  236. if (value != null) {
  237. _modifyNames(value);
  238. }
  239. },
  240. );
  241. },
  242. ),
  243. ClickItem(
  244. title: "手机号",
  245. content: "${provider.user?.mobile ?? ""}",
  246. onTap: () {
  247. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  248. },
  249. ),
  250. ClickItem(
  251. title: "我的团队",
  252. content: "${provider.user?.companyName ?? ""}",
  253. onTap: () {
  254. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  255. },
  256. ),
  257. ClickItem(
  258. title: "团队角色",
  259. content: "${provider.user?.roleName ?? ""}"),
  260. ClickItem(
  261. title: "操作证",
  262. content: Constant.certificateStatus[
  263. provider.user?.certificateStatus ?? 0],
  264. onTap: () {
  265. NavigatorUtils.push(
  266. context, AccountRouter.certificatePage);
  267. },
  268. ),
  269. ClickItem(
  270. title: "团队管理",
  271. content: "",
  272. onTap: () {
  273. NavigatorUtils.push(context, TeamRouter.teamListPage);
  274. },
  275. ),
  276. Container(
  277. margin: EdgeInsets.only(bottom: 8),
  278. child: ClickItem(
  279. title: "团队名片",
  280. content: "",
  281. onTap: () {
  282. NavigatorUtils.push(
  283. context, "${TeamRouter.teamUserPage}");
  284. },
  285. ),
  286. ),
  287. ClickItem(
  288. title: "企业",
  289. content: "${provider.user?.companyName ?? ""}",
  290. onTap: () {
  291. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  292. },
  293. ),
  294. Row(
  295. crossAxisAlignment: CrossAxisAlignment.start,
  296. mainAxisAlignment: MainAxisAlignment.start,
  297. children: <Widget>[
  298. Container(
  299. padding: EdgeInsets.only(
  300. left: ScreenUtil().setWidth(15),
  301. top: ScreenUtil().setWidth(10),
  302. bottom: ScreenUtil().setWidth(5)),
  303. child: Text(
  304. "简介",
  305. style: TextStyle(
  306. // fontSize:ScreenUtil().setSp(14),
  307. ),
  308. textAlign: TextAlign.left,
  309. ),
  310. ),
  311. ],
  312. ),
  313. Container(
  314. height: 120,
  315. // color:Colors.red,
  316. decoration: BoxDecoration(
  317. border: Border(
  318. bottom: BorderSide(width: 0.5, color: Colours.line),
  319. ),
  320. ),
  321. padding: EdgeInsets.only(
  322. left: ScreenUtil().setWidth(15),
  323. right: ScreenUtil().setWidth(15),
  324. bottom: ScreenUtil().setWidth(20)),
  325. child: TextFormField(
  326. // autofocus: true,
  327. // maxLength: 500,
  328. cursorColor: Color(0xffcccccc),
  329. controller: _unameController,
  330. maxLines: 5,
  331. decoration: InputDecoration(
  332. contentPadding: EdgeInsets.all(0),
  333. hintText: '请输入您的简介',
  334. hintStyle: TextStyle(color: Color(0xffcccccc)),
  335. focusedBorder: InputBorder.none,
  336. border: InputBorder.none,
  337. // filled: true, // 背景色
  338. // fillColor: Colors.cyan.withAlpha(35),
  339. // icon: Icon(Icons.person)
  340. ),
  341. // 校验
  342. validator: (val) {
  343. return val.trim().length > 0 ? null : "不能为空";
  344. }),
  345. ),
  346. Container(
  347. margin: EdgeInsets.only(
  348. top: ScreenUtil().setWidth(15),
  349. bottom: ScreenUtil().setWidth(15),
  350. left: ScreenUtil().setWidth(25),
  351. right: ScreenUtil().setWidth(25),
  352. ),
  353. height: ScreenUtil().setWidth(44),
  354. decoration: BoxDecoration(
  355. borderRadius:
  356. BorderRadius.circular(ScreenUtil().setWidth(22)),
  357. gradient: const LinearGradient(
  358. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  359. ),
  360. ),
  361. child: FlatButton(
  362. // padding: EdgeInsets.all(15.0),
  363. child: Text("保存"),
  364. textColor: Colors.white,
  365. onPressed: () {
  366. print(_unameController.text == "");
  367. if (_unameController.text == "") {
  368. toasts('请输入简介信息');
  369. } else {
  370. _submit(_unameController.text);
  371. }
  372. // if ((_formKey.currentState as FormState).validate()) {
  373. // submit();
  374. // }
  375. },
  376. ),
  377. ),
  378. ]);
  379. }),
  380. ),
  381. ),
  382. ));
  383. }
  384. @override
  385. bool get wantKeepAlive => true;
  386. }