|
|
@@ -0,0 +1,379 @@
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:file_picker/file_picker.dart';
|
|
|
+import 'package:flutter/cupertino.dart';
|
|
|
+import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
+import 'package:dio/dio.dart';
|
|
|
+import 'package:intl/intl.dart';
|
|
|
+import 'package:jpush_flutter/jpush_flutter.dart';
|
|
|
+import 'package:package_info/package_info.dart';
|
|
|
+import 'package:shared_preferences/shared_preferences.dart';
|
|
|
+import '../styles/colors.dart';
|
|
|
+import 'dart:io';
|
|
|
+import 'dart:async';
|
|
|
+import 'dart:convert';
|
|
|
+import 'dart:ui';
|
|
|
+import '../styles/totast.dart';
|
|
|
+import 'ChangeUserInfo.dart'; //修改信息页面
|
|
|
+import 'loginFirst.dart'; //登录
|
|
|
+import 'package:redux/redux.dart';
|
|
|
+import 'package:flutter_redux/flutter_redux.dart';
|
|
|
+import '../redux/AppState.dart';
|
|
|
+import '../model/UserInfo.dart';
|
|
|
+import '../net/HttpManager.dart';
|
|
|
+import '../net/Result.dart';
|
|
|
+import '../redux/UserRedux.dart';
|
|
|
+
|
|
|
+class UserChange extends StatefulWidget {
|
|
|
+ @override
|
|
|
+ UserChangeState createState() => UserChangeState();
|
|
|
+}
|
|
|
+
|
|
|
+class UserChangeState extends State<UserChange> {
|
|
|
+ String version = "";
|
|
|
+ bool receiveMsg = false;
|
|
|
+
|
|
|
+ void getFilePath() async {
|
|
|
+ String filePath = await FilePicker.getFilePath(type: FileType.IMAGE);
|
|
|
+ if (filePath == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ File _file = File(filePath);
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+ Result res = await HttpManager.post("assets/uploadFile", data: {
|
|
|
+ "file": UploadFileInfo(_file, filePath),
|
|
|
+ });
|
|
|
+ Toast.hide();
|
|
|
+ if (res.success) {
|
|
|
+ updateUserInfo(StoreProvider.of<AppState>(context).state.userInfo, res.data[0], 'icon');
|
|
|
+ } else {}
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ super.initState();
|
|
|
+ PackageInfo.fromPlatform().then((packageInfo) {
|
|
|
+ setState(() {
|
|
|
+ version = packageInfo.version;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
|
|
|
+ return StoreConnector<AppState, UserInfo>(
|
|
|
+ converter: (Store store) => store.state.userInfo,
|
|
|
+ builder: (context, userInfo) {
|
|
|
+ return new WillPopScope(
|
|
|
+ key: Key("UserChangesPage"),
|
|
|
+ child: Scaffold(
|
|
|
+ backgroundColor: PAGE_BACKGROUND_COLOR,
|
|
|
+ appBar: AppBar(
|
|
|
+ backgroundColor: PRIMARY_COLOR,
|
|
|
+ title: Text('系统设置'),
|
|
|
+ centerTitle: true,
|
|
|
+ elevation: 0,
|
|
|
+ ),
|
|
|
+ body: Stack(
|
|
|
+ children: <Widget>[
|
|
|
+ RefreshIndicator(
|
|
|
+ color: PRIMARY_COLOR,
|
|
|
+ backgroundColor: Colors.white,
|
|
|
+ displacement: 10,
|
|
|
+ onRefresh: () async {
|
|
|
+ await new Future.delayed(const Duration(seconds: 1));
|
|
|
+ getUserInfo();
|
|
|
+ },
|
|
|
+ child: SizedBox.expand(
|
|
|
+ child: SingleChildScrollView(
|
|
|
+ physics: AlwaysScrollableScrollPhysics(),
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ _sectionDivier(),
|
|
|
+ _section([
|
|
|
+ _cell(
|
|
|
+ '头像',
|
|
|
+ ClipOval(
|
|
|
+ child: Image.network(userInfo.icon, width: 36, height: 36),
|
|
|
+ ), onTap: () {
|
|
|
+ getFilePath();
|
|
|
+ }),
|
|
|
+ _cell('昵称', userInfo.nickname, placeholder: '请填写昵称', onTap: () {
|
|
|
+ Navigator.push(
|
|
|
+ context, new CupertinoPageRoute(builder: (context) => new ChangeUserInfo(title: '昵称', val: userInfo.nickname)));
|
|
|
+ }),
|
|
|
+ _cell('性别', userInfo.sex, placeholder: '请添加性别信息', onTap: () {
|
|
|
+ _chooseSex(context);
|
|
|
+ }),
|
|
|
+ _cell(
|
|
|
+ '生日',
|
|
|
+ DateFormat('yyyy-MM-dd').format(
|
|
|
+ DateTime.fromMillisecondsSinceEpoch(userInfo.birthday),
|
|
|
+ ),
|
|
|
+ placeholder: '选择生日',
|
|
|
+ onTap: () {
|
|
|
+ _chooseBirthday(context);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ _cell('手机', userInfo.phone, showBorder: false, onTap: () {
|
|
|
+ Navigator.push(context, new CupertinoPageRoute(builder: (context) => new ChangeUserInfo(title: '手机号', val: userInfo.phone)));
|
|
|
+ })
|
|
|
+ ]),
|
|
|
+
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ // Positioned(
|
|
|
+ // bottom: 10,
|
|
|
+ // right: 15,
|
|
|
+ // left: 15,
|
|
|
+ // height: 48,
|
|
|
+ // child: FlatButton(
|
|
|
+ // textColor: Colors.white,
|
|
|
+ // color: PRIMARY_COLOR,
|
|
|
+ // highlightColor: Color(0xFF763434),
|
|
|
+ // child: Text(
|
|
|
+ // "退出登录",
|
|
|
+ // style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
|
|
|
+ // ),
|
|
|
+ // onPressed: () async {
|
|
|
+ // Toast.show(context, '退出成功', 1500, 'success');
|
|
|
+ // Navigator.push(context, new MaterialPageRoute(builder: (context) => new LoginFirst()));
|
|
|
+ // final prefs = await SharedPreferences.getInstance();
|
|
|
+ // prefs.remove('token');
|
|
|
+ // JPush jpush = JPush();
|
|
|
+ // jpush.deleteAlias();
|
|
|
+ // // Future.delayed(const Duration(seconds: 1), () {
|
|
|
+ // // StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(null));
|
|
|
+ // // });
|
|
|
+ // }),
|
|
|
+ // )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ onWillPop: () {
|
|
|
+ Toast.hide();
|
|
|
+ Navigator.pop(context);
|
|
|
+ return Future.value(false);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void updateUserInfo(userInfo, value, key) async {
|
|
|
+ if (Toast.preToast == null) {
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+ }
|
|
|
+ final Result res = await HttpManager.post('userInfo/update', data: {"id": userInfo.id, key: value});
|
|
|
+ Toast.hide();
|
|
|
+ if (res.success) {
|
|
|
+ Toast.show(context, '修改成功', 1500, 'success');
|
|
|
+ getUserInfo();
|
|
|
+ } else {
|
|
|
+ Toast.show(context, res.error, 1500, 'info');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void getUserInfo() async {
|
|
|
+ Result res = await HttpManager.get("userInfo/getUserInfo");
|
|
|
+ if (res.success) {
|
|
|
+ StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
|
|
|
+ } else {}
|
|
|
+ }
|
|
|
+
|
|
|
+ _chooseSex(BuildContext context) async {
|
|
|
+ String sex = await showCupertinoModalPopup(
|
|
|
+ context: context,
|
|
|
+ builder: (BuildContext context) {
|
|
|
+ return CupertinoActionSheet(
|
|
|
+ title: Text('选择性别'),
|
|
|
+ actions: <Widget>[
|
|
|
+ CupertinoActionSheetAction(
|
|
|
+ child: Text('男'),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.pop(context, '男');
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ CupertinoActionSheetAction(
|
|
|
+ child: Text('女'),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.pop(context, '女');
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ CupertinoDialogAction(
|
|
|
+ child: const Text('取消'),
|
|
|
+ isDestructiveAction: true,
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.pop(context);
|
|
|
+ },
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ });
|
|
|
+ if (sex != null) {
|
|
|
+ updateUserInfo(StoreProvider.of<AppState>(context).state.userInfo, sex, 'sex');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _chooseBirthday(BuildContext context) async {
|
|
|
+ UserInfo userInfo = StoreProvider.of<AppState>(context).state.userInfo;
|
|
|
+ DateTime date = userInfo.birthday > 0 ? DateTime.fromMillisecondsSinceEpoch(userInfo.birthday) : DateTime.now();
|
|
|
+ DateTime res = await showCupertinoModalPopup<DateTime>(
|
|
|
+ context: context,
|
|
|
+ builder: (BuildContext context) {
|
|
|
+ return Container(
|
|
|
+ height: 216,
|
|
|
+ color: CupertinoColors.white,
|
|
|
+ child: Column(
|
|
|
+ children: <Widget>[
|
|
|
+ SizedBox(
|
|
|
+ height: 44,
|
|
|
+ child: Stack(
|
|
|
+ children: <Widget>[
|
|
|
+ Positioned(
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ bottom: 0,
|
|
|
+ child: CupertinoButton(
|
|
|
+ child: Text(
|
|
|
+ '取消',
|
|
|
+ style: TextStyle(color: PRIMARY_COLOR),
|
|
|
+ ),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.of(context).pop();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Positioned(
|
|
|
+ right: 0,
|
|
|
+ top: 0,
|
|
|
+ bottom: 0,
|
|
|
+ child: CupertinoButton(
|
|
|
+ child: Text(
|
|
|
+ '确定',
|
|
|
+ style: TextStyle(color: PRIMARY_COLOR),
|
|
|
+ ),
|
|
|
+ onPressed: () {
|
|
|
+ Navigator.of(context).pop(date);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(
|
|
|
+ flex: 1,
|
|
|
+ child: DefaultTextStyle(
|
|
|
+ style: const TextStyle(
|
|
|
+ color: CupertinoColors.black,
|
|
|
+ fontSize: 22.0,
|
|
|
+ ),
|
|
|
+ child: GestureDetector(
|
|
|
+ // Blocks taps from propagating to the modal sheet and popping.
|
|
|
+ onTap: () {},
|
|
|
+ child: SafeArea(
|
|
|
+ top: false,
|
|
|
+ child: CupertinoDatePicker(
|
|
|
+ mode: CupertinoDatePickerMode.date,
|
|
|
+ initialDateTime: date,
|
|
|
+ onDateTimeChanged: (DateTime newDateTime) {
|
|
|
+ date = newDateTime;
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ );
|
|
|
+ if (res != null) {
|
|
|
+ updateUserInfo(userInfo, res.millisecondsSinceEpoch, 'birthday');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _chooseImage(BuildContext context) async {
|
|
|
+ UserInfo userInfo = StoreProvider.of<AppState>(context).state.userInfo;
|
|
|
+ var image = await FilePicker.getFilePath(type: FileType.IMAGE);
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+ File _image = File(image);
|
|
|
+ _image.readAsBytes().then((bytes) async {
|
|
|
+ String encoded1 = 'data:image/jpeg;base64,' + base64Encode(bytes);
|
|
|
+ FormData formData = new FormData.from({"base64": encoded1});
|
|
|
+ Result res = await HttpManager.post('assets/uploadImg', data: formData);
|
|
|
+ if (res.success) {
|
|
|
+ updateUserInfo(userInfo, res.data, 'icon');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _sectionDivier() {
|
|
|
+ return SizedBox(height: 10);
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _section(List<Widget> children) {
|
|
|
+ return Container(
|
|
|
+ color: CELL_COLOR,
|
|
|
+ child: Column(
|
|
|
+ children: children,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _cell(String title, dynamic child, {String placeholder, void Function() onTap, bool showBorder = true}) {
|
|
|
+ Widget secondChild;
|
|
|
+ if (child == null || (child is String && child.length == 0)) {
|
|
|
+ secondChild = Text(
|
|
|
+ placeholder ?? '',
|
|
|
+ style: TextStyle(color: PLACEHOLDER_COLOR, fontSize: 13),
|
|
|
+ );
|
|
|
+ } else if (child is String) {
|
|
|
+ secondChild = Text(
|
|
|
+ child ?? '',
|
|
|
+ style: TextStyle(color: Colors.white, fontSize: 15),
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ secondChild = child;
|
|
|
+ }
|
|
|
+ return Container(
|
|
|
+ height: 60,
|
|
|
+ padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
|
|
|
+ child: GestureDetector(
|
|
|
+ onTap: onTap,
|
|
|
+ child: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ border: Border(
|
|
|
+ bottom: BorderSide(
|
|
|
+ color: Color(0x2E000000),
|
|
|
+ width: showBorder ? 1 : 0,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ child: Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.center,
|
|
|
+ children: <Widget>[
|
|
|
+ Expanded(
|
|
|
+ child: Text(
|
|
|
+ title ?? '',
|
|
|
+ style: TextStyle(color: Colors.white, fontSize: 14),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ secondChild,
|
|
|
+ Padding(
|
|
|
+ padding: EdgeInsets.only(left: 2),
|
|
|
+ child: Image.asset(
|
|
|
+ "images/icon_inter.png",
|
|
|
+ width: 24,
|
|
|
+ height: 24,
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|