Exemple #1
0
        public static CupertinoUserInterfaceLevelData?of(BuildContext context, bool nullOk = false)
        {
            D.assert(context != null);
            CupertinoUserInterfaceLevel query = context.dependOnInheritedWidgetOfExactType <CupertinoUserInterfaceLevel>(null);

            if (query != null)
            {
                return(query._data);
            }
            if (nullOk)
            {
                return(null);
            }
            throw new UIWidgetsError(
                      "CupertinoUserInterfaceLevel.of() called with a context that does not contain a CupertinoUserInterfaceLevel.\n" +
                      "No CupertinoUserInterfaceLevel ancestor could be found starting from the context that was passed " +
                      "to CupertinoUserInterfaceLevel.of(). This can happen because you do not have a WidgetsApp or " +
                      "MaterialApp widget (those widgets introduce a CupertinoUserInterfaceLevel), or it can happen " +
                      "if the context you use comes from a widget above those widgets.\n" +
                      "The context used was:\n" +
                      context.ToString()
                      );
        }
Exemple #2
0
        public CupertinoDynamicColor resolveFrom(BuildContext context, bool nullOk = true)
        {
            Brightness brightness = _isPlatformBrightnessDependent
                ? CupertinoTheme.brightnessOf(context, nullOk: nullOk) ?? Brightness.light
                : Brightness.light;

            bool isHighContrastEnabled = _isHighContrastDependent &&
                                         (MediaQuery.of(context, nullOk: nullOk)?.highContrast ?? false);

            CupertinoUserInterfaceLevelData level = _isInterfaceElevationDependent
                ? CupertinoUserInterfaceLevel.of(context, nullOk: nullOk) ?? CupertinoUserInterfaceLevelData.baselayer
                : CupertinoUserInterfaceLevelData.baselayer;

            Color resolved = null;

            switch (brightness)
            {
            case Brightness.light:
                switch (level)
                {
                case CupertinoUserInterfaceLevelData.baselayer:
                    resolved = isHighContrastEnabled ? highContrastColor : color;
                    break;

                case CupertinoUserInterfaceLevelData.elevatedlayer:
                    resolved = isHighContrastEnabled ? highContrastElevatedColor : elevatedColor;
                    break;
                }

                break;

            case Brightness.dark:
                switch (level)
                {
                case CupertinoUserInterfaceLevelData.baselayer:
                    resolved = isHighContrastEnabled ? darkHighContrastColor : darkColor;
                    break;

                case CupertinoUserInterfaceLevelData.elevatedlayer:
                    resolved = isHighContrastEnabled ? darkHighContrastElevatedColor : darkElevatedColor;
                    break;
                }

                break;
            }

            Element _debugContext = null;

            D.assert(() => {
                _debugContext = context as Element;
                return(true);
            }
                     );

            return(new CupertinoDynamicColor(
                       debugLabel: _debugLabel,
                       effectiveColor: resolved,
                       color: color,
                       darkColor: darkColor,
                       highContrastColor: highContrastColor,
                       darkHighContrastColor: darkHighContrastColor,
                       elevatedColor: color,
                       darkElevatedColor: darkColor,
                       highContrastElevatedColor: highContrastColor,
                       darkHighContrastElevatedColor: darkHighContrastColor,
                       debugResolveContext: null
                       ));
        }