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
/*
* @author lsy
* @date 2019-09-04
**/
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/commonModel/net/Responce/SimpleResponce.dart';
import 'package:gmalpha_flutter/userModel/page/user/UserPageModel.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/TestUserEntity.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart';
class UserWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => UserState();
}
class UserState extends State<UserWidget> {
UserPageModel _model;
TextEditingController _nameController = new TextEditingController();
TextEditingController _wordController = new TextEditingController();
@override
void initState() {
super.initState();
_model = new UserPageModel();
}
@override
void dispose() {
super.dispose();
_model.dispose();
_wordController.dispose();
_nameController.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"User",
style: TextStyle(fontSize: 16),
),
centerTitle: true,
),
body: Column(
children: <Widget>[
Expanded(
child: StreamBuilder<SimpleResponce>(
stream: _model.logoutLive.stream,
initialData: _model.logoutLive.data,
builder: (BuildContext context,
AsyncSnapshot<SimpleResponce> snapshot) {
if (snapshot.data == null) {
return Center(child: Text("没有退出"));
} else {
return Center(child: Text("退出接口回掉成功!!"));
}
},
),
),
Container(
margin: EdgeInsets.fromLTRB(16, 10, 16, 20),
child: TextField(
cursorColor: Colors.black,
controller: _nameController,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
icon: Icon(Icons.text_fields, color: Colors.black),
labelText: 'name',
labelStyle: TextStyle(color: Colors.black)),
autofocus: false,
),
),
Container(
margin: EdgeInsets.fromLTRB(16, 0, 16, 20),
child: TextField(
cursorColor: Colors.black,
controller: _wordController,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
icon: Icon(
Icons.text_fields,
color: Colors.black,
),
labelText: 'word',
labelStyle: TextStyle(color: Colors.black)),
autofocus: false,
),
),
Container(
width: double.maxFinite,
margin: EdgeInsets.fromLTRB(16, 0, 16, 0),
child: OutlineButton(
onPressed: () => _model.resignUser(
context, _nameController.text, _wordController.text),
child: Text("注册"),
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
)),
Container(
width: double.maxFinite,
margin: EdgeInsets.fromLTRB(16, 0, 16, 0),
child: OutlineButton(
onPressed: () => _model.logout(context),
child: Text("退出"),
shape: BeveledRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
)),
Expanded(
child: StreamBuilder<TestUserEntity>(
stream: _model.resignLive.stream,
initialData: _model.resignLive.data,
builder: (BuildContext context,
AsyncSnapshot<TestUserEntity> snapshot) {
if (snapshot.data != null) {
return Center(
child: snapshot.data.data == null
? Text("错误 ${snapshot.data.errorMsg}")
: Text("登入回掉 用户id: ${snapshot.data.data.id}"),
);
} else {
return Center(
child: Text("初始化~"),
);
}
},
),
)
],
),
);
}
}