fitness_item.dart 1.85 KB
Newer Older
1 2 3 4
// Copyright 2015 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
part of fitness;
6 7 8

typedef void FitnessItemHandler(FitnessItem item);

Eric Seidel's avatar
Eric Seidel committed
9 10 11
// TODO(eseidel): This should be a constant on a SingleLineTile class
// https://www.google.com/design/spec/components/lists.html#lists-specs
const double kFitnessItemHeight = 48.0;
12

13
abstract class FitnessItem {
14 15
  FitnessItem.fromJson(Map json) : when = DateTime.parse(json['when']);

16 17 18 19 20
  FitnessItem({ this.when }) {
    assert(when != null);
  }
  final DateTime when;

21 22
  Map toJson() => { 'when' : when.toIso8601String() };

23
  // TODO(jackson): Internationalize
24
  String get displayDate => DateUtils.toDateString(when);
25 26

  FitnessItemRow toRow({ FitnessItemHandler onDismissed });
27 28
}

29
abstract class FitnessItemRow extends StatelessComponent {
30 31 32

  FitnessItemRow({ FitnessItem item, this.onDismissed })
   : this.item = item,
Hixie's avatar
Hixie committed
33
     super(key: new ValueKey<DateTime>(item.when)) {
34 35
    assert(onDismissed != null);
  }
36 37 38 39

  final FitnessItem item;
  final FitnessItemHandler onDismissed;

40
  Widget buildContent(BuildContext context);
41

42
  Widget build(BuildContext context) {
43 44
    return new Dismissable(
      onDismissed: () => onDismissed(item),
Eric Seidel's avatar
Eric Seidel committed
45 46 47 48 49 50 51 52 53
      child: new Container(
        height: kFitnessItemHeight,
        // TODO(eseidel): Padding top should be 16px for a single-line tile:
        // https://www.google.com/design/spec/components/lists.html#lists-specs
        padding: const EdgeDims.all(10.0),
        // TODO(eseidel): This line should be drawn by the list as it should
        // stay put even when the tile is dismissed!
        decoration: new BoxDecoration(
          border: new Border(
54
            bottom: new BorderSide(color: Theme.of(context).dividerColor)
Eric Seidel's avatar
Eric Seidel committed
55 56
          )
        ),
57
        child: buildContent(context)
58 59 60 61
      )
    );
  }
}