Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
51d06647
Commit
51d06647
authored
Jan 07, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1122 from abarth/fix_tabs
Tabs don't display items other than 0 and 1
parents
1cee346a
5e2badad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
13 deletions
+25
-13
tabs.dart
packages/flutter/lib/src/material/tabs.dart
+25
-13
No files found.
packages/flutter/lib/src/material/tabs.dart
View file @
51d06647
...
...
@@ -782,7 +782,7 @@ class TabBarView<T> extends PageableList {
})
:
items
=
items
,
itemBuilder
=
itemBuilder
,
super
(
key:
key
,
scrollDirection:
ScrollDirection
.
horizontal
,
children:
items
.
map
((
T
item
)
=>
itemBuilder
(
item
)),
children:
items
.
map
((
T
item
)
=>
itemBuilder
(
item
))
.
toList
()
,
itemsWrap:
false
)
{
assert
(
items
!=
null
);
...
...
@@ -798,7 +798,7 @@ class TabBarView<T> extends PageableList {
class
_TabBarViewState
<
T
>
extends
PageableListState
<
TabBarView
<
T
>>
implements
TabBarSelectionPerformanceListener
{
TabBarSelectionState
_selection
;
List
<
int
>
_itemIndices
=
[
0
,
1
]
;
List
<
Widget
>
_items
;
AnimationDirection
_scrollDirection
=
AnimationDirection
.
forward
;
int
get
_tabCount
=>
config
.
items
.
length
;
...
...
@@ -810,7 +810,6 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
return
_boundedBehavior
;
}
void
_initSelection
(
TabBarSelectionState
<
T
>
selection
)
{
_selection
=
selection
;
if
(
_selection
!=
null
)
{
...
...
@@ -833,17 +832,24 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
_selection
=
null
;
}
void
_updateItems
(
int
first
,
int
second
,
[
int
third
])
{
List
<
Widget
>
widgets
=
config
.
children
;
_items
=
<
Widget
>[
widgets
[
first
],
widgets
[
second
]];
if
(
third
!=
null
)
_items
.
add
(
widgets
[
third
]);
}
void
_initItemIndicesAndScrollPosition
()
{
assert
(
_selection
!=
null
);
final
int
selectedIndex
=
_selection
.
index
;
if
(
selectedIndex
==
0
)
{
_
itemIndices
=
<
int
>[
0
,
1
]
;
_
updateItems
(
0
,
1
)
;
scrollTo
(
0.0
);
}
else
if
(
selectedIndex
==
_tabCount
-
1
)
{
_
itemIndices
=
<
int
>[
selectedIndex
-
1
,
selectedIndex
]
;
_
updateItems
(
selectedIndex
-
1
,
selectedIndex
)
;
scrollTo
(
1.0
);
}
else
{
_
itemIndices
=
<
int
>[
selectedIndex
-
1
,
selectedIndex
,
selectedIndex
+
1
]
;
_
updateItems
(
selectedIndex
-
1
,
selectedIndex
,
selectedIndex
+
1
)
;
scrollTo
(
1.0
);
}
}
...
...
@@ -870,10 +876,10 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
final
int
previousSelectedIndex
=
_selection
.
previousIndex
;
if
(
selectedIndex
<
previousSelectedIndex
)
{
_
itemIndices
=
<
int
>[
selectedIndex
,
previousSelectedIndex
]
;
_
updateItems
(
selectedIndex
,
previousSelectedIndex
)
;
_scrollDirection
=
AnimationDirection
.
reverse
;
}
else
{
_
itemIndices
=
<
int
>[
previousSelectedIndex
,
selectedIndex
]
;
_
updateItems
(
previousSelectedIndex
,
selectedIndex
)
;
_scrollDirection
=
AnimationDirection
.
forward
;
}
...
...
@@ -883,8 +889,6 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
scrollTo
(
1.0
-
performance
.
progress
);
}
int
get
itemCount
=>
_itemIndices
.
length
;
void
dispatchOnScroll
()
{
if
(
_selection
==
null
||
_selection
.
valueIsChanging
)
return
;
...
...
@@ -904,14 +908,16 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
if
(
scrollVelocity
.
dx
.
abs
()
>
_kMinFlingVelocity
)
{
final
int
selectionDelta
=
scrollVelocity
.
dx
>
0
?
-
1
:
1
;
_selection
.
value
=
_selection
.
values
[(
_selection
.
index
+
selectionDelta
).
clamp
(
0
,
_tabCount
-
1
)];
final
int
targetIndex
=
(
_selection
.
index
+
selectionDelta
).
clamp
(
0
,
_tabCount
-
1
);
_selection
.
value
=
_selection
.
values
[
targetIndex
];
return
new
Future
.
value
();
}
final
int
selectionIndex
=
_selection
.
index
;
final
int
settleIndex
=
snapScrollOffset
(
scrollOffset
).
toInt
();
if
(
selectionIndex
>
0
&&
settleIndex
!=
1
)
{
_selection
.
value
=
_selection
.
values
[
selectionIndex
+
(
settleIndex
==
2
?
1
:
-
1
)];
final
int
targetIndex
=
(
selectionIndex
+
(
settleIndex
==
2
?
1
:
-
1
)).
clamp
(
0
,
_tabCount
-
1
);
_selection
.
value
=
_selection
.
values
[
targetIndex
];
return
new
Future
.
value
();
}
else
if
(
selectionIndex
==
0
&&
settleIndex
==
1
)
{
_selection
.
value
=
_selection
.
values
[
1
];
...
...
@@ -924,6 +930,12 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
TabBarSelectionState
<
T
>
newSelection
=
TabBarSelection
.
of
(
context
);
if
(
_selection
!=
newSelection
)
_initSelection
(
newSelection
);
return
super
.
buildContent
(
context
);
return
new
PageViewport
(
itemsWrap:
config
.
itemsWrap
,
scrollDirection:
config
.
scrollDirection
,
startOffset:
scrollOffset
,
overlayPainter:
config
.
scrollableListPainter
,
children:
_items
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment