Exemplo n.º 1
0
 public IconTheme(
     Key key            = null,
     IconThemeData data = null,
     Widget child       = null
     ) : base(key: key, child: child)
 {
     D.assert(data != null);
     D.assert(child != null);
     this.data = data;
 }
Exemplo n.º 2
0
        static IconThemeData _getInheritedIconThemeData(BuildContext context)
        {
            IconTheme iconTheme = (IconTheme)context.inheritFromWidgetOfExactType(typeof(IconTheme));

            if (iconTheme != null)
            {
                return(iconTheme.data);
            }

            return(IconThemeData.fallback());
        }
Exemplo n.º 3
0
        public static IconThemeData of(BuildContext context)
        {
            IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context);

            return(iconThemeData.isConcrete
                ? iconThemeData
                : iconThemeData.copyWith(
                       size: iconThemeData.size ?? IconThemeData.fallback().size,
                       color: iconThemeData.color ?? IconThemeData.fallback().color,
                       opacity: iconThemeData.opacity ?? IconThemeData.fallback().opacity
                       ));
        }
Exemplo n.º 4
0
 public static Widget merge(
     Key key            = null,
     IconThemeData data = null,
     Widget child       = null
     )
 {
     return(new Builder(
                builder: context => new IconTheme(
                    key: key,
                    data: _getInheritedIconThemeData(context).merge(data),
                    child: child
                    )
                ));
 }
Exemplo n.º 5
0
        public override Widget build(BuildContext context)
        {
            IconThemeData iconTheme = IconTheme.of(context);
            float         iconSize  = this.size ?? iconTheme.size.Value;

            if (this.icon == null)
            {
                return(new SizedBox(width: iconSize, height: iconSize));
            }

            float iconOpacity = iconTheme.opacity.Value;
            Color iconColor   = this.color ?? iconTheme.color;

            if (iconOpacity != 1.0)
            {
                iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
            }

            Widget iconWidget = new RichText(
                overflow: TextOverflow.visible,
                text: new TextSpan(
                    text: new string(new[] { (char)this.icon.codePoint }),
                    style: new TextStyle(
                        inherit: false,
                        color: iconColor,
                        fontSize: iconSize,
                        fontFamily: this.icon.fontFamily
                        )
                    )
                );

            return(new SizedBox(
                       width: iconSize,
                       height: iconSize,
                       child: new Center(
                           child: iconWidget
                           )
                       ));
        }
Exemplo n.º 6
0
        static IconThemeData _getInheritedIconThemeData(BuildContext context)
        {
            IconTheme iconTheme = (IconTheme)context.dependOnInheritedWidgetOfExactType <IconTheme>();

            return(iconTheme?.data ?? IconThemeData.fallback());
        }
Exemplo n.º 7
0
        public override Widget build(BuildContext context)
        {
            D.assert(this.textDirection != null || WidgetsD.debugCheckHasDirectionality(context));
            TextDirection textDirection = this.textDirection ?? Directionality.of(context);
            IconThemeData iconTheme     = IconTheme.of(context);
            float         iconSize      = size ?? iconTheme.size.Value;

            if (icon == null)
            {
                return(new SizedBox(width: iconSize, height: iconSize));
            }

            float iconOpacity = iconTheme.opacity.Value;
            Color iconColor   = color ?? iconTheme.color;

            if (iconOpacity != 1.0)
            {
                iconColor = iconColor.withOpacity(iconColor.opacity * iconOpacity);
            }
            Widget iconWidget = new RichText(
                overflow: TextOverflow.visible, // Never clip.
                textDirection: textDirection,   // Since we already fetched it for the assert...
                text: new TextSpan(
                    text: new string(new[] { (char)icon.codePoint }),
                    style: new TextStyle(
                        inherit: false,
                        color: iconColor,
                        fontSize: iconSize,
                        fontFamily: icon.fontFamily
                        )
                    )
                );

            var matrix = Matrix4.identity();

            matrix.scale(-1.0f, 1.0f, 1.0f);
            if (icon.matchTextDirection)
            {
                switch (textDirection)
                {
                case TextDirection.rtl:
                    iconWidget = new Transform(
                        transform: matrix,
                        alignment: Alignment.center,
                        transformHitTests: false,
                        child: iconWidget
                        );
                    break;

                case TextDirection.ltr:
                    break;
                }
            }
            return(new SizedBox(
                       width: iconSize,
                       height: iconSize,
                       child: new Center(
                           child: iconWidget
                           )
                       ));
        }
Exemplo n.º 8
0
        public static IconThemeData of(BuildContext context)
        {
            IconThemeData iconThemeData = _getInheritedIconThemeData(context);

            return(iconThemeData.isConcrete ? iconThemeData : IconThemeData.fallback().merge(iconThemeData));
        }