11import 'package:flutter/material.dart' ;
22import 'package:gsy_github_app_flutter/common/dao/repos_dao.dart' ;
3+ import 'package:gsy_github_app_flutter/common/model/Repository.dart' ;
34import 'package:gsy_github_app_flutter/common/style/gsy_style.dart' ;
45import 'package:gsy_github_app_flutter/common/utils/common_utils.dart' ;
56import 'package:gsy_github_app_flutter/common/utils/navigator_utils.dart' ;
@@ -41,30 +42,39 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4142
4243 final OptionControl titleOptionControl = new OptionControl ();
4344
44- GlobalKey <RepositoryDetailFileListPageState > fileListKey = new GlobalKey <RepositoryDetailFileListPageState >();
45+ GlobalKey <RepositoryDetailFileListPageState > fileListKey =
46+ new GlobalKey <RepositoryDetailFileListPageState >();
4547
46- GlobalKey <ReposDetailInfoPageState > infoListKey = new GlobalKey <ReposDetailInfoPageState >();
48+ GlobalKey <ReposDetailInfoPageState > infoListKey =
49+ new GlobalKey <ReposDetailInfoPageState >();
4750
48- GlobalKey <RepositoryDetailReadmePageState > readmeKey = new GlobalKey <RepositoryDetailReadmePageState >();
51+ GlobalKey <RepositoryDetailReadmePageState > readmeKey =
52+ new GlobalKey <RepositoryDetailReadmePageState >();
4953
5054 List <String > branchList = new List ();
5155
52-
5356 _getReposStatus () async {
54- var result = await ReposDao .getRepositoryStatusDao (widget.userName, widget.reposName);
57+ var result = await ReposDao .getRepositoryStatusDao (
58+ widget.userName, widget.reposName);
5559 String watchText = result.data["watch" ] ? "UnWatch" : "Watch" ;
5660 String starText = result.data["star" ] ? "UnStar" : "Star" ;
57- IconData watchIcon = result.data["watch" ] ? GSYICons .REPOS_ITEM_WATCHED : GSYICons .REPOS_ITEM_WATCH ;
58- IconData starIcon = result.data["star" ] ? GSYICons .REPOS_ITEM_STARED : GSYICons .REPOS_ITEM_STAR ;
59- BottomStatusModel model = new BottomStatusModel (watchText, starText, watchIcon, starIcon, result.data["watch" ], result.data["star" ]);
61+ IconData watchIcon = result.data["watch" ]
62+ ? GSYICons .REPOS_ITEM_WATCHED
63+ : GSYICons .REPOS_ITEM_WATCH ;
64+ IconData starIcon = result.data["star" ]
65+ ? GSYICons .REPOS_ITEM_STARED
66+ : GSYICons .REPOS_ITEM_STAR ;
67+ BottomStatusModel model = new BottomStatusModel (watchText, starText,
68+ watchIcon, starIcon, result.data["watch" ], result.data["star" ]);
6069 setState (() {
6170 bottomStatusModel = model;
6271 tarBarControl.footerButton = _getBottomWidget ();
6372 });
6473 }
6574
6675 _getBranchList () async {
67- var result = await ReposDao .getBranchesDao (widget.userName, widget.reposName);
76+ var result =
77+ await ReposDao .getBranchesDao (widget.userName, widget.reposName);
6878 if (result != null && result.result) {
6979 setState (() {
7080 branchList = result.data;
@@ -94,23 +104,30 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
94104 List <Widget > bottomWidget = (bottomStatusModel == null )
95105 ? []
96106 : < Widget > [
97- _renderBottomItem (bottomStatusModel.starText, bottomStatusModel.starIcon, () {
107+ _renderBottomItem (
108+ bottomStatusModel.starText, bottomStatusModel.starIcon, () {
98109 CommonUtils .showLoadingDialog (context);
99- return ReposDao .doRepositoryStarDao (widget.userName, widget.reposName, bottomStatusModel.star).then ((result) {
110+ return ReposDao .doRepositoryStarDao (
111+ widget.userName, widget.reposName, bottomStatusModel.star)
112+ .then ((result) {
100113 _refresh ();
101114 Navigator .pop (context);
102115 });
103116 }),
104- _renderBottomItem (bottomStatusModel.watchText, bottomStatusModel.watchIcon, () {
117+ _renderBottomItem (
118+ bottomStatusModel.watchText, bottomStatusModel.watchIcon, () {
105119 CommonUtils .showLoadingDialog (context);
106- return ReposDao .doRepositoryWatchDao (widget.userName, widget.reposName, bottomStatusModel.watch).then ((result) {
120+ return ReposDao .doRepositoryWatchDao (widget.userName,
121+ widget.reposName, bottomStatusModel.watch)
122+ .then ((result) {
107123 _refresh ();
108124 Navigator .pop (context);
109125 });
110126 }),
111127 _renderBottomItem ("fork" , GSYICons .REPOS_ITEM_FORK , () {
112128 CommonUtils .showLoadingDialog (context);
113- return ReposDao .createForkDao (widget.userName, widget.reposName).then ((result) {
129+ return ReposDao .createForkDao (widget.userName, widget.reposName)
130+ .then ((result) {
114131 _refresh ();
115132 Navigator .pop (context);
116133 });
@@ -145,39 +162,48 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
145162 return list;
146163 }
147164
148- _getMoreOtherItem () {
165+ _getMoreOtherItem (Repository repository ) {
149166 return [
150167 ///Release Page
151- new GSYOptionModel (CommonUtils .getLocale (context).repos_option_release, CommonUtils .getLocale (context).repos_option_release, (model) {
168+ new GSYOptionModel (CommonUtils .getLocale (context).repos_option_release,
169+ CommonUtils .getLocale (context).repos_option_release, (model) {
152170 String releaseUrl = "" ;
153171 String tagUrl = "" ;
154172 if (infoListKey == null || infoListKey.currentState == null ) {
155173 releaseUrl = GSYConstant .app_default_share_url;
156174 tagUrl = GSYConstant .app_default_share_url;
157175 } else {
158- releaseUrl =
159- infoListKey.currentState.repository == null ? GSYConstant .app_default_share_url : infoListKey.currentState.repository.htmlUrl + "/releases" ;
160- tagUrl = infoListKey.currentState.repository == null ? GSYConstant .app_default_share_url : infoListKey.currentState.repository.htmlUrl + "/tags" ;
176+ releaseUrl = repository == null
177+ ? GSYConstant .app_default_share_url
178+ : repository.htmlUrl + "/releases" ;
179+ tagUrl = repository == null
180+ ? GSYConstant .app_default_share_url
181+ : repository.htmlUrl + "/tags" ;
161182 }
162- NavigatorUtils .goReleasePage (context, widget.userName, widget.reposName, releaseUrl, tagUrl);
183+ NavigatorUtils .goReleasePage (
184+ context, widget.userName, widget.reposName, releaseUrl, tagUrl);
163185 }),
164186
165187 ///Branch Page
166- new GSYOptionModel (CommonUtils .getLocale (context).repos_option_branch, CommonUtils .getLocale (context).repos_option_branch, (model) {
188+ new GSYOptionModel (CommonUtils .getLocale (context).repos_option_branch,
189+ CommonUtils .getLocale (context).repos_option_branch, (model) {
167190 if (branchList.length == 0 ) {
168191 return ;
169192 }
170193 CommonUtils .showCommitOptionDialog (context, branchList, (value) {
171194 setState (() {
172195 reposDetailModel.setCurrentBranch (branchList[value]);
173196 });
174- if (infoListKey.currentState != null && infoListKey.currentState.mounted) {
197+ if (infoListKey.currentState != null &&
198+ infoListKey.currentState.mounted) {
175199 infoListKey.currentState.showRefreshLoading ();
176200 }
177- if (fileListKey.currentState != null && fileListKey.currentState.mounted) {
201+ if (fileListKey.currentState != null &&
202+ fileListKey.currentState.mounted) {
178203 fileListKey.currentState.showRefreshLoading ();
179204 }
180- if (readmeKey.currentState != null && readmeKey.currentState.mounted) {
205+ if (readmeKey.currentState != null &&
206+ readmeKey.currentState.mounted) {
181207 readmeKey.currentState.refreshReadme ();
182208 }
183209 });
@@ -194,20 +220,26 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
194220
195221 @override
196222 Widget build (BuildContext context) {
197- Widget widgetContent = new GSYCommonOptionWidget (titleOptionControl, otherList: _getMoreOtherItem ());
198223 return new ScopedModel <ReposDetailModel >(
199224 model: reposDetailModel,
200225 child: new ScopedModelDescendant <ReposDetailModel >(
201226 builder: (context, child, model) {
227+ Widget widgetContent = new GSYCommonOptionWidget (titleOptionControl,
228+ otherList: _getMoreOtherItem (model.repository));
202229 return new GSYTabBarWidget (
203230 type: GSYTabBarWidget .TOP_TAB ,
204231 tarWidgetControl: tarBarControl,
205232 tabItems: _renderTabItem (),
206233 tabViews: [
207- new ReposDetailInfoPage (widget.userName, widget.reposName, titleOptionControl, key: infoListKey),
208- new RepositoryDetailReadmePage (widget.userName, widget.reposName, key: readmeKey),
234+ new ReposDetailInfoPage (
235+ widget.userName, widget.reposName, titleOptionControl,
236+ key: infoListKey),
237+ new RepositoryDetailReadmePage (widget.userName, widget.reposName,
238+ key: readmeKey),
209239 new RepositoryDetailIssuePage (widget.userName, widget.reposName),
210- new RepositoryDetailFileListPage (widget.userName, widget.reposName, key: fileListKey),
240+ new RepositoryDetailFileListPage (
241+ widget.userName, widget.reposName,
242+ key: fileListKey),
211243 ],
212244 backgroundColor: GSYColors .primarySwatch,
213245 indicatorColor: Color (GSYColors .white),
@@ -233,19 +265,30 @@ class BottomStatusModel {
233265 final bool star;
234266 final bool watch;
235267
236- BottomStatusModel (this .watchText, this .starText, this .watchIcon, this .starIcon, this .watch, this .star);
268+ BottomStatusModel (this .watchText, this .starText, this .watchIcon,
269+ this .starIcon, this .watch, this .star);
237270}
238271
239272class ReposDetailModel extends Model {
273+ static ReposDetailModel of (BuildContext context) =>
274+ ScopedModel .of <ReposDetailModel >(context);
275+
240276 int _currentIndex = 0 ;
241277
278+ int get currentIndex => _currentIndex;
279+
242280 String _currentBranch = "master" ;
243281
244282 String get currentBranch => _currentBranch;
245283
246- int get currentIndex => _currentIndex;
284+ Repository _repository = Repository .empty ();
285+
286+ Repository get repository => _repository;
247287
248- static ReposDetailModel of (BuildContext context) => ScopedModel .of <ReposDetailModel >(context);
288+ set repository (Repository data) {
289+ _repository = data;
290+ notifyListeners ();
291+ }
249292
250293 void setCurrentBranch (String branch) {
251294 _currentBranch = branch;
0 commit comments