personal_page.dart 15 KB

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