blob: 876ee60c12ca5ab56d18e875113302a396914ebd [file] [log] [blame]
Hans Muller8eaa9e62016-02-11 15:23:49 -08001// 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 Ardhuin2de61a02017-03-31 18:34:13 +02005import 'package:flutter/foundation.dart';
Hans Muller8eaa9e62016-02-11 15:23:49 -08006import 'package:flutter/material.dart';
Hans Muller8eaa9e62016-02-11 15:23:49 -08007
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +02008const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
9
Hans Muller8eaa9e62016-02-11 15:23:49 -080010class TravelDestination {
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +020011 const TravelDestination({
12 this.assetName,
13 this.assetPackage,
14 this.title,
15 this.description,
16 });
Hans Muller8eaa9e62016-02-11 15:23:49 -080017
18 final String assetName;
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +020019 final String assetPackage;
Hans Muller8eaa9e62016-02-11 15:23:49 -080020 final String title;
21 final List<String> description;
22
23 bool get isValid => assetName != null && title != null && description?.length == 3;
24}
25
26final List<TravelDestination> destinations = <TravelDestination>[
27 const TravelDestination(
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +020028 assetName: 'top_10_australian_beaches.jpg',
29 assetPackage: _kGalleryAssetsPackage,
Hans Muller8eaa9e62016-02-11 15:23:49 -080030 title: 'Top 10 Australian beaches',
31 description: const <String>[
32 'Number 10',
33 'Whitehaven Beach',
Adam Bartha0dee552017-01-30 16:45:51 -080034 'Whitsunday Island, Whitsunday Islands',
35 ],
Hans Muller8eaa9e62016-02-11 15:23:49 -080036 ),
37 const TravelDestination(
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +020038 assetName: 'kangaroo_valley_safari.jpg',
39 assetPackage: _kGalleryAssetsPackage,
Hans Muller8eaa9e62016-02-11 15:23:49 -080040 title: 'Kangaroo Valley Safari',
41 description: const <String>[
42 '2031 Moss Vale Road',
43 'Kangaroo Valley 2577',
Adam Bartha0dee552017-01-30 16:45:51 -080044 'New South Wales',
45 ],
Hans Muller8eaa9e62016-02-11 15:23:49 -080046 )
47];
48
Adam Barth95fc5ae2016-03-12 12:13:16 -080049class TravelDestinationItem extends StatelessWidget {
Alexandre Ardhuin7d713262017-06-07 21:39:47 +020050 TravelDestinationItem({ Key key, @required this.destination })
51 : assert(destination != null && destination.isValid),
52 super(key: key);
Hans Muller8eaa9e62016-02-11 15:23:49 -080053
Hans Muller49f5fbb2017-03-24 10:21:59 -070054 static final double height = 366.0;
Hans Muller8eaa9e62016-02-11 15:23:49 -080055 final TravelDestination destination;
56
Hixie797e27e2016-03-14 13:31:43 -070057 @override
Hans Muller8eaa9e62016-02-11 15:23:49 -080058 Widget build(BuildContext context) {
Chris Bracken96eea432017-03-03 17:51:21 -080059 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 Muller8eaa9e62016-02-11 15:23:49 -080062
Hans Muller49f5fbb2017-03-24 10:21:59 -070063 return new Container(
64 padding: const EdgeInsets.all(8.0),
Hans Mullera2ce9482016-04-19 09:45:53 -070065 height: height,
66 child: new Card(
Hans Muller8eaa9e62016-02-11 15:23:49 -080067 child: new Column(
Adam Barthb2fa6c22016-04-29 16:13:25 -070068 crossAxisAlignment: CrossAxisAlignment.start,
Hans Muller8eaa9e62016-02-11 15:23:49 -080069 children: <Widget>[
70 // photo and title
71 new SizedBox(
72 height: 184.0,
73 child: new Stack(
74 children: <Widget>[
DragoČ™ Tiseliceeafe1c72016-09-19 10:46:06 -070075 new Positioned.fill(
Adam Barthc674b4a2016-07-29 13:28:08 -070076 child: new Image.asset(
77 destination.assetName,
Sarah Zakariasa0e91bf2017-09-26 15:21:01 +020078 package: destination.assetPackage,
Adam Barth5cf04b62017-03-17 15:21:55 -070079 fit: BoxFit.cover,
Adam Bartha0dee552017-01-30 16:45:51 -080080 ),
Hans Muller8eaa9e62016-02-11 15:23:49 -080081 ),
82 new Positioned(
83 bottom: 16.0,
84 left: 16.0,
Hans Mullera8bf5942016-10-21 14:10:39 -070085 right: 16.0,
86 child: new FittedBox(
Adam Barth5cf04b62017-03-17 15:21:55 -070087 fit: BoxFit.scaleDown,
Hans Mullera8bf5942016-10-21 14:10:39 -070088 alignment: FractionalOffset.centerLeft,
89 child: new Text(destination.title,
90 style: titleStyle,
91 ),
92 ),
93 ),
Adam Bartha0dee552017-01-30 16:45:51 -080094 ],
95 ),
Hans Muller8eaa9e62016-02-11 15:23:49 -080096 ),
97 // description and share/expore buttons
Adam Barth8ca4caa2016-11-21 23:16:43 -080098 new Expanded(
Hans Muller8eaa9e62016-02-11 15:23:49 -080099 child: new Padding(
Adam Barthb2fa6c22016-04-29 16:13:25 -0700100 padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
Hans Muller69b4bca2016-06-16 17:20:54 -0700101 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 Muller49f5fbb2017-03-24 10:21:59 -0700109 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 Muller69b4bca2016-06-16 17:20:54 -0700116 new Text(destination.description[1]),
117 new Text(destination.description[2]),
Adam Bartha0dee552017-01-30 16:45:51 -0800118 ],
119 ),
120 ),
121 ),
Adam Barthb2fa6c22016-04-29 16:13:25 -0700122 ),
123 // share, explore buttons
Ian Hicksonf75fd5c2016-06-08 17:29:26 -0700124 new ButtonTheme.bar(
Adam Barthb2fa6c22016-04-29 16:13:25 -0700125 child: new ButtonBar(
126 alignment: MainAxisAlignment.start,
127 children: <Widget>[
128 new FlatButton(
Ian Hickson3eb87832017-04-07 12:24:32 -0700129 child: const Text('SHARE'),
Hans Muller49f5fbb2017-03-24 10:21:59 -0700130 textColor: Colors.amber.shade500,
Adam Bartha0dee552017-01-30 16:45:51 -0800131 onPressed: () { /* do nothing */ },
Adam Barthb2fa6c22016-04-29 16:13:25 -0700132 ),
133 new FlatButton(
Ian Hickson3eb87832017-04-07 12:24:32 -0700134 child: const Text('EXPLORE'),
Hans Muller49f5fbb2017-03-24 10:21:59 -0700135 textColor: Colors.amber.shade500,
Adam Bartha0dee552017-01-30 16:45:51 -0800136 onPressed: () { /* do nothing */ },
Adam Barthb2fa6c22016-04-29 16:13:25 -0700137 ),
Adam Bartha0dee552017-01-30 16:45:51 -0800138 ],
139 ),
Adam Barthb2fa6c22016-04-29 16:13:25 -0700140 ),
Adam Bartha0dee552017-01-30 16:45:51 -0800141 ],
142 ),
143 ),
Hans Muller8eaa9e62016-02-11 15:23:49 -0800144 );
145 }
146}
147
Adam Barth95fc5ae2016-03-12 12:13:16 -0800148class CardsDemo extends StatelessWidget {
xstera76c3522017-03-01 16:06:48 -0800149 static const String routeName = '/material/cards';
Adam Barth248960a2016-04-21 10:24:22 -0700150
Hixie797e27e2016-03-14 13:31:43 -0700151 @override
Hans Muller8eaa9e62016-02-11 15:23:49 -0800152 Widget build(BuildContext context) {
153 return new Scaffold(
Adam Barthede5dfc2016-03-12 17:22:40 -0800154 appBar: new AppBar(
Ian Hickson3eb87832017-04-07 12:24:32 -0700155 title: const Text('Travel stream')
Hans Muller8eaa9e62016-02-11 15:23:49 -0800156 ),
Ian Hickson332a2302017-02-03 16:05:43 -0800157 body: new ListView(
Hans Mullera2ce9482016-04-19 09:45:53 -0700158 itemExtent: TravelDestinationItem.height,
Adam Barthe71bd772016-03-12 11:43:18 -0800159 padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
Hans Muller8eaa9e62016-02-11 15:23:49 -0800160 children: destinations.map((TravelDestination destination) {
161 return new Container(
Adam Barthe71bd772016-03-12 11:43:18 -0800162 margin: const EdgeInsets.only(bottom: 8.0),
Hans Muller8eaa9e62016-02-11 15:23:49 -0800163 child: new TravelDestinationItem(destination: destination)
164 );
Adam Bartha0dee552017-01-30 16:45:51 -0800165 }).toList()
Hans Muller8eaa9e62016-02-11 15:23:49 -0800166 )
167 );
168 }
169}