Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

杨树贤 / kefu_server

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • kefu_server
  • ui
  • kefu_workbench
  • lib
  • views
  • user_detail
  • index.dart
index.dart 6.25 KB
chenxianqi's avatar
增加kefu_workbench
a18da124
 
chenxianqi committed 5 years ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
import 'package:dio/dio.dart';
import 'package:kefu_workbench/core_flutter.dart';
import 'package:kefu_workbench/provider/global.dart';
import 'package:kefu_workbench/provider/user.dart';

class UserDetailPage extends   StatefulWidget {
  final Map<dynamic, dynamic> arguments;
  UserDetailPage({this.arguments});
  @override
  _UserDetailPageState createState() => _UserDetailPageState();
}
class _UserDetailPageState extends State<UserDetailPage> {

   UserModel user;

  @override
  void initState() {
    super.initState();
    user = widget.arguments['user'];
  }


  /// edit
  void _goEdit(BuildContext context) async{
    Navigator.pushNamed(context, "/user_edit",arguments: {
      "user": user
    }).then((isSuccess) async{
      if(isSuccess == true){
        await UserProvide.getInstance().getUser(user.id);
        user =  UserProvide.getInstance().getItem(user.id);
        setState(() {});
      }
    });
  }

  /// delete
  void _delete(BuildContext context){
    UX.alert(
      context,
      content: Text("是否删除该用户吗!"),
      onConfirm: () async{
       Response response = await UserService.getInstance().delete(id: user.id);
       if (response.data["code"] == 200) {
         UX.showToast("删除成功");
         UserProvide.getInstance().deleteItem(user.id);
         Navigator.pop(context);
      } else {
        UX.showToast("${response.data["message"]}");
      }
      }
    );
  }
  
  @override
  Widget build(context) {
    user =  UserProvide.getInstance().getItem(user.id);
    return PageContext(builder: (context){
      ThemeData themeData = Theme.of(context);
      Widget _lineItem({
        Widget label = const Text(""),
        Widget icon = const Text(""),
        String content,
        TextStyle style,
        Widget subChild = const SizedBox(), 
        CrossAxisAlignment contextCrossAxisAlignment = CrossAxisAlignment.start
      }){
        return Container(
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(color: themeData.dividerColor))
            ),
            padding: EdgeInsets.symmetric(horizontal: ToPx.size(20), vertical: ToPx.size(40)),
            child: DefaultTextStyle(
              style: style,
              child: Row(
                children: <Widget>[
                  icon,
                  Expanded(
                    child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                    Row(
                        crossAxisAlignment: contextCrossAxisAlignment,
                      children: <Widget>[
                        label,
                        Expanded(
                          child: Text("$content", textAlign: TextAlign.left,),
                        )
                      ],
                    ),
                    subChild
                  ],),
                  )
                ],
              )
            )
          );
      }
      return Scaffold(
        backgroundColor: themeData.primaryColorLight,
        appBar: customAppBar(
            title: Text(
              "${user.nickname}",
              style: themeData.textTheme.display1,
            ),
            actions: [
              Button(
                height: ToPx.size(90),
                useIosStyle: true,
                color: Colors.transparent,
                width: ToPx.size(150),
                child: Text("编辑"),
                onPressed: () => _goEdit(context)
              ),
            ],
          ),
        body: ListView(
          children: <Widget>[
              _lineItem(
                icon: Avatar(
                  size: ToPx.size(100),
                  imgUrl: user.avatar == null || user.avatar.isEmpty ?
                  "http://qiniu.cmp520.com/avatar_default.png" : user.avatar
                ),
                content: "  ${user.nickname}",
                style: themeData.textTheme.title,
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                subChild: Row(
                  children: <Widget>[
                    Text("  所在平台:", style: themeData.textTheme.caption),
                    Text("${GlobalProvide.getInstance().getPlatformTitle(user.platform)}", style: themeData.textTheme.caption),
                  ],
                )
              ),
              _lineItem(
                label: Text("在线状态:"),
                content: user.online ==1 ? "在线" : "离线",
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
              _lineItem(
                label: Text("业务平台ID:"),
                content: user.uid.toString(),
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
              _lineItem(
                label: Text("所在地区:"),
                content: user.address.isNotEmpty ?  user.address : "未知地区",
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
               _lineItem(
                label: Text("联系方式:"),
                content: user.phone.isNotEmpty ?  user.phone : "未知联系方式",
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
              _lineItem(
                label: Text("备注信息:"),
                content: user.remarks.isNotEmpty ?  user.remarks : "未知设置备注",
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
              _lineItem(
                label: Text("注册时间:"),
                content: Utils.formatDate(user.createAt),
                contextCrossAxisAlignment: CrossAxisAlignment.center,
                style: themeData.textTheme.body1,
              ),
              Button(
                margin: EdgeInsets.symmetric(horizontal: ToPx.size(40), vertical: ToPx.size(50)),
                child: Text("删除"),
                withAlpha: 200,
                color: Colors.redAccent,
                onPressed: () => _delete(context),
              )
          ],
        )

      );
    }); 
  }
}