personal_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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);
  62. provider.setUser(user);
  63. FlutterStars.SpUtil.putString('username', user.userName);
  64. FlutterStars.SpUtil.putString('avatarUrl', user.avatarUrl);
  65. }
  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. void _getImage(int key) async {
  89. try {
  90. var _imageFile = await ImagePicker.pickImage(
  91. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  92. maxWidth: 800,
  93. imageQuality: 95);
  94. if (_imageFile != null) {
  95. updateAvatar(_imageFile);
  96. setState(() {});
  97. }
  98. } catch (e) {
  99. toasts("没有权限,无法打开相册!");
  100. }
  101. }
  102. void updateAvatar(File imageFile) {
  103. List<File> list = [imageFile];
  104. ApiService(context: context).uploadMore(list, onSuccess: (imgs) {
  105. ApiService(context: context).modifyAvatar(imgs[0], onSuccess: (res) {
  106. if (res != null) {
  107. getUserInfo();
  108. }
  109. }, onError: (code, msg) {
  110. toasts(msg);
  111. });
  112. });
  113. }
  114. // 修改用户昵称
  115. void _modifyName(value) {
  116. ApiService(context: context).userUpdate(value, onSuccess: (res) {
  117. // if (res != null) {
  118. getUserInfo();
  119. // }
  120. }, onError: (code, msg) {
  121. toasts(msg);
  122. });
  123. }
  124. // 修改用户名
  125. void _modifyNames(value) {
  126. ApiService(context: context).userUpdates(value, onSuccess: (res) {
  127. // if (res != null) {
  128. getUserInfo();
  129. // }
  130. }, onError: (code, msg) {
  131. toasts(msg);
  132. });
  133. }
  134. // 修改简介
  135. void _submit(value) {
  136. ApiService(context: context).userUpdateJj(value, onSuccess: (res) {
  137. // if (res != null) {
  138. toasts("保存成功");
  139. getUserInfo();
  140. // }
  141. }, onError: (code, msg) {
  142. toasts(msg);
  143. });
  144. }
  145. @override
  146. void dispose() {
  147. // provider.dispose();
  148. super.dispose();
  149. }
  150. @override
  151. Widget build(BuildContext context) {
  152. double width = MediaQuery.of(context).size.width;
  153. double height = MediaQuery.of(context).size.height;
  154. return ChangeNotifierProvider<UserProvider>(
  155. create: (_) => provider,
  156. child: Container(
  157. child: Scaffold(
  158. resizeToAvoidBottomPadding: false,
  159. appBar: MyAppBar(
  160. centerTitle: "个人资料",
  161. actions: <Widget>[
  162. Utils.getAuthByRouter('people_nearby', false) && FlutterStars.SpUtil.getInt("expertFlag") != 1
  163. ? FlatButton(
  164. child: Text("申请为专家"),
  165. textColor: Colours.dark_text,
  166. highlightColor: Colors.transparent,
  167. onPressed: () {
  168. NavigatorUtils.push(context, WodeRouter.masterBecome);
  169. },
  170. )
  171. : Container()
  172. ],
  173. ),
  174. body: GestureDetector(
  175. onTap: () {
  176. // 点击空白页面关闭键盘
  177. FocusScope.of(context).requestFocus(blankNode);
  178. },
  179. child: Consumer<UserProvider>(builder: (_, provider, __) {
  180. return ListView(
  181. padding: EdgeInsets.all(0.0),
  182. children: <Widget>[
  183. ClickItem(
  184. title: "头像",
  185. hasPicRight: "${provider.user?.avatarUrl ?? ""}",
  186. onTap: () {
  187. selectPicker();
  188. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  189. },
  190. ),
  191. ClickItem(
  192. title: "昵称",
  193. content: "${provider.user?.nickName ?? ""}",
  194. onTap: () {
  195. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  196. Navigator.of(context).push(
  197. MaterialPageRoute(
  198. builder: (context) {
  199. return EditTextPage(
  200. title: "编辑昵称",
  201. value: provider.user?.nickName ?? "",
  202. mType: 0,
  203. );
  204. },
  205. ),
  206. ).then(
  207. (value) {
  208. if (value != null) {
  209. _modifyName(value);
  210. }
  211. },
  212. );
  213. },
  214. ),
  215. ClickItem(
  216. title: "名称",
  217. content: "${provider.user?.userName ?? ""}",
  218. onTap: () {
  219. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  220. Navigator.of(context).push(
  221. MaterialPageRoute(
  222. builder: (context) {
  223. return EditTextPage(
  224. title: "编辑名称",
  225. value: provider.user?.userName ?? "",
  226. mType: 0,
  227. );
  228. },
  229. ),
  230. ).then(
  231. (value) {
  232. if (value != null) {
  233. _modifyNames(value);
  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. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  251. },
  252. ),
  253. ClickItem(
  254. title: "团队角色",
  255. content: "${provider.user?.roleName ?? ""}"),
  256. ClickItem(
  257. title: "操作证",
  258. content: Constant.certificateStatus[
  259. provider.user?.certificateStatus ?? 0],
  260. onTap: () {
  261. NavigatorUtils.push(
  262. context, AccountRouter.certificatePage);
  263. },
  264. ),
  265. ClickItem(
  266. title: "团队管理",
  267. content: "",
  268. onTap: () {
  269. NavigatorUtils.push(context, TeamRouter.teamListPage);
  270. },
  271. ),
  272. Container(
  273. margin: EdgeInsets.only(bottom: 8),
  274. child: ClickItem(
  275. title: "团队名片",
  276. content: "",
  277. onTap: () {
  278. NavigatorUtils.push(
  279. context, "${TeamRouter.teamUserPage}");
  280. },
  281. ),
  282. ),
  283. ClickItem(
  284. title: "企业",
  285. content: "${provider.user?.companyName ?? ""}",
  286. onTap: () {
  287. // NavigatorUtils.push(context, BbsRouter.videoDetail);
  288. },
  289. ),
  290. Row(
  291. crossAxisAlignment: CrossAxisAlignment.start,
  292. mainAxisAlignment: MainAxisAlignment.start,
  293. children: <Widget>[
  294. Container(
  295. padding: EdgeInsets.only(
  296. left: ScreenUtil().setWidth(15),
  297. top: ScreenUtil().setWidth(10),
  298. bottom: ScreenUtil().setWidth(5)),
  299. child: Text(
  300. "简介",
  301. style: TextStyle(
  302. // fontSize:ScreenUtil().setSp(14),
  303. ),
  304. textAlign: TextAlign.left,
  305. ),
  306. ),
  307. ],
  308. ),
  309. Container(
  310. height: 120,
  311. // color:Colors.red,
  312. decoration: BoxDecoration(
  313. border: Border(
  314. bottom: BorderSide(width: 0.5, color: Colours.line),
  315. ),
  316. ),
  317. padding: EdgeInsets.only(
  318. left: ScreenUtil().setWidth(15),
  319. right: ScreenUtil().setWidth(15),
  320. bottom: ScreenUtil().setWidth(20)),
  321. child: TextFormField(
  322. // autofocus: true,
  323. // maxLength: 500,
  324. cursorColor: Color(0xffcccccc),
  325. controller: _unameController,
  326. maxLines: 5,
  327. decoration: InputDecoration(
  328. contentPadding: EdgeInsets.all(0),
  329. hintText: '请输入您的简介',
  330. hintStyle: TextStyle(color: Color(0xffcccccc)),
  331. focusedBorder: InputBorder.none,
  332. border: InputBorder.none,
  333. // filled: true, // 背景色
  334. // fillColor: Colors.cyan.withAlpha(35),
  335. // icon: Icon(Icons.person)
  336. ),
  337. // 校验
  338. validator: (val) {
  339. return val.trim().length > 0 ? null : "不能为空";
  340. }),
  341. ),
  342. Container(
  343. margin: EdgeInsets.only(
  344. top: ScreenUtil().setWidth(15),
  345. bottom: ScreenUtil().setWidth(15),
  346. left: ScreenUtil().setWidth(25),
  347. right: ScreenUtil().setWidth(25),
  348. ),
  349. height: ScreenUtil().setWidth(44),
  350. decoration: BoxDecoration(
  351. borderRadius:
  352. BorderRadius.circular(ScreenUtil().setWidth(22)),
  353. gradient: const LinearGradient(
  354. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  355. ),
  356. ),
  357. child: FlatButton(
  358. // padding: EdgeInsets.all(15.0),
  359. child: Text("保存"),
  360. textColor: Colors.white,
  361. onPressed: () {
  362. print(_unameController.text == "");
  363. if (_unameController.text == "") {
  364. toasts('请输入您上传视频的简介');
  365. } else {
  366. _submit(_unameController.text);
  367. }
  368. // if ((_formKey.currentState as FormState).validate()) {
  369. // submit();
  370. // }
  371. },
  372. ),
  373. ),
  374. ]);
  375. }),
  376. ),
  377. ),
  378. ));
  379. }
  380. @override
  381. bool get wantKeepAlive => true;
  382. }