cards_demo.dart 6.47 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/foundation.dart';
Hans Muller's avatar
Hans Muller committed
6 7
import 'package:flutter/material.dart';

8 9
const String _kGalleryAssetsPackage = 'flutter_gallery_assets';

Hans Muller's avatar
Hans Muller committed
10
class TravelDestination {
11 12 13 14 15 16
  const TravelDestination({
    this.assetName,
    this.assetPackage,
    this.title,
    this.description,
  });
Hans Muller's avatar
Hans Muller committed
17 18

  final String assetName;
19
  final String assetPackage;
Hans Muller's avatar
Hans Muller committed
20 21 22 23 24 25 26 27
  final String title;
  final List<String> description;

  bool get isValid => assetName != null && title != null && description?.length == 3;
}

final List<TravelDestination> destinations = <TravelDestination>[
  const TravelDestination(
28 29
    assetName: 'top_10_australian_beaches.jpg',
    assetPackage: _kGalleryAssetsPackage,
Hans Muller's avatar
Hans Muller committed
30 31 32 33
    title: 'Top 10 Australian beaches',
    description: const <String>[
      'Number 10',
      'Whitehaven Beach',
34 35
      'Whitsunday Island, Whitsunday Islands',
    ],
Hans Muller's avatar
Hans Muller committed
36 37
  ),
  const TravelDestination(
38 39
    assetName: 'kangaroo_valley_safari.jpg',
    assetPackage: _kGalleryAssetsPackage,
Hans Muller's avatar
Hans Muller committed
40 41 42 43
    title: 'Kangaroo Valley Safari',
    description: const <String>[
      '2031 Moss Vale Road',
      'Kangaroo Valley 2577',
44 45
      'New South Wales',
    ],
Hans Muller's avatar
Hans Muller committed
46 47 48
  )
];

49
class TravelDestinationItem extends StatelessWidget {
Hans Muller's avatar
Hans Muller committed
50
  TravelDestinationItem({ Key key, @required this.destination, this.shape })
51 52
    : assert(destination != null && destination.isValid),
      super(key: key);
Hans Muller's avatar
Hans Muller committed
53

54
  static const double height = 366.0;
Hans Muller's avatar
Hans Muller committed
55
  final TravelDestination destination;
Hans Muller's avatar
Hans Muller committed
56
  final ShapeBorder shape;
Hans Muller's avatar
Hans Muller committed
57

58
  @override
Hans Muller's avatar
Hans Muller committed
59
  Widget build(BuildContext context) {
60 61 62
    final ThemeData theme = Theme.of(context);
    final TextStyle titleStyle = theme.textTheme.headline.copyWith(color: Colors.white);
    final TextStyle descriptionStyle = theme.textTheme.subhead;
Hans Muller's avatar
Hans Muller committed
63

64 65 66 67 68 69 70
    return new SafeArea(
      top: false,
      bottom: false,
      child: new Container(
        padding: const EdgeInsets.all(8.0),
        height: height,
        child: new Card(
Hans Muller's avatar
Hans Muller committed
71
          shape: shape,
72 73 74 75 76 77 78 79 80 81 82 83 84 85
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              // photo and title
              new SizedBox(
                height: 184.0,
                child: new Stack(
                  children: <Widget>[
                    new Positioned.fill(
                      child: new Image.asset(
                        destination.assetName,
                        package: destination.assetPackage,
                        fit: BoxFit.cover,
                      ),
86
                    ),
87 88 89 90 91 92 93 94 95 96
                    new Positioned(
                      bottom: 16.0,
                      left: 16.0,
                      right: 16.0,
                      child: new FittedBox(
                        fit: BoxFit.scaleDown,
                        alignment: Alignment.centerLeft,
                        child: new Text(destination.title,
                          style: titleStyle,
                        ),
97 98
                      ),
                    ),
99 100
                  ],
                ),
101
              ),
Josh Soref's avatar
Josh Soref committed
102
              // description and share/explore buttons
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
                  child: new DefaultTextStyle(
                    softWrap: false,
                    overflow: TextOverflow.ellipsis,
                    style: descriptionStyle,
                    child: new Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        // three line description
                        new Padding(
                          padding: const EdgeInsets.only(bottom: 8.0),
                          child: new Text(
                            destination.description[0],
                            style: descriptionStyle.copyWith(color: Colors.black54),
                          ),
120
                        ),
121 122 123 124
                        new Text(destination.description[1]),
                        new Text(destination.description[2]),
                      ],
                    ),
125 126 127
                  ),
                ),
              ),
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
              // share, explore buttons
              new ButtonTheme.bar(
                child: new ButtonBar(
                  alignment: MainAxisAlignment.start,
                  children: <Widget>[
                    new FlatButton(
                      child: const Text('SHARE'),
                      textColor: Colors.amber.shade500,
                      onPressed: () { /* do nothing */ },
                    ),
                    new FlatButton(
                      child: const Text('EXPLORE'),
                      textColor: Colors.amber.shade500,
                      onPressed: () { /* do nothing */ },
                    ),
                  ],
                ),
145
              ),
146 147
            ],
          ),
148 149
        ),
      ),
Hans Muller's avatar
Hans Muller committed
150 151 152 153
    );
  }
}

Hans Muller's avatar
Hans Muller committed
154 155

class CardsDemo extends StatefulWidget {
156
  static const String routeName = '/material/cards';
157

Hans Muller's avatar
Hans Muller committed
158 159 160 161 162 163 164
  @override
  _CardsDemoState createState() => new _CardsDemoState();
}

class _CardsDemoState extends State<CardsDemo> {
  ShapeBorder _shape;

165
  @override
Hans Muller's avatar
Hans Muller committed
166 167
  Widget build(BuildContext context) {
    return new Scaffold(
168
      appBar: new AppBar(
Hans Muller's avatar
Hans Muller committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        title: const Text('Travel stream'),
        actions: <Widget>[
          new IconButton(
            icon: const Icon(Icons.sentiment_very_satisfied),
            onPressed: () {
              setState(() {
                _shape = _shape != null ? null : const RoundedRectangleBorder(
                  borderRadius: const BorderRadius.only(
                    topLeft: const Radius.circular(16.0),
                    topRight: const Radius.circular(16.0),
                    bottomLeft: const Radius.circular(2.0),
                    bottomRight: const Radius.circular(2.0),
                  ),
                );
              });
            },
          ),
        ],
Hans Muller's avatar
Hans Muller committed
187
      ),
188
      body: new ListView(
189
        itemExtent: TravelDestinationItem.height,
190
        padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
Hans Muller's avatar
Hans Muller committed
191 192
        children: destinations.map((TravelDestination destination) {
          return new Container(
193
            margin: const EdgeInsets.only(bottom: 8.0),
Hans Muller's avatar
Hans Muller committed
194 195 196 197
            child: new TravelDestinationItem(
              destination: destination,
              shape: _shape,
            ),
Hans Muller's avatar
Hans Muller committed
198
          );
199
        }).toList()
Hans Muller's avatar
Hans Muller committed
200 201 202 203
      )
    );
  }
}