| | |
| | | import 'dart:ui'; |
| | | import 'dart:io'; |
| | | import 'dart:ui'; |
| | | |
| | | import 'package:flutter/cupertino.dart'; |
| | | import 'package:flutter/material.dart'; |
| | | import 'package:flutter_module/utils/wx_util.dart'; |
| | | import 'package:image_picker/image_picker.dart'; |
| | | import 'package:package_info/package_info.dart'; |
| | | |
| | | import '../../api/http.dart'; |
| | | import '../../api/user_api.dart'; |
| | | import '../../model/user/user_info.dart'; |
| | | import '../../ui/widget/button.dart'; |
| | | import '../../ui/widget/video_item.dart'; |
| | | import '../../utils/image_util.dart'; |
| | | import '../../api/http.dart'; |
| | | import '../../ui/common/browser.dart'; |
| | | import '../../ui/widget/button.dart'; |
| | | import '../../ui/widget/dialog.dart'; |
| | | import '../../ui/widget/nav.dart'; |
| | | import '../../ui/widget/video_item.dart'; |
| | | import '../../utils/cache_util.dart'; |
| | | import '../../utils/config_util.dart'; |
| | | import '../../utils/event_bus_util.dart'; |
| | | import '../../utils/image_util.dart'; |
| | | import '../../utils/pageutils.dart'; |
| | | import '../../utils/push_util.dart'; |
| | | import '../../utils/setting_util.dart'; |
| | |
| | | import '../../utils/ui_constant.dart'; |
| | | import '../../utils/ui_utils.dart'; |
| | | import '../../utils/user_util.dart'; |
| | | import 'package:package_info/package_info.dart'; |
| | | import 'package:image_picker/image_picker.dart'; |
| | | import 'login.dart'; |
| | | |
| | | void main() { |
| | | runApp(MyApp()); |
| | |
| | | |
| | | String? editPortrait; |
| | | String? editNickName; |
| | | int? editSex; |
| | | DateTime? editBirthday; |
| | | String? editSign; |
| | | |
| | | @override |
| | | void initState() { |
| | | super.initState(); |
| | | UserUtil.getUserInfo().then((value) { |
| | | getUserInfo(); |
| | | } |
| | | |
| | | void getUserInfo() async { |
| | | await UserUtil.updateUserInfo(context); |
| | | UserInfo? temp = await UserUtil.getUserInfo(); |
| | | setState(() { |
| | | _user = value; |
| | | }); |
| | | _user = temp; |
| | | }); |
| | | } |
| | | |
| | |
| | | @override |
| | | Widget build(BuildContext context) { |
| | | return Scaffold( |
| | | backgroundColor: const Color(0xFFDADADA), |
| | | backgroundColor: const Color(0xFFF3F3F3), |
| | | body: _user == null |
| | | ? Container() |
| | | : Column( |
| | |
| | | //保存 |
| | | UserApiUtil.updateUserInfo(context, |
| | | nickName: editNickName, |
| | | sex: editSex, |
| | | birthDay: editBirthday == null |
| | | ? null |
| | | : "${editBirthday!.year}/${editBirthday!.month}/${editBirthday!.day}", |
| | | sign: editSign, |
| | | portraitPath: editPortrait) |
| | | .then((value) { |
| | | if (value == null) { |
| | | return; |
| | | } |
| | | |
| | | if (value["IsPost"] == "true") { |
| | | if (value["code"] == 0) { |
| | | ToastUtil.toast("修改成功", context); |
| | | popPage(context); |
| | | } else { |
| | | ToastUtil.toast(value["Error"], context); |
| | | ToastUtil.toast(value["msg"], context); |
| | | } |
| | | }); |
| | | } |
| | |
| | | child: Column(children: [ |
| | | Container( |
| | | height: 10, |
| | | color: const Color(0xFFDADADA), |
| | | ), |
| | | Row( |
| | | mainAxisSize: MainAxisSize.min, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Container( |
| | | width: 15, |
| | | height: 50 * 4 + |
| | | (DimenUtil.getOnePixel(context)) * 3 * 2, |
| | | alignment: Alignment.center, |
| | | color: Colors.white, |
| | | ), |
| | | Expanded( |
| | | child: Column( |
| | | mainAxisSize: MainAxisSize.min, |
| | | children: [ |
| | | getPortraitItemView(onClick: () { |
| | | //选择头像 |
| | | selectImg(); |
| | |
| | | title: "昵称", |
| | | content: editNickName ?? _user!.nickname!, |
| | | onClick: () { |
| | | showEditNickName(editNickName ?? _user!.nickname!); |
| | | showEditNickName( |
| | | editNickName ?? _user!.nickname!); |
| | | }), |
| | | getCommonItemView( |
| | | title: "性别", |
| | | content: |
| | | _getSexDesc((editSex ?? int.parse(_user!.sex!))), |
| | | onClick: () { |
| | | showEditSex(editSex ?? int.parse(_user!.sex!)); |
| | | }), |
| | | getCommonItemView( |
| | | title: "生日", |
| | | content: _getBirthDay(), |
| | | onClick: () { |
| | | showEditBirthDay((editBirthday ?? |
| | | ((_user!.birthday == null || |
| | | _user!.birthday!.isEmpty) |
| | | ? null |
| | | : parseDate(_user!.birthday!)))); |
| | | }), |
| | | getCommonItemView( |
| | | title: "邮箱", |
| | | content: _user!.email!, |
| | | onClick: () {}, |
| | | canIn: false), |
| | | getCommonItemView( |
| | | title: "ID", |
| | | content: _user!.id!, |
| | | onClick: () {}, |
| | | canIn: false), |
| | | canIn: false) |
| | | ])) |
| | | ]), |
| | | Container( |
| | | height: 10, |
| | | color: const Color(0xFFDADADA), |
| | | height: 14, |
| | | ), |
| | | getSignItemView(onClick: () { |
| | | showEditSign(editSign ?? _user!.sign); |
| | | }), |
| | | Row( |
| | | mainAxisSize: MainAxisSize.min, |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | children: [ |
| | | Container( |
| | | width: 15, |
| | | height: 50 * 2 + |
| | | (DimenUtil.getOnePixel(context)) * 1 * 2, |
| | | alignment: Alignment.center, |
| | | color: Colors.white, |
| | | ), |
| | | Expanded( |
| | | child: Column( |
| | | mainAxisSize: MainAxisSize.min, |
| | | children: [ |
| | | getCommonItemView( |
| | | title: "手机号", |
| | | content: |
| | | StringUtil.isNullOrEmpty(_user!.phone) |
| | | ? "未添加" |
| | | : _user!.phone!, |
| | | onClick: () { |
| | | if (StringUtil.isNullOrEmpty( |
| | | _user!.phone)) { |
| | | //手机号绑定 |
| | | NavigatorUtil.navigateToNextPage( |
| | | context, |
| | | LoginPage( |
| | | title: "", |
| | | bindPhone: true, |
| | | ), (data) { |
| | | getUserInfo(); |
| | | }); |
| | | } |
| | | }, |
| | | canIn: |
| | | StringUtil.isNullOrEmpty(_user!.phone)), |
| | | getCommonItemView( |
| | | title: "微信授权", |
| | | content: StringUtil.isNullOrEmpty( |
| | | _user!.wxNickName) |
| | | ? "去授权" |
| | | : _user!.wxNickName!, |
| | | onClick: () { |
| | | if (!StringUtil.isNullOrEmpty( |
| | | _user!.wxNickName)) { |
| | | return; |
| | | } |
| | | WXAuthUtil.startAuth(context); |
| | | }, |
| | | canIn: StringUtil.isNullOrEmpty( |
| | | _user!.wxNickName)) |
| | | ])) |
| | | ]), |
| | | ]))), |
| | | ], |
| | | )); |
| | | } |
| | | |
| | | bool canSave() { |
| | | return editNickName != null || |
| | | editSex != null || |
| | | editBirthday != null || |
| | | editSign != null || |
| | | editPortrait != null; |
| | | } |
| | | |
| | | String _getSexDesc(int? sex) { |
| | | switch (sex) { |
| | | case 1: |
| | | return "男"; |
| | | case 2: |
| | | return "女"; |
| | | } |
| | | return "未知"; |
| | | } |
| | | |
| | | String _getBirthDay() { |
| | | DateTime? date = (editBirthday ?? |
| | | ((_user!.birthday == null || _user!.birthday!.isEmpty) |
| | | ? null |
| | | : parseDate(_user!.birthday!))); |
| | | if (date == null) { |
| | | return "请选择出生日期"; |
| | | } |
| | | |
| | | return "${date.year}/${date.month}/${date.day}"; |
| | | return editNickName != null || editPortrait != null; |
| | | } |
| | | |
| | | DateTime parseDate(String date) { |
| | |
| | | required GestureTapCallback onClick, |
| | | bool canIn = true}) { |
| | | return Container( |
| | | height: 53, |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 0, 1), |
| | | height: 50, |
| | | margin: EdgeInsets.fromLTRB(0, 0, 0, DimenUtil.getOnePixel(context) * 2), |
| | | color: Colors.white, |
| | | child: InkWell( |
| | | onTap: () { |
| | | if (!canIn) { |
| | | return; |
| | | } |
| | | onClick(); |
| | | }, |
| | | child: Container( |
| | | padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), |
| | | padding: const EdgeInsets.fromLTRB(0, 0, 20, 0), |
| | | child: Flex( |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | direction: Axis.horizontal, |
| | |
| | | const TextStyle(fontSize: 16, color: Color(0xFF333333)), |
| | | ), |
| | | Expanded( |
| | | child: Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.end, |
| | | child: Wrap( |
| | | alignment: WrapAlignment.end, |
| | | crossAxisAlignment: WrapCrossAlignment.center, |
| | | children: [ |
| | | Container( |
| | | child: Text(content, |
| | | style: const TextStyle( |
| | | fontSize: 14, color: Color(0xFF959595))), |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 13.5, 0), |
| | | fontSize: 14, color: Color(0xFF888888))), |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 0, 0), |
| | | ), |
| | | canIn |
| | | ? const SizedBox( |
| | | width: 10.5, |
| | | ) |
| | | : const SizedBox( |
| | | width: 0, |
| | | ), |
| | | canIn |
| | | ? Image.asset( |
| | | "assets/imgs/icon_person_info_input.png", |
| | | height: 13.5, |
| | | ) |
| | | : Container() |
| | | : Container( |
| | | width: 0, |
| | | ) |
| | | ], |
| | | )) |
| | | ], |
| | |
| | | |
| | | Widget getPortraitItemView({required GestureTapCallback onClick}) { |
| | | return Container( |
| | | height: 75, |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 0, 1), |
| | | height: 50, |
| | | margin: EdgeInsets.fromLTRB(0, 0, 0, DimenUtil.getOnePixel(context) * 2), |
| | | color: Colors.white, |
| | | child: InkWell( |
| | | onTap: () { |
| | | onClick(); |
| | | }, |
| | | child: Container( |
| | | padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), |
| | | padding: const EdgeInsets.fromLTRB(0, 0, 20, 0), |
| | | child: Flex( |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | direction: Axis.horizontal, |
| | |
| | | borderRadius: BorderRadius.circular(60), |
| | | child: editPortrait == null |
| | | ? CommonImage( |
| | | _user!.portrait!, |
| | | height: 57, |
| | | width: 57, |
| | | _user!.portrait == null |
| | | ? 'assets/imgs/ic_portrait_default.png' |
| | | : _user!.portrait!, |
| | | height: 33, |
| | | width: 33, |
| | | ) |
| | | : Image.file( |
| | | File(editPortrait!), |
| | | fit: BoxFit.cover, |
| | | height: 57, |
| | | width: 57, |
| | | height: 33, |
| | | width: 33, |
| | | )), |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 13.5, 0), |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 10.5, 0), |
| | | ), |
| | | Image.asset( |
| | | "assets/imgs/icon_person_info_input.png", |
| | |
| | | )), |
| | | ), |
| | | ); |
| | | } |
| | | |
| | | Widget getSignItemView({required GestureTapCallback onClick}) { |
| | | return Container( |
| | | height: 200, |
| | | margin: const EdgeInsets.fromLTRB(0, 0, 0, 1), |
| | | color: Colors.white, |
| | | child: InkWell( |
| | | onTap: () { |
| | | onClick(); |
| | | }, |
| | | child: Container( |
| | | padding: const EdgeInsets.fromLTRB(20, 0, 20, 0), |
| | | child: |
| | | Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ |
| | | Container( |
| | | height: 18, |
| | | ), |
| | | Flex( |
| | | crossAxisAlignment: CrossAxisAlignment.center, |
| | | direction: Axis.horizontal, |
| | | children: [ |
| | | const Text( |
| | | "个性签名", |
| | | style: TextStyle(fontSize: 16, color: Color(0xFF333333)), |
| | | ), |
| | | Expanded( |
| | | child: Flex( |
| | | direction: Axis.horizontal, |
| | | mainAxisAlignment: MainAxisAlignment.end, |
| | | children: [ |
| | | Image.asset( |
| | | "assets/imgs/icon_person_info_input.png", |
| | | height: 13.5, |
| | | ) |
| | | ], |
| | | )) |
| | | ], |
| | | ), |
| | | Container( |
| | | height: 21, |
| | | ), |
| | | Text( |
| | | _getSign(), |
| | | textAlign: TextAlign.start, |
| | | style: const TextStyle(color: Color(0xFFBEBEBE), fontSize: 15), |
| | | ) |
| | | ]), |
| | | ), |
| | | )); |
| | | } |
| | | |
| | | _getSign() { |
| | | return editSign ?? |
| | | ((_user!.sign == null || _user!.sign!.isEmpty) |
| | | ? "这个人很懒,什么也没有留下" |
| | | : _user!.sign!); |
| | | } |
| | | |
| | | showAlertDilaog(String title, Widget content, VoidCallback sure, |
| | |
| | | TextButton( |
| | | child: Text('取消'), |
| | | onPressed: () { |
| | | Navigator.of(context).pop(); |
| | | popPage(context); |
| | | }, |
| | | ), |
| | | TextButton( |
| | |
| | | if (controller.text.isEmpty) { |
| | | return; |
| | | } |
| | | Navigator.of(context).pop(); |
| | | popPage(context); |
| | | setState(() { |
| | | editNickName = controller.text; |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | void showEditSex(int sex) { |
| | | int? tempSex; |
| | | setState(() { |
| | | tempSex = sex; |
| | | }); |
| | | DialogUtil.showDialogBottom( |
| | | context, |
| | | Container( |
| | | margin: const EdgeInsets.all(10), |
| | | alignment: Alignment.bottomCenter, |
| | | child: Stack(alignment: Alignment.bottomCenter, children: [ |
| | | Container( |
| | | margin: const EdgeInsets.only(bottom: 50), |
| | | decoration: BoxDecoration( |
| | | color: Colors.white, |
| | | borderRadius: BorderRadius.circular(10)), |
| | | child: Container( |
| | | height: 100, |
| | | alignment: Alignment.center, |
| | | child: Column( |
| | | children: [ |
| | | InkWell( |
| | | onTap: () { |
| | | setState(() { |
| | | editSex = 1; |
| | | }); |
| | | Navigator.of(context).pop(); |
| | | }, |
| | | child: Container( |
| | | height: 50, |
| | | alignment: Alignment.center, |
| | | child: const Text( |
| | | "男", |
| | | style: TextStyle( |
| | | fontSize: 18, |
| | | color: ColorConstant.theme), |
| | | ))), |
| | | InkWell( |
| | | onTap: () { |
| | | setState(() { |
| | | editSex = 2; |
| | | }); |
| | | Navigator.of(context).pop(); |
| | | }, |
| | | child: Container( |
| | | height: 50, |
| | | alignment: Alignment.center, |
| | | child: const Text( |
| | | "女", |
| | | style: TextStyle( |
| | | fontSize: 18, |
| | | color: ColorConstant.theme), |
| | | ))), |
| | | ], |
| | | ))), |
| | | MyFillButton( |
| | | "取消", |
| | | 20, |
| | | height: 40, |
| | | color: Colors.grey, |
| | | fontSize: 14, |
| | | onClick: () { |
| | | popPage(context); |
| | | }, |
| | | ) |
| | | ]))); |
| | | } |
| | | |
| | | //编辑生日 |
| | | void showEditBirthDay(DateTime? dateTime) async { |
| | | dateTime ??= DateTime.now(); |
| | | Locale myLocale = Localizations.localeOf(context); |
| | | DateTime? date = await showDatePicker( |
| | | context: context, |
| | | initialDate: dateTime, |
| | | firstDate: DateTime(1900), |
| | | lastDate: DateTime(DateTime.now().year + 1), |
| | | locale: myLocale); |
| | | if (date != null) { |
| | | setState(() { |
| | | editBirthday = date; |
| | | }); |
| | | } |
| | | } |
| | | |
| | | void showEditSign(String? sign) { |
| | | sign ??= ""; |
| | | TextEditingController controller = TextEditingController(); |
| | | controller.text = sign; |
| | | showAlertDilaog( |
| | | "编辑签名", |
| | | TextField( |
| | | controller: controller, |
| | | maxLines: 5, |
| | | maxLength: 200, |
| | | decoration: const InputDecoration( |
| | | focusedBorder: InputBorder.none, |
| | | border: InputBorder.none, |
| | | counterStyle: TextStyle(color: Color(0xFF666666)), |
| | | hintText: "请输入签名内容", |
| | | hintStyle: TextStyle(fontSize: 15, color: Color(0xFF999999))), |
| | | ), () { |
| | | if (controller.text.isEmpty) { |
| | | return; |
| | | } |
| | | |
| | | Navigator.of(context).pop(); |
| | | setState(() { |
| | | editSign = controller.text; |
| | | }); |
| | | }); |
| | | } |