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
6fcdb64a
Commit
6fcdb64a
authored
Oct 02, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1455 from Hixie/heroes2
Groundwork for heroes transition in Stocks app
parents
6baf162a
7734c0b0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
35 deletions
+67
-35
stock_home.dart
examples/stocks/lib/stock_home.dart
+2
-2
stock_list.dart
examples/stocks/lib/stock_list.dart
+5
-7
stock_row.dart
examples/stocks/lib/stock_row.dart
+60
-26
No files found.
examples/stocks/lib/stock_home.dart
View file @
6fcdb64a
...
...
@@ -186,13 +186,13 @@ class StockHomeState extends State<StockHome> {
Widget
buildStockList
(
BuildContext
context
,
Iterable
<
Stock
>
stocks
)
{
return
new
StockList
(
stocks:
stocks
.
toList
(),
onAction:
(
Stock
stock
)
{
onAction:
(
Stock
stock
,
GlobalKey
row
,
GlobalKey
arrowKey
,
GlobalKey
symbolKey
,
GlobalKey
priceKey
)
{
setState
(()
{
stock
.
percentChange
=
100.0
*
(
1.0
/
stock
.
lastSale
);
stock
.
lastSale
+=
1.0
;
});
},
onOpen:
(
Stock
stock
)
{
onOpen:
(
Stock
stock
,
GlobalKey
row
,
GlobalKey
arrowKey
,
GlobalKey
symbolKey
,
GlobalKey
priceKey
)
{
config
.
navigator
.
pushNamed
(
'/stock/
${stock.symbol}
'
);
}
);
...
...
examples/stocks/lib/stock_list.dart
View file @
6fcdb64a
...
...
@@ -4,14 +4,12 @@
part of
stocks
;
typedef
void
StockActionListener
(
Stock
stock
);
class
StockList
extends
StatelessComponent
{
StockList
({
Key
key
,
this
.
stocks
,
this
.
on
Action
,
this
.
onOpe
n
})
:
super
(
key:
key
);
StockList
({
Key
key
,
this
.
stocks
,
this
.
on
Open
,
this
.
onActio
n
})
:
super
(
key:
key
);
final
List
<
Stock
>
stocks
;
final
Stock
ActionListener
onActio
n
;
final
Stock
ActionListener
onOpe
n
;
final
Stock
RowActionCallback
onOpe
n
;
final
Stock
RowActionCallback
onActio
n
;
Widget
build
(
BuildContext
context
)
{
return
new
Material
(
...
...
@@ -22,8 +20,8 @@ class StockList extends StatelessComponent {
itemBuilder:
(
BuildContext
context
,
Stock
stock
)
{
return
new
StockRow
(
stock:
stock
,
onPressed:
()
{
onAction
(
stock
);
}
,
onLongPressed:
()
{
onOpen
(
stock
);
}
onPressed:
onOpen
,
onLongPressed:
onAction
);
}
)
...
...
examples/stocks/lib/stock_row.dart
View file @
6fcdb64a
...
...
@@ -4,47 +4,60 @@
part of
stocks
;
enum
StockRowPartKind
{
arrow
,
symbol
,
price
}
class
StockRowPartGlobalKey
extends
GlobalKey
{
const
StockRowPartGlobalKey
(
this
.
stock
,
this
.
part
)
:
super
.
constructor
();
final
Stock
stock
;
final
StockRowPartKind
part
;
String
toString
()
=>
'[StockRowPartGlobalKey
${stock.symbol}
:
${part.toString().split(".")[1]}
)]'
;
bool
operator
==(
other
)
=>
other
is
StockRowPartGlobalKey
&&
identical
(
other
.
stock
,
stock
)
&&
identical
(
other
.
part
,
part
);
int
get
hashCode
=>
37
*
(
37
*
(
373
)
+
identityHashCode
(
stock
))
+
identityHashCode
(
part
);
}
typedef
void
StockRowActionCallback
(
Stock
stock
,
GlobalKey
row
,
GlobalKey
arrowKey
,
GlobalKey
symbolKey
,
GlobalKey
priceKey
);
class
StockRow
extends
StatelessComponent
{
StockRow
({
Stock
stock
,
this
.
onPressed
,
this
.
onLongPressed
})
:
this
.
stock
=
stock
,
super
(
key:
new
Key
(
stock
.
symbol
));
})
:
this
.
stock
=
stock
,
arrowKey
=
new
StockRowPartGlobalKey
(
stock
,
StockRowPartKind
.
arrow
),
symbolKey
=
new
StockRowPartGlobalKey
(
stock
,
StockRowPartKind
.
symbol
),
priceKey
=
new
StockRowPartGlobalKey
(
stock
,
StockRowPartKind
.
price
),
super
(
key:
new
GlobalObjectKey
(
stock
));
final
Stock
stock
;
final
GestureTapListener
onPressed
;
final
GestureLongPressListener
onLongPressed
;
final
StockRowActionCallback
onPressed
;
final
StockRowActionCallback
onLongPressed
;
final
GlobalKey
arrowKey
;
final
GlobalKey
symbolKey
;
final
GlobalKey
priceKey
;
static
const
double
kHeight
=
79.0
;
GestureTapListener
_getTapHandler
(
StockRowActionCallback
callback
)
{
if
(
callback
==
null
)
return
null
;
return
()
=>
callback
(
stock
,
key
,
arrowKey
,
symbolKey
,
priceKey
);
}
GestureLongPressListener
_getLongPressHandler
(
StockRowActionCallback
callback
)
{
if
(
callback
==
null
)
return
null
;
return
()
=>
callback
(
stock
,
key
,
arrowKey
,
symbolKey
,
priceKey
);
}
Widget
build
(
BuildContext
context
)
{
String
lastSale
=
"
\$
${stock.lastSale.toStringAsFixed(2)}
"
;
String
changeInPrice
=
"
${stock.percentChange.toStringAsFixed(2)}
%"
;
if
(
stock
.
percentChange
>
0
)
changeInPrice
=
"+"
+
changeInPrice
;
List
<
Widget
>
children
=
[
new
Flexible
(
child:
new
Text
(
stock
.
symbol
),
flex:
2
),
new
Flexible
(
child:
new
Text
(
lastSale
,
style:
const
TextStyle
(
textAlign:
TextAlign
.
right
)
)
),
new
Flexible
(
child:
new
Text
(
changeInPrice
,
style:
Theme
.
of
(
context
).
text
.
caption
.
copyWith
(
textAlign:
TextAlign
.
right
)
)
)
];
return
new
GestureDetector
(
onTap:
onPressed
,
onLongPress:
onLongPressed
,
onTap:
_getTapHandler
(
onPressed
)
,
onLongPress:
_getLongPressHandler
(
onLongPressed
)
,
child:
new
InkWell
(
child:
new
Container
(
padding:
const
EdgeDims
.
TRBL
(
16.0
,
16.0
,
20.0
,
16.0
),
...
...
@@ -55,12 +68,33 @@ class StockRow extends StatelessComponent {
),
child:
new
Row
([
new
Container
(
key:
arrowKey
,
child:
new
StockArrow
(
percentChange:
stock
.
percentChange
),
margin:
const
EdgeDims
.
only
(
right:
5.0
)
),
new
Flexible
(
child:
new
Row
(
children
,
child:
new
Row
([
new
Flexible
(
flex:
2
,
child:
new
Text
(
stock
.
symbol
,
key:
symbolKey
)
),
new
Flexible
(
child:
new
Text
(
lastSale
,
style:
const
TextStyle
(
textAlign:
TextAlign
.
right
),
key:
priceKey
)
),
new
Flexible
(
child:
new
Text
(
changeInPrice
,
style:
Theme
.
of
(
context
).
text
.
caption
.
copyWith
(
textAlign:
TextAlign
.
right
)
)
),
],
alignItems:
FlexAlignItems
.
baseline
,
textBaseline:
DefaultTextStyle
.
of
(
context
).
textBaseline
)
...
...
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