circle_avatar.dart 1.15 KB
Newer Older
Adam Barth's avatar
Adam Barth 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 39 40 41 42 43 44 45 46 47
// 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.

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

import 'constants.dart';
import 'theme.dart';
import 'typography.dart';

class CircleAvatar extends StatelessComponent {
  CircleAvatar({
    Key key,
    this.label,
    this.backgroundColor,
    this.textTheme
  }) : super(key: key);

  final String label;
  final Color backgroundColor;
  final TextTheme textTheme;

  Widget build(BuildContext context) {
    Color color = backgroundColor;
    TextStyle style = textTheme?.title;

    if (color == null || style == null) {
      ThemeData themeData = Theme.of(context);
      color ??= themeData.primaryColor;
      style ??= themeData.primaryTextTheme.title;
    }

    return new AnimatedContainer(
      duration: kThemeChangeDuration,
      decoration: new BoxDecoration(
        backgroundColor: color,
        shape: Shape.circle
      ),
      width: 40.0,
      height: 40.0,
      child: new Center(
        child: new Text(label, style: style)
      )
    );
  }
}