widgets.dart 4.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2017 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 'sections.dart';

const double kSectionIndicatorWidth = 32.0;

// The card for a single section. Displays the section's gradient and background image.
class SectionCard extends StatelessWidget {
13
  const SectionCard({ Key key, @required this.section })
14 15
    : assert(section != null),
      super(key: key);
16 17 18 19 20

  final Section section;

  @override
  Widget build(BuildContext context) {
21
    return Semantics(
22 23
      label: section.title,
      button: true,
24 25 26
      child: DecoratedBox(
        decoration: BoxDecoration(
          gradient: LinearGradient(
27 28 29 30 31 32 33 34
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
            colors: <Color>[
              section.leftColor,
              section.rightColor,
            ],
          ),
        ),
35
        child: Image.asset(
36 37 38 39 40
          section.backgroundAsset,
          package: section.backgroundAssetPackage,
          color: const Color.fromRGBO(255, 255, 255, 0.075),
          colorBlendMode: BlendMode.modulate,
          fit: BoxFit.cover,
41
        ),
42
      ),
43 44 45 46 47 48 49
    );
  }
}

// The title is rendered with two overlapping text widgets that are vertically
// offset a little. It's supposed to look sort-of 3D.
class SectionTitle extends StatelessWidget {
50
  const SectionTitle({
51 52 53 54
    Key key,
    @required this.section,
    @required this.scale,
    @required this.opacity,
55 56 57 58
  }) : assert(section != null),
       assert(scale != null),
       assert(opacity != null && opacity >= 0.0 && opacity <= 1.0),
       super(key: key);
59 60 61 62 63

  final Section section;
  final double scale;
  final double opacity;

64 65 66 67 68 69 70 71 72 73 74 75 76
  static const TextStyle sectionTitleStyle = TextStyle(
    fontFamily: 'Raleway',
    inherit: false,
    fontSize: 24.0,
    fontWeight: FontWeight.w500,
    color: Colors.white,
    textBaseline: TextBaseline.alphabetic,
  );

  static final TextStyle sectionTitleShadowStyle = sectionTitleStyle.copyWith(
    color: const Color(0x19000000),
  );

77 78
  @override
  Widget build(BuildContext context) {
79 80
    return IgnorePointer(
      child: Opacity(
81
        opacity: opacity,
82 83
        child: Transform(
          transform: Matrix4.identity()..scale(scale),
84
          alignment: Alignment.center,
85
          child: Stack(
86
            children: <Widget>[
87
              Positioned(
88
                top: 4.0,
89
                child: Text(section.title, style: sectionTitleShadowStyle),
90
              ),
91
              Text(section.title, style: sectionTitleStyle),
92 93 94 95 96 97 98 99 100 101
            ],
          ),
        ),
      ),
    );
  }
}

// Small horizontal bar that indicates the selected section.
class SectionIndicator extends StatelessWidget {
102
  const SectionIndicator({ Key key, this.opacity = 1.0 }) : super(key: key);
103 104 105 106 107

  final double opacity;

  @override
  Widget build(BuildContext context) {
108 109
    return IgnorePointer(
      child: Container(
110 111
        width: kSectionIndicatorWidth,
        height: 3.0,
112
        color: Colors.white.withOpacity(opacity),
113 114 115 116 117 118 119
      ),
    );
  }
}

// Display a single SectionDetail.
class SectionDetailView extends StatelessWidget {
120 121 122 123
  SectionDetailView({ Key key, @required this.detail })
    : assert(detail != null && detail.imageAsset != null),
      assert((detail.imageAsset ?? detail.title) != null),
      super(key: key);
124 125 126 127 128

  final SectionDetail detail;

  @override
  Widget build(BuildContext context) {
129 130 131 132 133
    final Widget image = DecoratedBox(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6.0),
        image: DecorationImage(
          image: AssetImage(
134 135 136
            detail.imageAsset,
            package: detail.imageAssetPackage,
          ),
137
          fit: BoxFit.cover,
138
          alignment: Alignment.center,
139 140 141 142 143 144
        ),
      ),
    );

    Widget item;
    if (detail.title == null && detail.subtitle == null) {
145
      item = Container(
146 147
        height: 240.0,
        padding: const EdgeInsets.all(16.0),
148
        child: SafeArea(
149 150 151 152
          top: false,
          bottom: false,
          child: image,
        ),
153 154
      );
    } else {
155 156 157 158
      item = ListTile(
        title: Text(detail.title),
        subtitle: Text(detail.subtitle),
        leading: SizedBox(width: 32.0, height: 32.0, child: image),
159 160 161
      );
    }

162 163
    return DecoratedBox(
      decoration: BoxDecoration(color: Colors.grey.shade200),
164 165 166 167
      child: item,
    );
  }
}