You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
9.4 KiB

4 years ago
import 'dart:convert';
4 years ago
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/foundation.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/userinfo.dart';
import 'package:huixiang/utils/flutter_utils.dart';
4 years ago
import 'package:huixiang/view_widget/cupertino_date_picker.dart';
import 'package:huixiang/view_widget/language_set_page.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:intl/intl.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class UserInfoPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _UserInfoPage();
}
}
class _UserInfoPage extends State<UserInfoPage> {
4 years ago
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
user = Userinfo.fromJson(jsonDecode(value.getString('user'))),
mobile = value.getString('mobile'),
nickName = value.getString('nick'),
birth = user.birth,
age = AppUtils.getAgeByString(birth),
refresh()
});
}
String birth;
String age;
String mobile = "";
String locale = "zh";
String nickName = "";
Userinfo user;
refresh() async {
setState(() {});
}
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).zhanghaoxinxi,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
centerTitle: false,
backgroundColor: Color(0xFFF7F7F7),
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
leadingWidth: 56,
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
Container(
margin: EdgeInsets.only(left: 16),
child: Text(
S.of(context).gerenxinxi,
style: TextStyle(
4 years ago
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
fontSize: 16,
),
4 years ago
),
),
userInfo(),
SizedBox(
height: 24,
),
Container(
margin: EdgeInsets.only(left: 16),
child: Text(
S.of(context).shezhi,
style: TextStyle(
4 years ago
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
fontSize: 16,
),
4 years ago
),
),
SizedBox(
height: 16,
),
GestureDetector(
onTap: () {
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (context) {
4 years ago
return LanguageSetPage(locale);
4 years ago
}).then((value) => {
setState(() {
if (value == "tw") {
S.load(Locale.fromSubtags(
languageCode: 'zh', countryCode: 'TW'));
4 years ago
locale = "tw";
4 years ago
} else {
S.load(Locale.fromSubtags(
languageCode: 'zh', countryCode: 'CN'));
4 years ago
locale = "zh";
4 years ago
}
4 years ago
setState(() {});
4 years ago
})
});
},
child: settingItem(
S.of(context).yuyan,
4 years ago
locale == "zh"
4 years ago
? S.of(context).zhongwenjianti
: S.of(context).fantizhongwen),
),
GestureDetector(
child:
settingItem(S.of(context).quanxian, S.of(context).weikaiqi),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: 54,
alignment: Alignment.center,
margin: EdgeInsets.only(bottom: 46, left: 16, right: 16),
color: Color(0xFF32A060),
child: RoundButton(
text: S.of(context).tuichudenglu,
backgroup: Color(0xFF32A060),
textColor: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
)
],
),
flex: 1,
)
],
),
),
);
}
Widget settingItem(left, right) {
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
]),
child: Row(
children: [
Expanded(
child: Text(
left,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xFF353535),
),
),
flex: 1,
),
Text(
right,
style: TextStyle(fontSize: 12, color: Color(0xFF727272)),
),
SizedBox(
width: 16,
),
Icon(
Icons.keyboard_arrow_right,
size: 20,
),
],
),
);
}
Widget userInfo() {
return Container(
margin: EdgeInsets.fromLTRB(16, 32, 16, 16),
padding: EdgeInsets.fromLTRB(20, 6, 20, 18),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
),
],
),
child: Column(
children: [
avatarItem(0, ""),
4 years ago
avatarItem(1, nickName),
4 years ago
InkWell(
onTap: showDateSelector,
child: avatarItem(
2,
4 years ago
(birth != null && birth != "")
? birth
: S.of(context).wanshanshengrixinxi_yhq),
4 years ago
),
4 years ago
avatarItem(3, mobile),
4 years ago
avatarItem(
4,
4 years ago
(age == null || age == "")
4 years ago
? S.of(context).wanshanshengrixinxi_nl
: S.of(context).sui(age)),
],
),
);
}
List<String> itemLefts = [
S.current.touxiang,
S.current.yonghuming,
S.current.wodeshengri,
S.current.shoujihao,
S.current.wodenianling,
];
showDateSelector() async {
4 years ago
DateTime dateTime = await showModalBottomSheet(
4 years ago
backgroundColor: Colors.transparent,
context: context,
4 years ago
builder: (_) {
4 years ago
return CupertinoDatePickerWidget();
});
if (dateTime != null) {
4 years ago
birth = DateFormat("yyyy.MM.dd").format(dateTime);
age = AppUtils.getAge(dateTime);
4 years ago
setState(() {});
}
}
Widget avatarItem(type, value) {
return Container(
margin: EdgeInsets.only(top: 14, bottom: 14),
child: Row(
children: [
Expanded(
child: Text(
itemLefts[type],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xFF353535),
),
),
flex: 1,
),
buildValue(type, value),
4 years ago
if (type == 3 || type == 0) valueEnd(),
4 years ago
],
),
);
}
Widget valueEnd() {
return Container(
child: Row(
children: [
SizedBox(
width: 8,
),
Icon(
Icons.keyboard_arrow_right,
size: 20,
)
],
),
);
}
Widget buildValue(type, value) {
if (type == 0) {
return ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Image.network(
"https://t7.baidu.com/it/u=2869268957,1721811479&fm=193&f=GIF",
width: 42,
height: 42,
fit: BoxFit.cover,
),
);
} else if (type == 1) {
return Text(
value,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 14, color: Colors.black),
);
} else {
return Text(
value,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xFF727272)),
);
}
}
}