Skip to content

Commit a3900eb

Browse files
committed
fix search
1 parent a0a27c3 commit a3900eb

8 files changed

Lines changed: 45 additions & 76 deletions

File tree

‎lib/common/net/Address.dart‎

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,10 @@ class Address {
1717
if (type == 'user') {
1818
return "${host}search/users?q=$q&page=$page&per_page=$pageSize";
1919
}
20-
if (sort == null) {
21-
sort = "best%20match";
22-
}
23-
if (order == null) {
24-
order = "desc";
25-
}
26-
if (page == null) {
27-
page = 1;
28-
}
29-
if (pageSize == null) {
30-
pageSize = Config.PAGE_SIZE;
31-
}
20+
sort ??= "best%20match";
21+
order ??= "desc";
22+
page ??= 1;
23+
pageSize ??= Config.PAGE_SIZE;
3224
return "${host}search/repositories?q=$q&sort=$sort&order=$order&page=$page&per_page=$pageSize";
3325
}
3426

@@ -39,9 +31,7 @@ class Address {
3931

4032
///用户的仓库 get
4133
static userRepos(userName, sort) {
42-
if (sort == null) {
43-
sort = 'pushed';
44-
}
34+
sort ??= 'pushed';
4535
return "${host}users/$userName/repos?sort=$sort";
4636
}
4737

@@ -82,15 +72,9 @@ class Address {
8272

8373
///仓库Issue get
8474
static getReposIssue(reposOwner, reposName, state, sort, direction) {
85-
if (state == null) {
86-
state = 'all';
87-
}
88-
if (sort == null) {
89-
sort = 'created';
90-
}
91-
if (direction == null) {
92-
direction = 'desc';
93-
}
75+
state ??= 'all';
76+
sort ??= 'created';
77+
direction ??= 'desc';
9478
return "${host}repos/$reposOwner/$reposName/issues?state=$state&sort=$sort&direction=$direction";
9579
}
9680

@@ -152,17 +136,15 @@ class Address {
152136

153137
///自己的star get
154138
static myStar(sort) {
155-
if (sort == null) {
156-
sort = 'updated';
157-
}
139+
sort ??= 'updated';
140+
158141
return "${host}users/starred?sort=$sort";
159142
}
160143

161144
///用户的star get
162145
static userStar(userName, sort) {
163-
if (sort == null) {
164-
sort = 'updated';
165-
}
146+
sort ??= 'updated';
147+
166148
return "${host}users/$userName/starred?sort=$sort";
167149
}
168150

@@ -233,9 +215,7 @@ class Address {
233215

234216
///fork get
235217
static getForker(reposOwner, reposName, sort) {
236-
if (sort == null) {
237-
sort = 'newest';
238-
}
218+
sort ??= 'newest';
239219
return "${host}repos/$reposOwner/$reposName/forks?sort=$sort";
240220
}
241221

@@ -269,12 +249,8 @@ class Address {
269249
if (all == null && participating == null) {
270250
return "${host}notifications";
271251
}
272-
if (all == null) {
273-
all = false;
274-
}
275-
if (participating == null) {
276-
participating = false;
277-
}
252+
all ??= false;
253+
participating ??= false;
278254
return "${host}notifications?all=$all&participating=$participating";
279255
}
280256

‎lib/page/SearchPage.dart‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class _SearchPageState extends GSYListState<SearchPage> {
5050
return await ReposDao.searchRepositoryDao(searchText, language, type, sort, selectIndex == 0 ? null : 'user', page, Config.PAGE_SIZE);
5151
}
5252

53+
54+
_clearSelect(List<FilterModel> list) {
55+
for (FilterModel model in list) {
56+
model.select = false;
57+
}
58+
}
59+
5360
@override
5461
bool get wantKeepAlive => true;
5562

@@ -69,6 +76,17 @@ class _SearchPageState extends GSYListState<SearchPage> {
6976
return await _getDataLogic();
7077
}
7178

79+
@override
80+
void dispose() {
81+
super.dispose();
82+
_clearSelect(sortType);
83+
sortType[0].select = true;
84+
_clearSelect(searchLanguageType);
85+
searchLanguageType[0].select = true;
86+
_clearSelect(searchFilterType);
87+
searchFilterType[0].select = true;
88+
}
89+
7290
@override
7391
Widget build(BuildContext context) {
7492
super.build(context); // See AutomaticKeepAliveClientMixin.

‎lib/widget/GSYCardItem.dart‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ class GSYCardItem extends StatelessWidget {
2020
EdgeInsets margin = this.margin;
2121
RoundedRectangleBorder shape = this.shape;
2222
Color color = this.color;
23-
if (margin == null) {
24-
margin = EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0, bottom: 10.0);
25-
}
26-
if (shape == null) {
27-
shape = new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
28-
}
29-
if (color == null) {
30-
color = new Color(GSYColors.cardWhite);
31-
}
23+
margin ??= EdgeInsets.only(left: 10.0, top: 10.0, right: 10.0, bottom: 10.0);
24+
shape ??= new RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
25+
color ??= new Color(GSYColors.cardWhite);
3226
return new Card(elevation: elevation, shape: shape, color: color, margin: margin, child: child);
3327
}
3428
}

‎lib/widget/GSYSearchDrawer.dart‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,6 @@ class _GSYSearchDrawerState extends State<GSYSearchDrawer> {
9393
);
9494
}
9595

96-
_clearSelect(List<FilterModel> list) {
97-
for (FilterModel model in list) {
98-
model.select = false;
99-
}
100-
}
101-
102-
@override
103-
void dispose() {
104-
super.dispose();
105-
_clearSelect(sortType);
106-
sortType[0].select = true;
107-
_clearSelect(searchLanguageType);
108-
searchLanguageType[0].select = true;
109-
_clearSelect(searchFilterType);
110-
searchFilterType[0].select = true;
111-
}
112-
11396
_renderItem(FilterModel model, List<FilterModel> list, int index, SearchSelectItemChanged<String> select) {
11497
return new Container(
11598
height: 50.0,
@@ -166,7 +149,7 @@ var searchLanguageType = [
166149
FilterModel(name: "Swift", value: 'Swift', select: false),
167150
FilterModel(name: "JavaScript", value: 'JavaScript', select: false),
168151
FilterModel(name: "PHP", value: 'PHP', select: false),
169-
FilterModel(name: "C__", value: 'C__', select: false),
152+
FilterModel(name: "C__", value: 'C++', select: false),
170153
FilterModel(name: "C", value: 'C', select: false),
171154
FilterModel(name: "HTML", value: 'HTML', select: false),
172155
FilterModel(name: "CSS", value: 'CSS', select: false),

‎lib/widget/HomeDrawer.dart‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import 'package:gsy_github_app_flutter/widget/GSYFlexButton.dart';
2020
*/
2121
class HomeDrawer extends StatelessWidget {
2222
showAboutDialog(BuildContext context, String versionName) {
23-
if(versionName == null) {
24-
versionName = "Null";
25-
}
23+
versionName ??= "Null";
2624
showDialog(
2725
context: context,
2826
builder: (BuildContext context) => AboutDialog(

‎lib/widget/IssueItem.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class IssueItemViewModel {
137137
issueTag = "#" + issueMap["number"].toString();
138138
number = issueMap["number"].toString();
139139
} else {
140-
issueComment = issueMap["body"] != null ? issueMap["body"] : "";
140+
issueComment = issueMap["body"] ?? "";
141141
id = issueMap["id"].toString();
142142
}
143143
}

‎lib/widget/ReposHeaderItem.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ class ReposHeaderItem extends StatelessWidget {
8585
new Padding(padding: new EdgeInsets.all(5.0)),
8686
new Row(
8787
children: <Widget>[
88-
new Text(reposHeaderViewModel.repositoryType != null ? reposHeaderViewModel.repositoryType : "--",
88+
new Text(reposHeaderViewModel.repositoryType ?? "--",
8989
style: GSYConstant.subLightSmallText),
9090
new Container(width: 5.3, height: 1.0),
91-
new Text(reposHeaderViewModel.repositorySize != null ? reposHeaderViewModel.repositorySize : "--",
91+
new Text(reposHeaderViewModel.repositorySize ?? "--",
9292
style: GSYConstant.subLightSmallText),
9393
new Container(width: 5.3, height: 1.0),
94-
new Text(reposHeaderViewModel.license != null ? reposHeaderViewModel.license : "--", style: GSYConstant.subLightSmallText),
94+
new Text(reposHeaderViewModel.license ?? "--", style: GSYConstant.subLightSmallText),
9595
],
9696
),
9797
new Padding(padding: new EdgeInsets.all(5.0)),
9898
new Container(
9999
child:
100-
new Text(reposHeaderViewModel.repositoryDes != null ? reposHeaderViewModel.repositoryDes : "---", style: GSYConstant.subLightSmallText),
100+
new Text(reposHeaderViewModel.repositoryDes ?? "---", style: GSYConstant.subLightSmallText),
101101
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
102102
alignment: Alignment.topLeft),
103103
new Container(

‎lib/widget/ReposItem.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ReposViewModel {
127127
repositoryStar = data["watchers_count"].toString();
128128
repositoryFork = data["forks_count"].toString();
129129
repositoryWatch = data["open_issues"].toString();
130-
repositoryType = data["language"] != null ? data["language"] : '---';
131-
repositoryDes = data["description"] != null ? data["description"] : '---';
130+
repositoryType = data["language"] ?? '---';
131+
repositoryDes = data["description"] ?? '---';
132132
}
133133
}

0 commit comments

Comments
 (0)