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/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/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
import 'login.dart';
|
|
void main() {
|
runApp(MyApp());
|
}
|
|
class MyApp extends StatelessWidget {
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: '个人信息',
|
theme: ThemeData(primaryColor: const Color(0xFFF5F5F5)),
|
home: PersonInfoPage(title: ''),
|
);
|
}
|
}
|
|
class PersonInfoPage extends StatefulWidget {
|
PersonInfoPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_PersonInfoPageState createState() => _PersonInfoPageState();
|
}
|
|
class _PersonInfoPageState extends State<PersonInfoPage>
|
with SingleTickerProviderStateMixin {
|
UserInfo? _user;
|
|
String? editPortrait;
|
String? editNickName;
|
|
@override
|
void initState() {
|
super.initState();
|
getUserInfo();
|
}
|
|
void getUserInfo() async {
|
await UserUtil.updateUserInfo(context);
|
UserInfo? temp = await UserUtil.getUserInfo();
|
setState(() {
|
_user = temp;
|
});
|
}
|
|
void selectImg() async {
|
File? image = await ImageUtil.selectAndCropImage();
|
if (image == null) {
|
return;
|
}
|
//image.path
|
setState(() {
|
editPortrait = image.path;
|
});
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: const Color(0xFFF3F3F3),
|
body: _user == null
|
? Container()
|
: Column(
|
children: [
|
TopNavBar(
|
title: "个人信息",
|
rightText: canSave() ? "保存" : null,
|
rightClick: canSave()
|
? () {
|
//保存
|
UserApiUtil.updateUserInfo(context,
|
nickName: editNickName,
|
portraitPath: editPortrait)
|
.then((value) {
|
if (value == null) {
|
return;
|
}
|
|
if (value["code"] == 0) {
|
ToastUtil.toast("修改成功", context);
|
popPage(context);
|
} else {
|
ToastUtil.toast(value["msg"], context);
|
}
|
});
|
}
|
: null,
|
),
|
Expanded(
|
child: SingleChildScrollView(
|
child: Column(children: [
|
Container(
|
height: 10,
|
),
|
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();
|
}),
|
getCommonItemView(
|
title: "昵称",
|
content: editNickName ?? _user!.nickname!,
|
onClick: () {
|
showEditNickName(
|
editNickName ?? _user!.nickname!);
|
}),
|
getCommonItemView(
|
title: "ID",
|
content: _user!.id!,
|
onClick: () {},
|
canIn: false)
|
]))
|
]),
|
Container(
|
height: 14,
|
),
|
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 || editPortrait != null;
|
}
|
|
DateTime parseDate(String date) {
|
List<String> sts = date.split("/");
|
|
return DateTime(int.parse(sts[0]), int.parse(sts[1]), int.parse(sts[2]));
|
}
|
|
Widget getCommonItemView(
|
{required String title,
|
String content = "",
|
required GestureTapCallback onClick,
|
bool canIn = true}) {
|
return Container(
|
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(0, 0, 20, 0),
|
child: Flex(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
direction: Axis.horizontal,
|
children: [
|
Text(
|
title,
|
style:
|
const TextStyle(fontSize: 16, color: Color(0xFF333333)),
|
),
|
Expanded(
|
child: Wrap(
|
alignment: WrapAlignment.end,
|
crossAxisAlignment: WrapCrossAlignment.center,
|
children: [
|
Container(
|
child: Text(content,
|
style: const TextStyle(
|
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(
|
width: 0,
|
)
|
],
|
))
|
],
|
)),
|
),
|
);
|
}
|
|
Widget getPortraitItemView({required GestureTapCallback onClick}) {
|
return Container(
|
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(0, 0, 20, 0),
|
child: 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: [
|
Container(
|
child: ClipRRect(
|
borderRadius: BorderRadius.circular(60),
|
child: editPortrait == null
|
? CommonImage(
|
_user!.portrait == null
|
? 'assets/imgs/ic_portrait_default.png'
|
: _user!.portrait!,
|
height: 33,
|
width: 33,
|
)
|
: Image.file(
|
File(editPortrait!),
|
fit: BoxFit.cover,
|
height: 33,
|
width: 33,
|
)),
|
margin: const EdgeInsets.fromLTRB(0, 0, 10.5, 0),
|
),
|
Image.asset(
|
"assets/imgs/icon_person_info_input.png",
|
height: 13.5,
|
)
|
],
|
))
|
],
|
)),
|
),
|
);
|
}
|
|
showAlertDilaog(String title, Widget content, VoidCallback sure,
|
{VoidCallback? cancel}) {
|
showCupertinoDialog(
|
context: context,
|
builder: (context) {
|
return AlertDialog(
|
title: Text(title),
|
content: content,
|
actions: <Widget>[
|
TextButton(
|
child: Text('取消'),
|
onPressed: () {
|
popPage(context);
|
},
|
),
|
TextButton(
|
child: Text('确定'),
|
onPressed: () {
|
sure();
|
},
|
),
|
],
|
);
|
});
|
}
|
|
void showEditNickName(String nickName) {
|
TextEditingController controller = TextEditingController();
|
controller.text = nickName;
|
showAlertDilaog(
|
"修改昵称",
|
TextField(
|
controller: controller,
|
), () {
|
if (controller.text.isEmpty) {
|
return;
|
}
|
popPage(context);
|
setState(() {
|
editNickName = controller.text;
|
});
|
});
|
}
|
}
|