|
|
@@ -1,6 +1,8 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
import "package:image_picker/image_picker.dart";
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
+import 'package:flutter_picker/flutter_picker.dart';
|
|
|
import 'package:dio/dio.dart';
|
|
|
import '../styles/colors.dart';
|
|
|
import '../styles/api.dart';
|
|
|
@@ -10,6 +12,10 @@ import 'dart:typed_data';
|
|
|
import 'dart:convert';
|
|
|
import 'dart:ui';
|
|
|
import '../styles/totast.dart';
|
|
|
+import 'package:flutter_redux/flutter_redux.dart';
|
|
|
+import '../state.dart';
|
|
|
+import 'changeUserInfo.dart'; //修改信息页面
|
|
|
+import 'loginFirst.dart'; //登录
|
|
|
|
|
|
class Setting extends StatefulWidget {
|
|
|
@override
|
|
|
@@ -45,7 +51,14 @@ class SettingState extends State<Setting> {
|
|
|
// TODO: implement initState
|
|
|
super.initState();
|
|
|
|
|
|
- getUserInfo(false);
|
|
|
+ // getUserInfo(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void didChangeDependencies() {
|
|
|
+ // TODO: implement didChangeDependencies
|
|
|
+ super.didChangeDependencies();
|
|
|
+ userInfo = StoreProvider.of<CountState>(context).state.userInfo;
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -60,44 +73,92 @@ class SettingState extends State<Setting> {
|
|
|
centerTitle: true,
|
|
|
elevation: 0,
|
|
|
),
|
|
|
- body: RefreshIndicator(
|
|
|
- color: PRIMARY_COLOR,
|
|
|
- backgroundColor: BG_SUB_COLOR,
|
|
|
- displacement: 10,
|
|
|
- onRefresh: () async {
|
|
|
- await new Future.delayed(const Duration(seconds: 1));
|
|
|
- getUserInfo(false);
|
|
|
- },
|
|
|
- child: SingleChildScrollView(
|
|
|
- physics: AlwaysScrollableScrollPhysics(),
|
|
|
- child: ConstrainedBox(
|
|
|
- constraints: BoxConstraints(
|
|
|
- minHeight: window.physicalSize.height /
|
|
|
- window.devicePixelRatio -
|
|
|
- 56 -
|
|
|
- MediaQueryData.fromWindow(window).padding.top),
|
|
|
- child: Container(
|
|
|
- color: BG_COLOR,
|
|
|
- child: Column(
|
|
|
- children: <Widget>[
|
|
|
- Container(
|
|
|
- color: BG_SUB_COLOR,
|
|
|
- padding: EdgeInsets.only(top: 10),
|
|
|
- child: Column(
|
|
|
- children: <Widget>[_settingItem('头像')],
|
|
|
- ),
|
|
|
- )
|
|
|
- ],
|
|
|
- ),
|
|
|
- ),
|
|
|
- ))),
|
|
|
- floatingActionButton: FloatingActionButton(
|
|
|
- onPressed: () {
|
|
|
- print('点击照片');
|
|
|
- Toast.show(context, '加载中', -1, 'loading');
|
|
|
- },
|
|
|
- tooltip: 'Pick Image',
|
|
|
- child: Icon(Icons.add_a_photo),
|
|
|
+ body: Stack(
|
|
|
+ children: <Widget>[
|
|
|
+ RefreshIndicator(
|
|
|
+ color: PRIMARY_COLOR,
|
|
|
+ backgroundColor: BG_SUB_COLOR,
|
|
|
+ displacement: 10,
|
|
|
+ onRefresh: () async {
|
|
|
+ await new Future.delayed(const Duration(seconds: 1));
|
|
|
+ getUserInfo(false);
|
|
|
+ },
|
|
|
+ child: SingleChildScrollView(
|
|
|
+ physics: AlwaysScrollableScrollPhysics(),
|
|
|
+ child: ConstrainedBox(
|
|
|
+ constraints: BoxConstraints(
|
|
|
+ minHeight: window.physicalSize.height /
|
|
|
+ window.devicePixelRatio -
|
|
|
+ 56 -
|
|
|
+ MediaQueryData.fromWindow(window)
|
|
|
+ .padding
|
|
|
+ .top),
|
|
|
+ child: Container(
|
|
|
+ padding: EdgeInsets.only(bottom: 100),
|
|
|
+ color: BG_COLOR,
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ Container(
|
|
|
+ color: BG_SUB_COLOR,
|
|
|
+ padding: EdgeInsets.only(top: 10),
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ _settingItem('头像', true),
|
|
|
+ _settingItem('昵称', true),
|
|
|
+ _settingItem('性别', true),
|
|
|
+ _settingItem('生日', true),
|
|
|
+ _settingItem('手机', false),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ color: BG_SUB_COLOR,
|
|
|
+ padding: EdgeInsets.only(top: 10),
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ _settingItem('是否接受消息提示', false),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ color: BG_SUB_COLOR,
|
|
|
+ padding: EdgeInsets.only(top: 10),
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ _settingItem('检查更新', true),
|
|
|
+ _settingItem('版本号', false),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ))),
|
|
|
+ Positioned(
|
|
|
+ bottom: 10,
|
|
|
+ width: ScreenUtil().setWidth(345),
|
|
|
+ left: ScreenUtil().setWidth(15),
|
|
|
+ height: 48,
|
|
|
+ child: FlatButton(
|
|
|
+ textColor: Colors.white,
|
|
|
+ color: PRIMARY_COLOR,
|
|
|
+ highlightColor: Color(0xFF763434),
|
|
|
+ child: Text("退出登录"),
|
|
|
+ onPressed: () {
|
|
|
+ print('退出登录');
|
|
|
+ StoreProvider.of<CountState>(context).dispatch({
|
|
|
+ "action": Actions.updateAll,
|
|
|
+ "token": "",
|
|
|
+ "user": {}
|
|
|
+ });
|
|
|
+ Toast.show(context, '退出成功', 1500, 'success');
|
|
|
+ Navigator.push(
|
|
|
+ context,
|
|
|
+ new MaterialPageRoute(
|
|
|
+ builder: (context) => new LoginFirst()));
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ ],
|
|
|
)),
|
|
|
onWillPop: () {
|
|
|
Toast.hide();
|
|
|
@@ -106,29 +167,55 @@ class SettingState extends State<Setting> {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- Widget _settingItem(name) {
|
|
|
+ Widget _settingItem(name, isNext) {
|
|
|
return Container(
|
|
|
padding: EdgeInsets.only(left: 15, right: 15),
|
|
|
- height: 60,
|
|
|
color: BG_COLOR,
|
|
|
child: GestureDetector(
|
|
|
- child: Row(
|
|
|
+ child: Column(
|
|
|
children: <Widget>[
|
|
|
- Text(name,
|
|
|
- style: TextStyle(
|
|
|
- color: Colors.white,
|
|
|
- fontSize: 14,
|
|
|
- fontWeight: FontWeight.w400)),
|
|
|
- Expanded(flex: 1, child: _centerWidget('头像')),
|
|
|
- Image.asset(
|
|
|
- 'images/icon_inter.png',
|
|
|
- width: 24,
|
|
|
+ Container(
|
|
|
+ height: 60,
|
|
|
+ child: Row(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
+ children: <Widget>[
|
|
|
+ Text(name,
|
|
|
+ style: TextStyle(
|
|
|
+ color: Colors.white,
|
|
|
+ fontSize: 14,
|
|
|
+ fontWeight: FontWeight.w400)),
|
|
|
+ Expanded(flex: 1, child: _centerWidget(name)),
|
|
|
+ Image.asset(
|
|
|
+ 'images/icon_inter.png',
|
|
|
+ width: name != '是否接受消息提示' && name != '版本号' ? 24 : 0,
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ height: isNext ? 1 : 0,
|
|
|
+ color: BG_SUB_COLOR,
|
|
|
+ width: double.infinity,
|
|
|
)
|
|
|
],
|
|
|
),
|
|
|
onTap: () {
|
|
|
if (name == '头像') {
|
|
|
getImage();
|
|
|
+ } else if (name == '昵称') {
|
|
|
+ Navigator.push(
|
|
|
+ context,
|
|
|
+ new CupertinoPageRoute(
|
|
|
+ builder: (context) => new ChangeUserInfo(title: '昵称')));
|
|
|
+ } else if (name == '性别') {
|
|
|
+ showPicker(context);
|
|
|
+ } else if (name == '生日') {
|
|
|
+ showPickerDate(context);
|
|
|
+ } else if (name == '手机') {
|
|
|
+ Navigator.push(
|
|
|
+ context,
|
|
|
+ new CupertinoPageRoute(
|
|
|
+ builder: (context) => new ChangeUserInfo(title: '手机号')));
|
|
|
}
|
|
|
},
|
|
|
),
|
|
|
@@ -138,6 +225,19 @@ class SettingState extends State<Setting> {
|
|
|
Widget _centerWidget(name) {
|
|
|
Widget _wiget;
|
|
|
print(name);
|
|
|
+
|
|
|
+ TextStyle mainText = TextStyle(
|
|
|
+ color: Colors.white,
|
|
|
+ fontSize: 15,
|
|
|
+ fontWeight: FontWeight.w500,
|
|
|
+ );
|
|
|
+
|
|
|
+ TextStyle placText = TextStyle(
|
|
|
+ color: Color(0xFF727785),
|
|
|
+ fontSize: 13,
|
|
|
+ fontWeight: FontWeight.w400,
|
|
|
+ );
|
|
|
+
|
|
|
if (name == '头像') {
|
|
|
_wiget = UnconstrainedBox(
|
|
|
alignment: Alignment.centerRight,
|
|
|
@@ -149,6 +249,79 @@ class SettingState extends State<Setting> {
|
|
|
userInfo.containsKey('icon') ? userInfo['icon'] : '')),
|
|
|
),
|
|
|
);
|
|
|
+ } else if (name == '昵称') {
|
|
|
+ _wiget = Text(
|
|
|
+ userInfo.containsKey('nickname') ? userInfo['nickname'] : '',
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ } else if (name == '性别') {
|
|
|
+ if (userInfo.containsKey('sex')) {
|
|
|
+ _wiget = Text(
|
|
|
+ userInfo['sex'],
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ _wiget = Text(
|
|
|
+ '请添加性别信息',
|
|
|
+ style: placText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else if (name == '生日') {
|
|
|
+ if (userInfo.containsKey('birthday')) {
|
|
|
+ _wiget = Text(
|
|
|
+ readTimestamp(userInfo['birthday']),
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ _wiget = Text(
|
|
|
+ '选择生日',
|
|
|
+ style: placText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else if (name == '手机') {
|
|
|
+ if (userInfo.containsKey('phone')) {
|
|
|
+ _wiget = Text(
|
|
|
+ userInfo['phone'],
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ _wiget = Text(
|
|
|
+ '请输入手机号',
|
|
|
+ style: placText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else if (name == '是否接受消息提示') {
|
|
|
+ _wiget = UnconstrainedBox(
|
|
|
+ alignment: Alignment.centerRight,
|
|
|
+ child: Container(
|
|
|
+ width: 60,
|
|
|
+ child: Switch(
|
|
|
+ value: true,
|
|
|
+ activeColor: PRIMARY_COLOR, // 激活时原点颜色
|
|
|
+ onChanged: (bool val) {},
|
|
|
+ ),
|
|
|
+ ));
|
|
|
+ } else if (name == '版本号') {
|
|
|
+ if (userInfo.containsKey('phone')) {
|
|
|
+ _wiget = Text(
|
|
|
+ 'V1.2.20',
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ _wiget = Text(
|
|
|
+ '',
|
|
|
+ style: mainText,
|
|
|
+ textAlign: TextAlign.right,
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
return _wiget;
|
|
|
@@ -157,12 +330,14 @@ class SettingState extends State<Setting> {
|
|
|
void updateUserInfo(value, key) async {
|
|
|
print(value);
|
|
|
print(key);
|
|
|
- FormData formdata =
|
|
|
- new FormData.from({key: value, "id": isDebug ? debugID : ''});
|
|
|
+ FormData formdata = new FormData.from({key: value, "id": userInfo['id']});
|
|
|
print(formdata);
|
|
|
- final response =
|
|
|
- await Dio().post(domain + 'userInfo/update', data: formdata);
|
|
|
- print(response);
|
|
|
+ final response = await Dio().post(domain + 'userInfo/update',
|
|
|
+ data: formdata,
|
|
|
+ options: Options(headers: {
|
|
|
+ "token": StoreProvider.of<CountState>(context).state.usetoken
|
|
|
+ }));
|
|
|
+ print(response);
|
|
|
final res = json.decode(response.toString());
|
|
|
if (res['success']) {
|
|
|
Toast.hide();
|
|
|
@@ -172,23 +347,60 @@ class SettingState extends State<Setting> {
|
|
|
}
|
|
|
|
|
|
void getUserInfo(isFreash) async {
|
|
|
- Future.delayed(Duration(seconds: 1000), () {
|
|
|
- if (!userInfo.containsKey('nickname')) {
|
|
|
- Toast.show(context, '加载中', -1, 'loading');
|
|
|
- isFreash = true;
|
|
|
- }
|
|
|
- });
|
|
|
final response = await Dio().get(domain + 'userInfo/getUserInfo',
|
|
|
- data: {"id": isDebug ? debugID : ''});
|
|
|
+ options: Options(headers: {
|
|
|
+ "token": StoreProvider.of<CountState>(context).state.usetoken
|
|
|
+ }));
|
|
|
final res = json.decode(response.toString());
|
|
|
- if (isFreash) {
|
|
|
- Toast.hide();
|
|
|
- }
|
|
|
if (res['success']) {
|
|
|
- print(res['data']);
|
|
|
+ StoreProvider.of<CountState>(context)
|
|
|
+ .dispatch({"action": Actions.updateUser, "val": res['data']});
|
|
|
setState(() {
|
|
|
userInfo = res['data'];
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ showPicker(BuildContext context) {
|
|
|
+ String PickerData = '''["男","女"]''';
|
|
|
+ new Picker(
|
|
|
+ confirmText: '确定',
|
|
|
+ cancelText: "取消",
|
|
|
+ adapter: PickerDataAdapter<String>(
|
|
|
+ pickerdata: new JsonDecoder().convert(PickerData)),
|
|
|
+ changeToFirst: true,
|
|
|
+ textAlign: TextAlign.left,
|
|
|
+ columnPadding: const EdgeInsets.all(8.0),
|
|
|
+ onConfirm: (Picker picker, List value) {
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+ updateUserInfo(
|
|
|
+ picker.getSelectedValues()[0].toString().trim(), 'sex');
|
|
|
+ }).showModal(this.context);
|
|
|
+ }
|
|
|
+
|
|
|
+ showPickerDate(BuildContext context) {
|
|
|
+ new Picker(
|
|
|
+ hideHeader: true,
|
|
|
+ confirmText: '确定',
|
|
|
+ cancelText: "取消",
|
|
|
+ adapter: new DateTimePickerAdapter(
|
|
|
+ type: PickerDateTimeType.kYMD,
|
|
|
+ isNumberMonth: true,
|
|
|
+ //strAMPM: const["上午", "下午"],
|
|
|
+ yearSuffix: "年",
|
|
|
+ monthSuffix: "月",
|
|
|
+ daySuffix: "日"),
|
|
|
+ title: new Text("选择出生日期"),
|
|
|
+ onConfirm: (Picker picker, List value) {
|
|
|
+ if (DateTime.parse(picker.adapter.toString()).millisecondsSinceEpoch >
|
|
|
+ DateTime.now().millisecondsSinceEpoch) {
|
|
|
+ Toast.show(context, '日期错误', 1500, 'info');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+ updateUserInfo(
|
|
|
+ DateTime.parse(picker.adapter.toString()).millisecondsSinceEpoch,
|
|
|
+ 'birthday');
|
|
|
+ }).showDialog(context);
|
|
|
+ }
|
|
|
}
|