Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alexandre Ardhuin | 2de61a0 | 2017-03-31 18:34:13 +0200 | [diff] [blame] | 5 | import 'package:flutter/foundation.dart'; |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 6 | import 'package:flutter/material.dart'; |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 7 | |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 8 | const String _kGalleryAssetsPackage = 'flutter_gallery_assets'; |
| 9 | |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 10 | class TravelDestination { |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 11 | const TravelDestination({ |
| 12 | this.assetName, |
| 13 | this.assetPackage, |
| 14 | this.title, |
| 15 | this.description, |
| 16 | }); |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 17 | |
| 18 | final String assetName; |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 19 | final String assetPackage; |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 20 | final String title; |
| 21 | final List<String> description; |
| 22 | |
| 23 | bool get isValid => assetName != null && title != null && description?.length == 3; |
| 24 | } |
| 25 | |
| 26 | final List<TravelDestination> destinations = <TravelDestination>[ |
| 27 | const TravelDestination( |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 28 | assetName: 'top_10_australian_beaches.jpg', |
| 29 | assetPackage: _kGalleryAssetsPackage, |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 30 | title: 'Top 10 Australian beaches', |
| 31 | description: const <String>[ |
| 32 | 'Number 10', |
| 33 | 'Whitehaven Beach', |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 34 | 'Whitsunday Island, Whitsunday Islands', |
| 35 | ], |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 36 | ), |
| 37 | const TravelDestination( |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 38 | assetName: 'kangaroo_valley_safari.jpg', |
| 39 | assetPackage: _kGalleryAssetsPackage, |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 40 | title: 'Kangaroo Valley Safari', |
| 41 | description: const <String>[ |
| 42 | '2031 Moss Vale Road', |
| 43 | 'Kangaroo Valley 2577', |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 44 | 'New South Wales', |
| 45 | ], |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 46 | ) |
| 47 | ]; |
| 48 | |
Adam Barth | 95fc5ae | 2016-03-12 12:13:16 -0800 | [diff] [blame] | 49 | class TravelDestinationItem extends StatelessWidget { |
Alexandre Ardhuin | 7d71326 | 2017-06-07 21:39:47 +0200 | [diff] [blame] | 50 | TravelDestinationItem({ Key key, @required this.destination }) |
| 51 | : assert(destination != null && destination.isValid), |
| 52 | super(key: key); |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 53 | |
Hans Muller | 49f5fbb | 2017-03-24 10:21:59 -0700 | [diff] [blame] | 54 | static final double height = 366.0; |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 55 | final TravelDestination destination; |
| 56 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 57 | @override |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 58 | Widget build(BuildContext context) { |
Chris Bracken | 96eea43 | 2017-03-03 17:51:21 -0800 | [diff] [blame] | 59 | final ThemeData theme = Theme.of(context); |
| 60 | final TextStyle titleStyle = theme.textTheme.headline.copyWith(color: Colors.white); |
| 61 | final TextStyle descriptionStyle = theme.textTheme.subhead; |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 62 | |
Hans Muller | 49f5fbb | 2017-03-24 10:21:59 -0700 | [diff] [blame] | 63 | return new Container( |
| 64 | padding: const EdgeInsets.all(8.0), |
Hans Muller | a2ce948 | 2016-04-19 09:45:53 -0700 | [diff] [blame] | 65 | height: height, |
| 66 | child: new Card( |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 67 | child: new Column( |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 68 | crossAxisAlignment: CrossAxisAlignment.start, |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 69 | children: <Widget>[ |
| 70 | // photo and title |
| 71 | new SizedBox( |
| 72 | height: 184.0, |
| 73 | child: new Stack( |
| 74 | children: <Widget>[ |
DragoČ™ Tiselice | eafe1c7 | 2016-09-19 10:46:06 -0700 | [diff] [blame] | 75 | new Positioned.fill( |
Adam Barth | c674b4a | 2016-07-29 13:28:08 -0700 | [diff] [blame] | 76 | child: new Image.asset( |
| 77 | destination.assetName, |
Sarah Zakarias | a0e91bf | 2017-09-26 15:21:01 +0200 | [diff] [blame^] | 78 | package: destination.assetPackage, |
Adam Barth | 5cf04b6 | 2017-03-17 15:21:55 -0700 | [diff] [blame] | 79 | fit: BoxFit.cover, |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 80 | ), |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 81 | ), |
| 82 | new Positioned( |
| 83 | bottom: 16.0, |
| 84 | left: 16.0, |
Hans Muller | a8bf594 | 2016-10-21 14:10:39 -0700 | [diff] [blame] | 85 | right: 16.0, |
| 86 | child: new FittedBox( |
Adam Barth | 5cf04b6 | 2017-03-17 15:21:55 -0700 | [diff] [blame] | 87 | fit: BoxFit.scaleDown, |
Hans Muller | a8bf594 | 2016-10-21 14:10:39 -0700 | [diff] [blame] | 88 | alignment: FractionalOffset.centerLeft, |
| 89 | child: new Text(destination.title, |
| 90 | style: titleStyle, |
| 91 | ), |
| 92 | ), |
| 93 | ), |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 94 | ], |
| 95 | ), |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 96 | ), |
| 97 | // description and share/expore buttons |
Adam Barth | 8ca4caa | 2016-11-21 23:16:43 -0800 | [diff] [blame] | 98 | new Expanded( |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 99 | child: new Padding( |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 100 | padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0), |
Hans Muller | 69b4bca | 2016-06-16 17:20:54 -0700 | [diff] [blame] | 101 | child: new DefaultTextStyle( |
| 102 | softWrap: false, |
| 103 | overflow: TextOverflow.ellipsis, |
| 104 | style: descriptionStyle, |
| 105 | child: new Column( |
| 106 | crossAxisAlignment: CrossAxisAlignment.start, |
| 107 | children: <Widget>[ |
| 108 | // three line description |
Hans Muller | 49f5fbb | 2017-03-24 10:21:59 -0700 | [diff] [blame] | 109 | new Padding( |
| 110 | padding: const EdgeInsets.only(bottom: 8.0), |
| 111 | child: new Text( |
| 112 | destination.description[0], |
| 113 | style: descriptionStyle.copyWith(color: Colors.black54), |
| 114 | ), |
| 115 | ), |
Hans Muller | 69b4bca | 2016-06-16 17:20:54 -0700 | [diff] [blame] | 116 | new Text(destination.description[1]), |
| 117 | new Text(destination.description[2]), |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 118 | ], |
| 119 | ), |
| 120 | ), |
| 121 | ), |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 122 | ), |
| 123 | // share, explore buttons |
Ian Hickson | f75fd5c | 2016-06-08 17:29:26 -0700 | [diff] [blame] | 124 | new ButtonTheme.bar( |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 125 | child: new ButtonBar( |
| 126 | alignment: MainAxisAlignment.start, |
| 127 | children: <Widget>[ |
| 128 | new FlatButton( |
Ian Hickson | 3eb8783 | 2017-04-07 12:24:32 -0700 | [diff] [blame] | 129 | child: const Text('SHARE'), |
Hans Muller | 49f5fbb | 2017-03-24 10:21:59 -0700 | [diff] [blame] | 130 | textColor: Colors.amber.shade500, |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 131 | onPressed: () { /* do nothing */ }, |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 132 | ), |
| 133 | new FlatButton( |
Ian Hickson | 3eb8783 | 2017-04-07 12:24:32 -0700 | [diff] [blame] | 134 | child: const Text('EXPLORE'), |
Hans Muller | 49f5fbb | 2017-03-24 10:21:59 -0700 | [diff] [blame] | 135 | textColor: Colors.amber.shade500, |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 136 | onPressed: () { /* do nothing */ }, |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 137 | ), |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 138 | ], |
| 139 | ), |
Adam Barth | b2fa6c2 | 2016-04-29 16:13:25 -0700 | [diff] [blame] | 140 | ), |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 141 | ], |
| 142 | ), |
| 143 | ), |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 144 | ); |
| 145 | } |
| 146 | } |
| 147 | |
Adam Barth | 95fc5ae | 2016-03-12 12:13:16 -0800 | [diff] [blame] | 148 | class CardsDemo extends StatelessWidget { |
xster | a76c352 | 2017-03-01 16:06:48 -0800 | [diff] [blame] | 149 | static const String routeName = '/material/cards'; |
Adam Barth | 248960a | 2016-04-21 10:24:22 -0700 | [diff] [blame] | 150 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 151 | @override |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 152 | Widget build(BuildContext context) { |
| 153 | return new Scaffold( |
Adam Barth | ede5dfc | 2016-03-12 17:22:40 -0800 | [diff] [blame] | 154 | appBar: new AppBar( |
Ian Hickson | 3eb8783 | 2017-04-07 12:24:32 -0700 | [diff] [blame] | 155 | title: const Text('Travel stream') |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 156 | ), |
Ian Hickson | 332a230 | 2017-02-03 16:05:43 -0800 | [diff] [blame] | 157 | body: new ListView( |
Hans Muller | a2ce948 | 2016-04-19 09:45:53 -0700 | [diff] [blame] | 158 | itemExtent: TravelDestinationItem.height, |
Adam Barth | e71bd77 | 2016-03-12 11:43:18 -0800 | [diff] [blame] | 159 | padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0), |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 160 | children: destinations.map((TravelDestination destination) { |
| 161 | return new Container( |
Adam Barth | e71bd77 | 2016-03-12 11:43:18 -0800 | [diff] [blame] | 162 | margin: const EdgeInsets.only(bottom: 8.0), |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 163 | child: new TravelDestinationItem(destination: destination) |
| 164 | ); |
Adam Barth | a0dee55 | 2017-01-30 16:45:51 -0800 | [diff] [blame] | 165 | }).toList() |
Hans Muller | 8eaa9e6 | 2016-02-11 15:23:49 -0800 | [diff] [blame] | 166 | ) |
| 167 | ); |
| 168 | } |
| 169 | } |