Skip to content

Commit 1744373

Browse files
committed
branch list
1 parent f7ace2b commit 1744373

2 files changed

Lines changed: 73 additions & 15 deletions

File tree

‎lib/common/dao/ReposDao.dart‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,22 @@ class ReposDao {
299299
/**
300300
* 获取当前仓库所有分支
301301
*/
302-
static getBranchesDao(userName, reposName) async {}
302+
static getBranchesDao(userName, reposName) async {
303+
String url = Address.getbranches(userName, reposName);
304+
var res = await HttpManager.netFetch(url, null, null, null);
305+
if (res != null && res.result && res.data.length > 0) {
306+
List<String> list = new List();
307+
var dataList = res.data;
308+
if (dataList == null || dataList.length == 0) {
309+
return new DataResult(null, false);
310+
}
311+
for (int i = 0; i < dataList.length; i++) {
312+
var data = dataList[i];
313+
list.add(data['name']);
314+
}
315+
return new DataResult(list, true);
316+
} else {
317+
return new DataResult(null, false);
318+
}
319+
}
303320
}

‎lib/page/RepositoryDetailPage.dart‎

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:async';
2-
31
import 'package:flutter/material.dart';
42
import 'package:gsy_github_app_flutter/common/config/Config.dart';
53
import 'package:gsy_github_app_flutter/common/dao/ReposDao.dart';
@@ -44,6 +42,10 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4442

4543
final TarWidgetControl tarBarControl = new TarWidgetControl();
4644

45+
String currentBranch = "master";
46+
47+
List<String> branchList = new List();
48+
4749
_RepositoryDetailPageState(this.userName, this.reposName);
4850

4951
_getReposDetail() async {
@@ -72,11 +74,60 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
7274
});
7375
}
7476

77+
_getBranchList() async {
78+
var result = await ReposDao.getBranchesDao(userName, reposName);
79+
if (result != null && result.result) {
80+
setState(() {
81+
branchList = result.data;
82+
});
83+
}
84+
}
85+
7586
_refresh() {
7687
this._getReposDetail();
7788
this._getReposStatus();
7889
}
7990

91+
_renderBranchPopItem(String data, List<String> list, onSelected) {
92+
if (list == null && list.length == 0) {
93+
return new Container(height: 0.0, width: 0.0);
94+
}
95+
return new Container(
96+
height: 30.0,
97+
child: new PopupMenuButton<String>(
98+
child: new FlatButton(
99+
onPressed: null,
100+
color: Color(GSYColors.primaryValue),
101+
disabledColor: Color(GSYColors.primaryValue),
102+
child: new GSYIConText(
103+
Icons.arrow_drop_up,
104+
data,
105+
GSYConstant.smallTextWhite,
106+
Color(GSYColors.white),
107+
30.0,
108+
padding: 3.0,
109+
mainAxisAlignment: MainAxisAlignment.center,
110+
),
111+
),
112+
onSelected: onSelected,
113+
itemBuilder: (BuildContext context) {
114+
return _renderHeaderPopItemChild(list);
115+
},
116+
),
117+
);
118+
}
119+
120+
_renderHeaderPopItemChild(List<String> data) {
121+
List<PopupMenuEntry<String>> list = new List();
122+
for (String item in data) {
123+
list.add(PopupMenuItem<String>(
124+
value: item,
125+
child: new Text(item),
126+
));
127+
}
128+
return list;
129+
}
130+
80131
_getBottomWidget() {
81132
List<Widget> bottomWidget = (bottomStatusModel == null)
82133
? []
@@ -132,18 +183,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
132183
padding: 5.0,
133184
mainAxisAlignment: MainAxisAlignment.center,
134185
)),
135-
new FlatButton(
136-
onPressed: () {},
137-
color: Color(GSYColors.primaryValue),
138-
child: new GSYIConText(
139-
Icons.arrow_drop_up,
140-
"master",
141-
GSYConstant.smallTextWhite,
142-
Color(GSYColors.white),
143-
30.0,
144-
padding: 3.0,
145-
mainAxisAlignment: MainAxisAlignment.center,
146-
))
186+
_renderBranchPopItem(currentBranch, branchList, (value) {}),
147187
];
148188
return bottomWidget;
149189
}
@@ -152,6 +192,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
152192
void initState() {
153193
super.initState();
154194
_refresh();
195+
_getBranchList();
155196
}
156197

157198
@override

0 commit comments

Comments
 (0)