@@ -12,6 +12,7 @@ import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
1212import 'package:gsy_github_app_flutter/widget/GSYTabBarWidget.dart' ;
1313import 'package:gsy_github_app_flutter/widget/GSYTitleBar.dart' ;
1414import 'package:gsy_github_app_flutter/widget/ReposHeaderItem.dart' ;
15+ import 'package:scoped_model/scoped_model.dart' ;
1516
1617/**
1718 * 仓库详情
@@ -40,7 +41,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
4041
4142 final TarWidgetControl tarBarControl = new TarWidgetControl ();
4243
43- final ReposDetailParentControl reposDetailParentControl = new ReposDetailParentControl ( "master" );
44+ final ReposDetailModel reposDetailModel = new ReposDetailModel ( );
4445
4546 final PageController topPageControl = new PageController ();
4647
@@ -82,7 +83,6 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
8283 this ._getReposStatus ();
8384 }
8485
85-
8686 _renderBottomItem (var text, var icon, var onPressed) {
8787 return new FlatButton (
8888 onPressed: onPressed,
@@ -139,7 +139,7 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
139139 return new FlatButton (
140140 padding: EdgeInsets .all (0.0 ),
141141 onPressed: () {
142- reposDetailParentControl.currentIndex = i ;
142+ reposDetailModel. setCurrentIndex (i) ;
143143 topPageControl.jumpTo (MediaQuery .of (context).size.width * i);
144144 },
145145 child: new Text (
@@ -166,32 +166,32 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
166166 releaseUrl = GSYConstant .app_default_share_url;
167167 tagUrl = GSYConstant .app_default_share_url;
168168 } else {
169- releaseUrl = infoListKey.currentState.repository == null
170- ? GSYConstant .app_default_share_url
171- : infoListKey.currentState.repository.htmlUrl + "/releases" ;
172- tagUrl =
173- infoListKey.currentState.repository == null ? GSYConstant .app_default_share_url : infoListKey.currentState.repository.htmlUrl + "/tags" ;
169+ releaseUrl =
170+ infoListKey.currentState.repository == null ? GSYConstant .app_default_share_url : infoListKey.currentState.repository.htmlUrl + "/releases" ;
171+ tagUrl = infoListKey.currentState.repository == null ? GSYConstant .app_default_share_url : infoListKey.currentState.repository.htmlUrl + "/tags" ;
174172 }
175173 NavigatorUtils .goReleasePage (context, userName, reposName, releaseUrl, tagUrl);
176- }), ///Branch Page
174+ }),
175+
176+ ///Branch Page
177177 new GSYOptionModel (CommonUtils .getLocale (context).repos_option_branch, CommonUtils .getLocale (context).repos_option_branch, (model) {
178- if (branchList.length == 0 ) {
179- return ;
180- }
181- CommonUtils .showCommitOptionDialog (context, branchList, (value){
182- setState (() {
183- reposDetailParentControl.currentBranch = branchList[value];
184- });
185- if (infoListKey.currentState != null && infoListKey.currentState.mounted) {
186- infoListKey.currentState.showRefreshLoading ();
187- }
188- if (fileListKey.currentState != null && fileListKey.currentState.mounted) {
189- fileListKey.currentState.showRefreshLoading ();
190- }
191- if (readmeKey.currentState != null && readmeKey.currentState.mounted) {
192- readmeKey.currentState.refreshReadme ();
193- }
178+ if (branchList.length == 0 ) {
179+ return ;
180+ }
181+ CommonUtils .showCommitOptionDialog (context, branchList, (value) {
182+ setState (() {
183+ reposDetailModel.setCurrentBranch (branchList[value]);
194184 });
185+ if (infoListKey.currentState != null && infoListKey.currentState.mounted) {
186+ infoListKey.currentState.showRefreshLoading ();
187+ }
188+ if (fileListKey.currentState != null && fileListKey.currentState.mounted) {
189+ fileListKey.currentState.showRefreshLoading ();
190+ }
191+ if (readmeKey.currentState != null && readmeKey.currentState.mounted) {
192+ readmeKey.currentState.refreshReadme ();
193+ }
194+ });
195195 }),
196196 ];
197197 }
@@ -206,26 +206,33 @@ class _RepositoryDetailPageState extends State<RepositoryDetailPage> {
206206 @override
207207 Widget build (BuildContext context) {
208208 Widget widget = new GSYCommonOptionWidget (titleOptionControl, otherList: _getMoreOtherItem ());
209- return new GSYTabBarWidget (
210- type: GSYTabBarWidget .TOP_TAB ,
211- tarWidgetControl: tarBarControl,
212- tabItems: _renderTabItem (),
213- tabViews: [
214- new ReposDetailInfoPage (userName, reposName, reposDetailParentControl, titleOptionControl, key: infoListKey),
215- new RepositoryDetailReadmePage (userName, reposName, reposDetailParentControl, key: readmeKey),
216- new RepositoryDetailIssuePage (userName, reposName),
217- new RepositoryDetailFileListPage (userName, reposName, reposDetailParentControl, key: fileListKey),
218- ],
219- topPageControl: topPageControl,
220- backgroundColor: GSYColors .primarySwatch,
221- indicatorColor: Color (GSYColors .white),
222- title: new GSYTitleBar (
223- reposName,
224- rightWidget: widget,
209+ return new ScopedModel <ReposDetailModel >(
210+ model: reposDetailModel,
211+ child: new ScopedModelDescendant <ReposDetailModel >(
212+ builder: (context, child, model) {
213+ return new GSYTabBarWidget (
214+ type: GSYTabBarWidget .TOP_TAB ,
215+ tarWidgetControl: tarBarControl,
216+ tabItems: _renderTabItem (),
217+ tabViews: [
218+ new ReposDetailInfoPage (userName, reposName, titleOptionControl, key: infoListKey),
219+ new RepositoryDetailReadmePage (userName, reposName, key: readmeKey),
220+ new RepositoryDetailIssuePage (userName, reposName),
221+ new RepositoryDetailFileListPage (userName, reposName, key: fileListKey),
222+ ],
223+ topPageControl: topPageControl,
224+ backgroundColor: GSYColors .primarySwatch,
225+ indicatorColor: Color (GSYColors .white),
226+ title: new GSYTitleBar (
227+ reposName,
228+ rightWidget: widget,
229+ ),
230+ onPageChanged: (index) {
231+ reposDetailModel.setCurrentIndex (index);
232+ },
233+ );
234+ },
225235 ),
226- onPageChanged: (index) {
227- reposDetailParentControl.currentIndex = index;
228- },
229236 );
230237 }
231238}
@@ -241,10 +248,26 @@ class BottomStatusModel {
241248 BottomStatusModel (this .watchText, this .starText, this .watchIcon, this .starIcon, this .watch, this .star);
242249}
243250
244- class ReposDetailParentControl {
245- int currentIndex = 0 ;
251+ class ReposDetailModel extends Model {
252+ int _currentIndex = 0 ;
253+
254+ String _currentBranch = "master" ;
255+
256+ String get currentBranch => _currentBranch;
257+
258+ int get currentIndex => _currentIndex;
246259
247- String currentBranch ;
260+ static ReposDetailModel of ( BuildContext context) => ScopedModel . of < ReposDetailModel >(context) ;
248261
249- ReposDetailParentControl (this .currentBranch);
262+ void setCurrentBranch (String branch) {
263+ _currentBranch = branch;
264+ notifyListeners ();
265+ }
266+
267+ void setCurrentIndex (int index) {
268+ _currentIndex = index;
269+ print ("----" );
270+ print (_currentIndex);
271+ notifyListeners ();
272+ }
250273}
0 commit comments