123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- import 'package:farmer_client/widgets/DefaultButton.dart';
- import 'package:farmer_client/widgets/layout/BasicPage.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:get/get.dart';
-
- import '../../models/app.dart';
- import '../../models/entities/person.dart';
- import '../../services/user.dart';
-
- class UserInfo extends BasicPage {
- late String name;
- late String phone;
- late TextEditingController _cName;
- late TextEditingController _cPhone;
- AppController userInfo = AppController.t;
-
- @override
- void beforeShow() {
- super.beforeShow();
- name = userInfo.user().nickName != null
- ? userInfo.user().nickName.toString()
- : '';
- phone = userInfo.user().phone.toString();
- _cName = TextEditingController(text: name);
- _cPhone = TextEditingController(text: phone);
- }
-
- bool disableLogin = false;
- RegExp exp = RegExp(r'^1[3456789]\d{9}$');
-
- Map<String, dynamic> data = {};
-
- void handleOk() {
- if (name == '' && phone == '') {
- Fluttertoast.showToast(msg: '请输入正确的信息');
- return;
- } else if (phone == '' && !exp.hasMatch(phone)) {
- Fluttertoast.showToast(msg: '请输入正确的手机号');
- return;
- } else {
- data = {
- ...userInfo.user().toJson(),
- 'nickName': name,
- 'phone': phone
- };
- updateInfo(userInfo.user().personId.toString(), data).then((value) {
- // 尝试获取一次人员信息
- EasyLoading.show(status: '数据加载中...');
-
- getCurrent().then((person) {
- EasyLoading.dismiss();
- userInfo.user(Person.fromJson(person));
- Fluttertoast.showToast(msg: '保存成功');
-
- Get.offAllNamed('/main');
- }).catchError((e) {
- EasyLoading.dismiss();
- EasyLoading.showError('出错啦!');
- print(e);
- });
- });
- }
- }
-
- @override
- Widget builder(BuildContext context) {
- naviTitle = '个人信息';
- return Container(
- height: 700.h,
- color: const Color(0xFFffffff),
- padding: EdgeInsets.all(15.w),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: 345.w,
- margin: EdgeInsets.fromLTRB(0, 0, 0, 40.h),
- padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 0),
- decoration: BoxDecoration(
- color: const Color(0xFFFFFFFF),
- boxShadow: [
- BoxShadow(
- color: const Color(0x1F000000),
- offset: Offset(0, 1.w),
- blurRadius: 0,
- ),
- ],
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- width: 63.w,
- height: 63.w,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- image: userInfo.user().avatar != null
- ? DecorationImage(
- image: NetworkImage(
- userInfo.user().avatar.toString()),
- fit: BoxFit.cover,
- )
- : DecorationImage(
- image: AssetImage('images/userMoren.png')),
- ),
- ),
- GestureDetector(
- onTap: () {
- Get.toNamed("/resetPassword");
- },
- child: Text("修改密码", style: TextStyle(
- color: const Color(0xFF333333),
- fontSize: 17.sp,
- fontWeight: FontWeight.bold,
- letterSpacing: 2),),
- )
- ]),
- ),
- Text(
- '姓名:',
- style: TextStyle(
- color: const Color(0xFF333333),
- fontSize: 17.sp,
- letterSpacing: 2,
- fontWeight: FontWeight.bold),
- ),
- Container(
- width: 345.w,
- margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
- padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
- decoration: BoxDecoration(
- color: const Color(0xFFFFFFFF),
- boxShadow: [
- BoxShadow(
- color: const Color(0x1F000000),
- offset: Offset(0, 1.w),
- blurRadius: 0,
- ),
- ],
- ),
- child: Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- SizedBox(
- width: 327.w,
- child: TextField(
- controller: _cName,
- style: TextStyle(
- color: const Color(0xFF333333),
- fontSize: 17.sp,
- letterSpacing: 2,
- fontWeight: FontWeight.bold),
- decoration: const InputDecoration(
- isCollapsed: true,
- hintText: '请输入您的姓名',
- border: InputBorder.none,
- counterText: '', //去掉计数
- floatingLabelBehavior:
- FloatingLabelBehavior.never,
- ),
- onChanged: (e) {
- name = e;
- print(name);
- },
- ),
- ),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- name = '';
- _cName.clear();
- },
- child: Image.asset(
- 'images/icons/cancel.png',
- width: 18.w,
- height: 18.w,
- ),
- ),
- ]),
- ],
- )),
- Text(
- '手机号:',
- style: TextStyle(
- color: const Color(0xFF333333),
- fontSize: 17.sp,
- letterSpacing: 2,
- fontWeight: FontWeight.bold),
- ),
- Container(
- width: 345.w,
- margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
- padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
- decoration: BoxDecoration(
- color: const Color(0xFFFFFFFF),
- boxShadow: [
- BoxShadow(
- color: const Color(0x1F000000),
- offset: Offset(0, 1.w),
- blurRadius: 0,
- ),
- ],
- ),
- child: Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- SizedBox(
- width: 327.w,
- child: TextField(
- keyboardType: TextInputType.number,
- controller: _cPhone,
- maxLength: 11,
- style: TextStyle(
- color: const Color(0xFF333333),
- fontSize: 17.sp,
- letterSpacing: 2,
- fontWeight: FontWeight.bold),
- decoration: const InputDecoration(
- isCollapsed: true,
- hintText: '请输入您的手机号',
- border: InputBorder.none,
- counterText: '', //去掉计数
- floatingLabelBehavior:
- FloatingLabelBehavior.never,
- ),
- onChanged: (e) {
- phone = e;
- },
- ),
- ),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- phone = '';
- _cPhone.clear();
- },
- child: Image.asset(
- 'images/icons/cancel.png',
- width: 18.w,
- height: 18.w,
- ),
- ),
- ]),
- ],
- )),
- const Spacer(),
- DefaultButton(
- color: const Color(0xffffffff),
- backColor: const Color(0xFFFF703B),
- width: 345.w,
- height: 49.h,
- text: '保存',
- onPressed: handleOk,
- margin: const EdgeInsets.all(0),
- fontSize: 20.sp,
- radius: 24.5.w,
- ),
- ],
- ),
- );
- }
- }
|