cards_demo.dart 4.45 KB
Newer Older
Hans Muller's avatar
Hans Muller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// 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.

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TravelDestination {
  const TravelDestination({ this.assetName, this.title, this.description });

  final String assetName;
  final String title;
  final List<String> description;

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

final List<TravelDestination> destinations = <TravelDestination>[
  const TravelDestination(
    assetName: 'packages/flutter_gallery_assets/top_10_australian_beaches.png',
    title: 'Top 10 Australian beaches',
    description: const <String>[
      'Number 10',
      'Whitehaven Beach',
      'Whitsunday Island, Whitsunday Islands'
    ]
  ),
  const TravelDestination(
    assetName: 'packages/flutter_gallery_assets/kangaroo_valley_safari.png',
    title: 'Kangaroo Valley Safari',
    description: const <String>[
      '2031 Moss Vale Road',
      'Kangaroo Valley 2577',
      'New South Wales'
    ]
  )
];

39
class TravelDestinationItem extends StatelessWidget {
Hans Muller's avatar
Hans Muller committed
40 41 42 43 44 45
  TravelDestinationItem({ Key key, this.destination }) : super(key: key) {
    assert(destination != null && destination.isValid);
  }

  final TravelDestination destination;

46
  @override
Hans Muller's avatar
Hans Muller committed
47 48
  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
49 50 51
    TextStyle titleStyle = theme.textTheme.headline.copyWith(color: Colors.white);
    TextStyle descriptionStyle = theme.textTheme.subhead;
    TextStyle buttonStyle = theme.textTheme.button.copyWith(color: theme.primaryColor);
Hans Muller's avatar
Hans Muller committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

    return new Card(
      child: new SizedBox(
        height: 328.0,
        child: new Column(
          children: <Widget>[
            // photo and title
            new SizedBox(
              height: 184.0,
              child: new Stack(
                children: <Widget>[
                  new Positioned(
                    left: 0.0,
                    top: 0.0,
                    bottom: 0.0,
                    right: 0.0,
                    child: new AssetImage(
                      name: destination.assetName,
                      fit: ImageFit.cover
                    )
                  ),
                  new Positioned(
                    bottom: 16.0,
                    left: 16.0,
                    child: new Text(destination.title, style: titleStyle)
                  )
                ]
              )
            ),
            // description and share/expore buttons
            new Flexible(
              child: new Padding(
84
                padding: const EdgeInsets.all(16.0),
Hans Muller's avatar
Hans Muller committed
85
                child: new Column(
86 87
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
Hans Muller's avatar
Hans Muller committed
88 89 90 91 92 93 94 95
                  children: <Widget>[
                    // three line description
                    new Text(destination.description[0], style: descriptionStyle),
                    new Text(destination.description[1], style: descriptionStyle),
                    new Text(destination.description[2], style: descriptionStyle),
                    // share, explore buttons
                    new Flexible(
                      child: new Row(
96 97
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.end,
Hans Muller's avatar
Hans Muller committed
98 99
                        children: <Widget>[
                          new Padding(
100
                            padding: const EdgeInsets.only(right: 16.0),
Hans Muller's avatar
Hans Muller committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                            child: new Text('SHARE', style: buttonStyle)
                          ),
                          new Text('EXPLORE', style: buttonStyle)
                        ]
                      )
                    )
                  ]
                )
              )
            )
          ]
        )
      )
    );
  }
}

118
class CardsDemo extends StatelessWidget {
119
  @override
Hans Muller's avatar
Hans Muller committed
120 121
  Widget build(BuildContext context) {
    return new Scaffold(
122 123
      appBar: new AppBar(
        title: new Text("Travel Stream")
Hans Muller's avatar
Hans Muller committed
124 125
      ),
      body: new Block(
126
        padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
Hans Muller's avatar
Hans Muller committed
127 128
        children: destinations.map((TravelDestination destination) {
          return new Container(
129
            margin: const EdgeInsets.only(bottom: 8.0),
Hans Muller's avatar
Hans Muller committed
130 131 132 133 134 135 136 137
            child: new TravelDestinationItem(destination: destination)
          );
        })
        .toList()
      )
    );
  }
}