| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import 'package:flutter/material.dart';
- import '../styles/colors.dart';
- import 'dart:ui';
- import '../styles/totast.dart';
- import '../widget/ITextInput.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 'dart:convert';
- class ChangeUserInfo extends StatefulWidget {
- ChangeUserInfo({Key key, this.title, this.val}) : super(key: key);
- final String title; // 用来储存传递过来的值
- final String val; // 用来储存传递过来的值
- @override
- ChangeUserInfoState createState() => ChangeUserInfoState();
- }
- class ChangeUserInfoState extends State<ChangeUserInfo> {
- Map userInfo = {};
- String changeText = '';
- String changekey = 'nickname';
- @override
- void initState() {
- super.initState();
- switch (widget.title) {
- case '昵称':
- changekey = 'nickname';
- break;
- case '手机号':
- changekey = 'phone';
- break;
- }
- changeText = widget.val;
- }
- @override
- Widget build(BuildContext context) {
- return StoreConnector<AppState, UserInfo>(
- converter: (Store store) => store.state.userInfo,
- builder: (context, userInfo) {
- return new WillPopScope(
- child: Scaffold(
- appBar: AppBar(
- backgroundColor: PRIMARY_COLOR,
- title: Text('修改' + widget.title),
- centerTitle: true,
- elevation: 0,
- ),
- body: Container(
- padding: EdgeInsets.symmetric(vertical: 30, horizontal: 15),
- color: BG_COLOR,
- child: Column(
- children: <Widget>[
- Container(
- child: ITextField(
- autofocus: true,
- inputText: changeText,
- maxLength: 15,
- hintText: '输入用户' + widget.title,
- hintStyle: TextStyle(
- fontSize: 16,
- color: Color(0xFF727785),
- ),
- textStyle: TextStyle(
- color: Colors.white,
- fontSize: 18,
- fontWeight: FontWeight.w500),
- fieldCallBack: (content) {
- setState(() {
- changeText = content;
- });
- },
- counterStyle:
- TextStyle(color: BG_SUB_COLOR, fontSize: 0),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 30),
- width: double.infinity,
- height: 48,
- child: FlatButton(
- textColor: Colors.white,
- color: PRIMARY_COLOR,
- highlightColor: Color(0xFF763434),
- child: Text(
- "确定修改",
- style: TextStyle(
- fontSize: 16, fontWeight: FontWeight.w500),
- ),
- onPressed: () async {
- if (changeText.isEmpty) {
- Toast.show(context, '修改内容不能为空', 1500, 'info');
- return;
- }
- Toast.show(context, '加载中', -1, 'loading');
- final Result res = await HttpManager.post(
- 'userInfo/update',
- data: {
- "id": userInfo.id,
- changekey: changeText
- });
- Toast.hide();
- if (res.success) {
- Result res2 = await HttpManager.get(
- "userInfo/getUserInfo");
- if (res2.success) {
- StoreProvider.of<AppState>(context)
- .dispatch({
- "action": Actions.updateUser,
- "user": res2.data
- });
- Toast.show(
- context, '修改成功', 1000, 'success');
- Future.delayed(Duration(milliseconds: 1000),
- () {
- Navigator.of(context).pop();
- });
- } else {}
- } else {
- Toast.show(context, res.error, 1500, 'info');
- }
- }),
- ),
- ],
- ),
- )),
- onWillPop: () {
- Toast.hide();
- Navigator.pop(context, false);
- return Future.value(false);
- });
- });
- }
- }
|