personal_page.dart 15 KB

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