コード例 #1
0
ファイル: circle_avatar.cs プロジェクト: JC-ut0/CubeGame
        public override Widget build(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            ThemeData theme     = Theme.of(context);
            TextStyle textStyle = theme.primaryTextTheme.subhead.copyWith(color: this.foregroundColor);
            Color     effectiveBackgroundColor = this.backgroundColor;

            if (effectiveBackgroundColor == null)
            {
                switch (ThemeData.estimateBrightnessForColor(textStyle.color))
                {
                case Brightness.dark:
                    effectiveBackgroundColor = theme.primaryColorLight;
                    break;

                case Brightness.light:
                    effectiveBackgroundColor = theme.primaryColorDark;
                    break;
                }
            }
            else if (this.foregroundColor == null)
            {
                switch (ThemeData.estimateBrightnessForColor(this.backgroundColor))
                {
                case Brightness.dark:
                    textStyle = textStyle.copyWith(color: theme.primaryColorLight);
                    break;

                case Brightness.light:
                    textStyle = textStyle.copyWith(color: theme.primaryColorDark);
                    break;
                }
            }

            float minDiameter = this._minDiameter;
            float maxDiameter = this._maxDiameter;

            return(new AnimatedContainer(
                       constraints: new BoxConstraints(
                           minHeight: minDiameter,
                           minWidth: minDiameter,
                           maxWidth: maxDiameter,
                           maxHeight: maxDiameter
                           ),
                       duration: Constants.kThemeChangeDuration,
                       decoration: new BoxDecoration(
                           color: effectiveBackgroundColor,
                           image: this.backgroundImage != null
                        ? new DecorationImage(image: this.backgroundImage, fit: BoxFit.cover)
                        : null,
                           shape: BoxShape.circle
                           ),
                       child: this.child == null
                    ? null
                    : new Center(
                           child: new MediaQuery(
                               data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0f),
                               child: new IconTheme(
                                   data: theme.iconTheme.copyWith(color: textStyle.color),
                                   child: new DefaultTextStyle(
                                       style: textStyle,
                                       child: this.child
                                       )
                                   )
                               )
                           )
                       ));
        }