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
fe0b9093
Commit
fe0b9093
authored
Feb 11, 2017
by
Adam Barth
Committed by
GitHub
Feb 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove more clients of LazyBlock (#8071)
The last remaining client is complex_layout.
parent
073843f2
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
161 deletions
+98
-161
card_collection.dart
dev/manual_tests/card_collection.dart
+55
-123
overlay_geometry.dart
dev/manual_tests/overlay_geometry.dart
+43
-38
No files found.
dev/manual_tests/card_collection.dart
View file @
fe0b9093
This diff is collapsed.
Click to expand it.
dev/manual_tests/overlay_geometry.dart
View file @
fe0b9093
...
@@ -8,10 +8,12 @@ import 'package:flutter/rendering.dart';
...
@@ -8,10 +8,12 @@ import 'package:flutter/rendering.dart';
class
CardModel
{
class
CardModel
{
CardModel
(
this
.
value
,
this
.
height
,
this
.
color
);
CardModel
(
this
.
value
,
this
.
height
,
this
.
color
);
int
value
;
int
value
;
double
height
;
double
height
;
Color
color
;
Color
color
;
String
get
label
=>
"Card
$value
"
;
String
get
label
=>
'Card
$value
'
;
Key
get
key
=>
new
ObjectKey
(
this
);
Key
get
key
=>
new
ObjectKey
(
this
);
GlobalKey
get
targetKey
=>
new
GlobalObjectKey
(
this
);
GlobalKey
get
targetKey
=>
new
GlobalObjectKey
(
this
);
}
}
...
@@ -21,7 +23,7 @@ enum MarkerType { topLeft, bottomRight, touch }
...
@@ -21,7 +23,7 @@ enum MarkerType { topLeft, bottomRight, touch }
class
_MarkerPainter
extends
CustomPainter
{
class
_MarkerPainter
extends
CustomPainter
{
const
_MarkerPainter
({
const
_MarkerPainter
({
this
.
size
,
this
.
size
,
this
.
type
this
.
type
,
});
});
final
double
size
;
final
double
size
;
...
@@ -56,10 +58,10 @@ class _MarkerPainter extends CustomPainter {
...
@@ -56,10 +58,10 @@ class _MarkerPainter extends CustomPainter {
class
Marker
extends
StatelessWidget
{
class
Marker
extends
StatelessWidget
{
Marker
({
Marker
({
Key
key
,
this
.
type
:
MarkerType
.
touch
,
this
.
type
:
MarkerType
.
touch
,
this
.
position
,
this
.
position
,
this
.
size
:
40.0
,
this
.
size
:
40.0
,
Key
key
})
:
super
(
key:
key
);
})
:
super
(
key:
key
);
final
Point
position
;
final
Point
position
;
...
@@ -77,10 +79,10 @@ class Marker extends StatelessWidget {
...
@@ -77,10 +79,10 @@ class Marker extends StatelessWidget {
child:
new
CustomPaint
(
child:
new
CustomPaint
(
painter:
new
_MarkerPainter
(
painter:
new
_MarkerPainter
(
size:
size
,
size:
size
,
type:
type
type:
type
,
)
)
,
)
)
,
)
)
,
);
);
}
}
}
}
...
@@ -92,7 +94,7 @@ class OverlayGeometryApp extends StatefulWidget {
...
@@ -92,7 +94,7 @@ class OverlayGeometryApp extends StatefulWidget {
typedef
void
CardTapCallback
(
GlobalKey
targetKey
,
Point
globalPosition
);
typedef
void
CardTapCallback
(
GlobalKey
targetKey
,
Point
globalPosition
);
class
CardBuilder
extends
LazyBlock
Delegate
{
class
CardBuilder
extends
SliverChild
Delegate
{
CardBuilder
({
this
.
cardModels
,
this
.
onTapUp
});
CardBuilder
({
this
.
cardModels
,
this
.
onTapUp
});
final
List
<
CardModel
>
cardModels
;
final
List
<
CardModel
>
cardModels
;
...
@@ -102,7 +104,7 @@ class CardBuilder extends LazyBlockDelegate {
...
@@ -102,7 +104,7 @@ class CardBuilder extends LazyBlockDelegate {
const
TextStyle
(
color:
Colors
.
white
,
fontSize:
18.0
,
fontWeight:
FontWeight
.
bold
);
const
TextStyle
(
color:
Colors
.
white
,
fontSize:
18.0
,
fontWeight:
FontWeight
.
bold
);
@override
@override
Widget
build
Item
(
BuildContext
context
,
int
index
)
{
Widget
build
(
BuildContext
context
,
int
index
)
{
if
(
index
>=
cardModels
.
length
)
if
(
index
>=
cardModels
.
length
)
return
null
;
return
null
;
CardModel
cardModel
=
cardModels
[
index
];
CardModel
cardModel
=
cardModels
[
index
];
...
@@ -115,20 +117,18 @@ class CardBuilder extends LazyBlockDelegate {
...
@@ -115,20 +117,18 @@ class CardBuilder extends LazyBlockDelegate {
child:
new
Container
(
child:
new
Container
(
height:
cardModel
.
height
,
height:
cardModel
.
height
,
padding:
const
EdgeInsets
.
all
(
8.0
),
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
new
Center
(
child:
new
Text
(
cardModel
.
label
,
style:
cardLabelStyle
))
child:
new
Center
(
child:
new
Text
(
cardModel
.
label
,
style:
cardLabelStyle
))
,
)
)
,
)
)
,
);
);
}
}
@override
@override
bool
shouldRebuild
(
CardBuilder
oldDelegate
)
{
int
get
estimatedChildCount
=>
cardModels
.
length
;
return
oldDelegate
.
cardModels
!=
cardModels
;
}
@override
@override
double
estimateTotalExtent
(
int
firstIndex
,
int
lastIndex
,
double
minOffset
,
double
firstStartOffset
,
double
lastEndOffset
)
{
bool
shouldRebuild
(
CardBuilder
oldDelegate
)
{
return
(
lastEndOffset
-
minOffset
)
*
cardModels
.
length
/
(
lastIndex
+
1
)
;
return
oldDelegate
.
cardModels
!=
cardModels
;
}
}
}
}
...
@@ -144,7 +144,7 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
...
@@ -144,7 +144,7 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
List
<
double
>
cardHeights
=
<
double
>[
List
<
double
>
cardHeights
=
<
double
>[
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
,
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
,
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
,
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
,
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
48.0
,
63.0
,
82.0
,
146.0
,
60.0
,
55.0
,
84.0
,
96.0
,
50.0
,
];
];
cardModels
=
new
List
<
CardModel
>.
generate
(
cardHeights
.
length
,
(
int
i
)
{
cardModels
=
new
List
<
CardModel
>.
generate
(
cardHeights
.
length
,
(
int
i
)
{
Color
color
=
Color
.
lerp
(
Colors
.
red
[
300
],
Colors
.
blue
[
900
],
i
/
cardHeights
.
length
);
Color
color
=
Color
.
lerp
(
Colors
.
red
[
300
],
Colors
.
blue
[
900
],
i
/
cardHeights
.
length
);
...
@@ -152,15 +152,18 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
...
@@ -152,15 +152,18 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
});
});
}
}
void
handleScroll
(
double
offset
)
{
bool
handleScrollNotification
(
ScrollNotification2
notification
)
{
setState
(()
{
if
(
notification
is
ScrollUpdateNotification
&&
notification
.
depth
==
1
)
{
double
dy
=
markersScrollOffset
-
offset
;
setState
(()
{
markersScrollOffset
=
offset
;
double
dy
=
markersScrollOffset
-
notification
.
metrics
.
extentBefore
;
for
(
MarkerType
type
in
markers
.
keys
)
{
markersScrollOffset
=
notification
.
metrics
.
extentBefore
;
Point
oldPosition
=
markers
[
type
];
for
(
MarkerType
type
in
markers
.
keys
)
{
markers
[
type
]
=
new
Point
(
oldPosition
.
x
,
oldPosition
.
y
+
dy
);
Point
oldPosition
=
markers
[
type
];
}
markers
[
type
]
=
new
Point
(
oldPosition
.
x
,
oldPosition
.
y
+
dy
);
});
}
});
}
return
false
;
}
}
void
handleTapUp
(
GlobalKey
target
,
Point
globalPosition
)
{
void
handleTapUp
(
GlobalKey
target
,
Point
globalPosition
)
{
...
@@ -182,15 +185,17 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
...
@@ -182,15 +185,17 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
appBar:
new
AppBar
(
title:
new
Text
(
'Tap a Card'
)),
appBar:
new
AppBar
(
title:
new
Text
(
'Tap a Card'
)),
body:
new
Container
(
body:
new
Container
(
padding:
const
EdgeInsets
.
symmetric
(
vertical:
12.0
,
horizontal:
8.0
),
padding:
const
EdgeInsets
.
symmetric
(
vertical:
12.0
,
horizontal:
8.0
),
child:
new
LazyBlock
(
child:
new
NotificationListener
<
ScrollNotification2
>(
onScroll:
handleScroll
,
onNotification:
handleScrollNotification
,
delegate:
new
CardBuilder
(
child:
new
ListView
.
custom
(
cardModels:
cardModels
,
childrenDelegate:
new
CardBuilder
(
onTapUp:
handleTapUp
cardModels:
cardModels
,
)
onTapUp:
handleTapUp
,
)
),
)
),
)
),
),
),
];
];
for
(
MarkerType
type
in
markers
.
keys
)
for
(
MarkerType
type
in
markers
.
keys
)
layers
.
add
(
new
Marker
(
type:
type
,
position:
markers
[
type
]));
layers
.
add
(
new
Marker
(
type:
type
,
position:
markers
[
type
]));
...
@@ -203,9 +208,9 @@ void main() {
...
@@ -203,9 +208,9 @@ void main() {
theme:
new
ThemeData
(
theme:
new
ThemeData
(
brightness:
Brightness
.
light
,
brightness:
Brightness
.
light
,
primarySwatch:
Colors
.
blue
,
primarySwatch:
Colors
.
blue
,
accentColor:
Colors
.
redAccent
[
200
]
accentColor:
Colors
.
redAccent
[
200
]
,
),
),
title:
'Cards'
,
title:
'Cards'
,
home:
new
OverlayGeometryApp
()
home:
new
OverlayGeometryApp
()
,
));
));
}
}
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