Skip to content

Commit 0f7ab5a

Browse files
committed
feat: 添加issue回复功能
1 parent d49bce4 commit 0f7ab5a

File tree

2 files changed

+164
-6
lines changed

2 files changed

+164
-6
lines changed

lib/page/comment/details.dart

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:efox_flutter/lang/index.dart' show AppLocalizations;
33
import 'package:efox_flutter/store/index.dart' show Store, UserModel;
44
import 'package:efox_flutter/store/objects/flutter_ui_issues.dart' show IssuesContent;
55
import 'package:efox_flutter/store/objects/issues_comment.dart' show IssuesDetails;
6+
import 'package:efox_flutter/page/app_login/index.dart' as LoginIndex;
67

78
class Index extends StatefulWidget {
89
int indexes;
@@ -12,6 +13,17 @@ class Index extends StatefulWidget {
1213
}
1314

1415
class _IndexState extends State<Index> {
16+
final TextEditingController _controller = TextEditingController();
17+
var _getComment;
18+
bool isCanSend = false;
19+
20+
@override
21+
void initState() {
22+
// TODO: implement initState
23+
super.initState();
24+
_getComment = this._getIssueComment(context);
25+
}
26+
1527
@override
1628
Widget build(BuildContext context) {
1729
return Scaffold(
@@ -22,9 +34,15 @@ class _IndexState extends State<Index> {
2234
AppLocalizations.$t('title_comment_detials')
2335
),
2436
),
25-
body: Container(
26-
child: _ContentList(context)
27-
),
37+
body: Stack(
38+
children: <Widget>[
39+
Container(
40+
margin: EdgeInsets.only(bottom: 50),
41+
child: _ContentList(context),
42+
),
43+
_SendComment(context)
44+
],
45+
)
2846
);
2947
}
3048

@@ -79,7 +97,7 @@ class _IndexState extends State<Index> {
7997

8098
Widget _CommentContent (BuildContext context) {
8199
return FutureBuilder(
82-
future: _getIssueComment(context),
100+
future: _getComment,
83101
builder: (BuildContext context, AsyncSnapshot snapshot) {
84102
if (snapshot.connectionState == ConnectionState.waiting) {
85103
return Container(
@@ -112,8 +130,8 @@ class _IndexState extends State<Index> {
112130
}
113131

114132
Future<String> _getIssueComment(BuildContext context) async {
115-
IssuesContent issuesContent = Store.value<UserModel>(context).flutter_ui_issues.issuesContent[widget.indexes];
116-
await Store.value<UserModel>(context).getIssueComment(issuesContent.number);
133+
IssuesContent issuesContent = Store.valueNotCtx<UserModel>().flutter_ui_issues.issuesContent[widget.indexes];
134+
await Store.valueNotCtx<UserModel>().getIssueComment(issuesContent.number);
117135
return 'end';
118136
}
119137

@@ -136,4 +154,120 @@ class _IndexState extends State<Index> {
136154
),
137155
);
138156
}
157+
158+
Widget _SendComment (BuildContext context) {
159+
return Positioned(
160+
bottom: 0,
161+
left: 0,
162+
child: Container(
163+
width: MediaQuery.of(context).size.width,
164+
height: 50,
165+
decoration: BoxDecoration(
166+
color: Colors.white,
167+
border: Border(
168+
top: BorderSide(width: 0.5, color: Color(int.parse('0xffe4e4e4')))
169+
)
170+
),
171+
child: Row(
172+
children: <Widget>[
173+
Expanded(
174+
flex: 1,
175+
child: _InputBox(),
176+
),
177+
Store.connect<UserModel>(
178+
builder: (context, child, model) {
179+
IssuesContent issuesContent = model.flutter_ui_issues.issuesContent[widget.indexes];
180+
return GestureDetector(
181+
onTap: () async {
182+
if (isCanSend) {
183+
if (model.user.id != null) {
184+
print('发布内容:${_controller.text}');
185+
bool isSendSuccess = await model.setIssueComment(
186+
_controller.text,
187+
issuesContent.number
188+
);
189+
if (isSendSuccess) {
190+
await this._getIssueComment(context);
191+
_controller.text = '';
192+
} else {
193+
print('网络错误');
194+
Scaffold.of(context).showSnackBar(SnackBar(
195+
content: Text('网络出错,请稍后重试'),
196+
));
197+
}
198+
} else {
199+
print('去往登陆');
200+
Navigator.of(context).push(
201+
MaterialPageRoute(
202+
builder: (BuildContext context) {
203+
return LoginIndex.Index();
204+
}
205+
)
206+
);
207+
}
208+
}
209+
},
210+
child: Container(
211+
padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
212+
child: Text(
213+
'发布',
214+
style: TextStyle(
215+
color: isCanSend ? Theme.of(context).primaryColor : Colors.grey,
216+
fontSize: 17
217+
)
218+
),
219+
),
220+
);
221+
}
222+
)
223+
],
224+
)
225+
),
226+
);
227+
}
228+
Widget _InputBox() {
229+
return Container(
230+
height: 30,
231+
margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
232+
decoration: BoxDecoration(
233+
color: Color(int.parse('0xffEDEDED')),
234+
borderRadius: BorderRadius.circular(15)
235+
),
236+
child: Row(
237+
children: <Widget>[
238+
Expanded(
239+
flex: 1,
240+
child: TextField(
241+
controller: _controller,
242+
autofocus: false,
243+
onChanged: _onChanged,
244+
style: TextStyle(
245+
fontSize: 18.0,
246+
color: Colors.black,
247+
fontWeight: FontWeight.w300
248+
),
249+
decoration: InputDecoration(
250+
contentPadding: EdgeInsets.fromLTRB(10, 0, 10, 0),
251+
border: InputBorder.none,
252+
hintText: '说点什么吧',
253+
hintStyle: TextStyle(fontSize: 15)
254+
),
255+
),
256+
)
257+
],
258+
)
259+
);
260+
}
261+
262+
_onChanged(String text) {
263+
if (text.length > 0) {
264+
setState(() {
265+
isCanSend = true;
266+
});
267+
} else {
268+
setState(() {
269+
isCanSend = false;
270+
});
271+
}
272+
}
139273
}

lib/store/models/user_model.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,28 @@ class UserModel extends UserModelInfo with ChangeNotifier {
246246
print('获取对应issue下的回复内容出错:$error');
247247
}
248248
}
249+
250+
/**
251+
* 回复issue评论
252+
*/
253+
setIssueComment(String text, int number) async {
254+
var data = {
255+
"body": "$text"
256+
};
257+
var response = await Http.post(
258+
url: 'https://api.github.com/repos/$owner_repo/issues/$number/comments',
259+
data: data
260+
);
261+
try {
262+
print('回复issue评论状态码:${response.statusCode}');
263+
if (response.statusCode == 201) {
264+
return true;
265+
} else {
266+
return false;
267+
}
268+
} catch (error) {
269+
print('回复issue评论出错:$error');
270+
return false;
271+
}
272+
}
249273
}

0 commit comments

Comments
 (0)