Esempio n. 1
0
        public override Widget build(BuildContext context)
        {
            base.build(context); // See AutomaticKeepAliveClientMixin.
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            ThemeData                 themeData          = Theme.of(context);
            TextStyle                 style              = this.widget.style ?? themeData.textTheme.subhead;
            Brightness                keyboardAppearance = this.widget.keyboardAppearance ?? themeData.primaryColorBrightness;
            TextEditingController     controller         = this._effectiveController;
            FocusNode                 focusNode          = this._effectiveFocusNode;
            List <TextInputFormatter> formatters         = this.widget.inputFormatters ?? new List <TextInputFormatter>();

            if (this.widget.maxLength != null && this.widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(this.widget.maxLength));
            }


            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: this._editableTextKey,
                    controller: controller,
                    focusNode: focusNode,
                    keyboardType: this.widget.keyboardType,
                    textInputAction: this.widget.textInputAction,
                    textCapitalization: this.widget.textCapitalization,
                    style: style,
                    textAlign: this.widget.textAlign,
                    textDirection: this.widget.textDirection,
                    autofocus: this.widget.autofocus,
                    obscureText: this.widget.obscureText,
                    autocorrect: this.widget.autocorrect,
                    maxLines: this.widget.maxLines,
                    selectionColor: themeData.textSelectionColor,
                    selectionControls: this.widget.enableInteractiveSelection
                        ? MaterialUtils.materialTextSelectionControls
                        : null,
                    onChanged: this.widget.onChanged,
                    onEditingComplete: this.widget.onEditingComplete,
                    onSubmitted: this.widget.onSubmitted,
                    onSelectionChanged: this._handleSelectionChanged,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: this.widget.cursorWidth,
                    cursorRadius: this.widget.cursorRadius,
                    cursorColor: this.widget.cursorColor ?? Theme.of(context).cursorColor,
                    scrollPadding: this.widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: this.widget.enableInteractiveSelection
                    )
                );

            if (this.widget.decoration != null)
            {
                child = new AnimatedBuilder(
                    animation: ListenableUtils.merge(new List <Listenable> {
                    focusNode, controller
                }),
                    builder:
                    (_context, _child) => {
                    return(new InputDecorator(
                               decoration: this._getEffectiveDecoration(),
                               baseStyle: this.widget.style,
                               textAlign: this.widget.textAlign,
                               isFocused: focusNode.hasFocus,
                               isEmpty: controller.value.text.isEmpty(),
                               child: _child
                               ));
                },
                    child: child
                    );
            }

            return(new IgnorePointer(
                       ignoring: !(this.widget.enabled ?? this.widget.decoration?.enabled ?? true),
                       child: new GestureDetector(
                           behavior: HitTestBehavior.translucent,
                           onTapDown: this._handleTapDown,
                           onTap: this._handleTap,
                           onTapCancel: this._handleTapCancel,
                           onLongPress: this._handleLongPress,
                           child: child
                           )
                       ));
        }
Esempio n. 2
0
        Widget _buildLikeCountWidget()
        {
            if (this._likeCount == null)
            {
                return(new Container());
            }
            var likeCount    = this._likeCount.ToString();
            var preLikeCount = this._preLikeCount.ToString();

            int didIndex = 0;

            if (preLikeCount.Length == likeCount.Length)
            {
                for (; didIndex < likeCount.Length; didIndex++)
                {
                    if (likeCount[didIndex] != preLikeCount[didIndex])
                    {
                        break;
                    }
                }
            }

            bool allChange = preLikeCount.Length != likeCount.Length || didIndex == 0;

            Widget result;

            if (this.widget.likeCountAnimationType == LikeCountAnimationType.none ||
                this._likeCount == this._preLikeCount)
            {
                result = this._createLikeCountWidget(this._likeCount, this._isLiked, this._likeCount.ToString());
            }
            else if (this.widget.likeCountAnimationType == LikeCountAnimationType.part &&
                     !allChange)
            {
                var samePart          = likeCount.Substring(0, didIndex);
                var preText           = preLikeCount.Substring(didIndex, preLikeCount.Length);
                var text              = likeCount.Substring(didIndex, likeCount.Length);
                var preSameWidget     = this._createLikeCountWidget(this._preLikeCount, !this._isLiked, samePart);
                var currentSameWidget = this._createLikeCountWidget(this._likeCount, this._isLiked, samePart);
                var preWidget         = this._createLikeCountWidget(this._preLikeCount, !this._isLiked, preText);
                var currentWidget     = this._createLikeCountWidget(this._likeCount, this._isLiked, text);

                result = new AnimatedBuilder(
                    animation: this._likeCountController,
                    builder: (b, w) => new Row(
                        children: new List <Widget> {
                    new Stack(
                        fit: StackFit.passthrough,
                        overflow: Overflow.clip,
                        children: new List <Widget> {
                        new Opacity(
                            child: currentSameWidget,
                            opacity: this._opacityAnimation.value
                            ),
                        new Opacity(
                            child: preSameWidget,
                            opacity: 1 - this._opacityAnimation.value
                            )
                    }
                        ),
                    new Stack(
                        fit: StackFit.passthrough,
                        overflow: Overflow.clip,
                        children: new List <Widget> {
                        new FractionalTranslation(
                            child: currentWidget,
                            translation: this._preLikeCount > this._likeCount
                                            ? this._slideCurrentValueAnimation.value
                                            : -this._slideCurrentValueAnimation.value
                            ),
                        new FractionalTranslation(
                            child: preWidget,
                            translation: this._preLikeCount > this._likeCount
                                            ? this._slidePreValueAnimation.value
                                            : -this._slidePreValueAnimation.value
                            )
                    }
                        )
                }
                        ));
            }
            else
            {
                result = new AnimatedBuilder(
                    animation: this._likeCountController,
                    builder: (b, w) => new Stack(
                        fit: StackFit.passthrough,
                        overflow: Overflow.clip,
                        children: new List <Widget> {
                    new FractionalTranslation(
                        child: this._createLikeCountWidget(this._likeCount, this._isLiked,
                                                           this._likeCount.ToString()),
                        translation: this._preLikeCount > this._likeCount
                                    ? this._slideCurrentValueAnimation.value
                                    : -this._slideCurrentValueAnimation.value
                        ),
                    new FractionalTranslation(
                        child: this._createLikeCountWidget(this._likeCount, !this._isLiked,
                                                           this._preLikeCount.ToString()),
                        translation: this._preLikeCount > this._likeCount
                                    ? this._slidePreValueAnimation.value
                                    : -this._slidePreValueAnimation.value
                        )
                }
                        )
                    );
            }

            result = new ClipRect(
                child: result,
                clipper: new LikeCountClip()
                );

            if (this.widget.likeCountPadding != null)
            {
                result = new Padding(
                    padding: this.widget.likeCountPadding,
                    child: result
                    );
            }

            return(result);
        }
Esempio n. 3
0
        public override Widget build(BuildContext context)
        {
            MediaQueryData mediaQueryData = MediaQuery.of(context);

            D.assert(widget.animation != null);
            ThemeData         theme         = Theme.of(context);
            ColorScheme       colorScheme   = theme.colorScheme;
            SnackBarThemeData snackBarTheme = theme.snackBarTheme;
            bool isThemeDark = theme.brightness == Brightness.dark;

            Brightness brightness           = isThemeDark ? Brightness.light : Brightness.dark;
            Color      themeBackgroundColor = isThemeDark
                ? colorScheme.onSurface
                : Color.alphaBlend(colorScheme.onSurface.withOpacity(0.80f), colorScheme.surface);
            ThemeData inverseTheme = new ThemeData(
                brightness: brightness,
                backgroundColor: themeBackgroundColor,
                colorScheme: new ColorScheme(
                    primary: colorScheme.onPrimary,
                    primaryVariant: colorScheme.onPrimary,
                    secondary: isThemeDark ? colorScheme.primaryVariant : colorScheme.secondary,
                    secondaryVariant: colorScheme.onSecondary,
                    surface: colorScheme.onSurface,
                    background: themeBackgroundColor,
                    error: colorScheme.onError,
                    onPrimary: colorScheme.primary,
                    onSecondary: colorScheme.secondary,
                    onSurface: colorScheme.surface,
                    onBackground: colorScheme.background,
                    onError: colorScheme.error,
                    brightness: brightness
                    ),
                snackBarTheme: snackBarTheme
                );

            TextStyle        contentTextStyle   = snackBarTheme.contentTextStyle ?? inverseTheme.textTheme.subtitle1;
            SnackBarBehavior snackBarBehavior   = widget.behavior ?? snackBarTheme.behavior ?? SnackBarBehavior.fix;
            bool             isFloatingSnackBar = snackBarBehavior == SnackBarBehavior.floating;
            float            snackBarPadding    = isFloatingSnackBar ? 16.0f : 24.0f;

            CurvedAnimation heightAnimation =
                new CurvedAnimation(parent: widget.animation, curve: SnackBarUtils._snackBarHeightCurve);
            CurvedAnimation fadeInAnimation =
                new CurvedAnimation(parent: widget.animation, curve: SnackBarUtils._snackBarFadeInCurve);
            CurvedAnimation fadeOutAnimation = new CurvedAnimation(
                parent: widget.animation,
                curve: SnackBarUtils._snackBarFadeOutCurve,
                reverseCurve: new Threshold(0.0f)
                );

            var childrenList = new List <Widget>()
            {
                new SizedBox(width: snackBarPadding),
                new Expanded(
                    child: new Container(
                        padding: EdgeInsets.symmetric(vertical: SnackBarUtils._singleLineVerticalPadding),
                        child: new DefaultTextStyle(
                            style: contentTextStyle,
                            child: widget.content
                            )
                        )
                    )
            };

            if (widget.action != null)
            {
                childrenList.Add(new ButtonTheme(
                                     textTheme: ButtonTextTheme.accent,
                                     minWidth: 64.0f,
                                     padding: EdgeInsets.symmetric(horizontal: snackBarPadding),
                                     child: widget.action
                                     ));
            }
            else
            {
                childrenList.Add(new SizedBox(width: snackBarPadding));
            }

            Widget snackBar = new SafeArea(
                top: false,
                bottom: !isFloatingSnackBar,
                child: new Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: childrenList
                    )
                );

            float elevation       = widget.elevation ?? snackBarTheme.elevation ?? 6.0f;
            Color backgroundColor =
                widget.backgroundColor ?? snackBarTheme.backgroundColor ?? inverseTheme.backgroundColor;
            ShapeBorder shape = widget.shape
                                ?? snackBarTheme.shape
                                ?? (isFloatingSnackBar
                                    ? new RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0f))
                                    : null);

            snackBar = new Material(
                shape: shape,
                elevation: elevation,
                color: backgroundColor,
                child: new Theme(
                    data: inverseTheme,
                    child: mediaQueryData.accessibleNavigation
                        ? snackBar
                        : new FadeTransition(
                        opacity: fadeOutAnimation,
                        child: snackBar
                        )
                    )
                );

            if (isFloatingSnackBar)
            {
                snackBar = new Padding(
                    padding: EdgeInsets.fromLTRB(15.0f, 5.0f, 15.0f, 10.0f),
                    child: snackBar
                    );
            }

            snackBar = new Dismissible(
                key: Key.key("dismissible"),
                direction: DismissDirection.down,
                resizeDuration: null,
                onDismissed: (DismissDirection? direction) => {
                Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
            },
                child: snackBar
                );

            Widget snackBarTransition = null;

            if (mediaQueryData.accessibleNavigation)
            {
                snackBarTransition = snackBar;
            }
            else if (isFloatingSnackBar)
            {
                snackBarTransition = new FadeTransition(
                    opacity: fadeInAnimation,
                    child: snackBar
                    );
            }
            else
            {
                snackBarTransition = new AnimatedBuilder(
                    animation: heightAnimation,
                    builder: (BuildContext subContext, Widget subChild) => {
                    return(new Align(
                               alignment: AlignmentDirectional.topStart,
                               heightFactor: heightAnimation.value,
                               child: subChild
                               ));
                },
                    child: snackBar
                    );
            }

            return(new ClipRect(child: snackBarTransition));
        }
Esempio n. 4
0
        public override Widget build(BuildContext context)
        {
            base.build(context); // See AutomaticKeepAliveClientMixin.
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(
                !(this.widget.style != null && this.widget.style.inherit == false &&
                  (this.widget.style.fontSize == null || this.widget.style.textBaseline == null)),
                "inherit false style must supply fontSize and textBaseline"
                );
            ThemeData                 themeData          = Theme.of(context);
            TextStyle                 style              = themeData.textTheme.subhead.merge(this.widget.style);
            Brightness                keyboardAppearance = this.widget.keyboardAppearance ?? themeData.primaryColorBrightness;
            TextEditingController     controller         = this._effectiveController;
            FocusNode                 focusNode          = this._effectiveFocusNode;
            List <TextInputFormatter> formatters         = this.widget.inputFormatters ?? new List <TextInputFormatter>();

            if (this.widget.maxLength != null && this.widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(this.widget.maxLength));
            }

            bool forcePressEnabled = false;
            TextSelectionControls textSelectionControls = MaterialUtils.materialTextSelectionControls;;
            bool   paintCursorAboveText  = false;
            bool   cursorOpacityAnimates = false;
            Offset cursorOffset          = null;
            Color  cursorColor           = this.widget.cursorColor ?? themeData.cursorColor;
            Radius cursorRadius          = this.widget.cursorRadius;

            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: this._editableTextKey,
                    controller: controller,
                    focusNode: focusNode,
                    keyboardType: this.widget.keyboardType,
                    textInputAction: this.widget.textInputAction,
                    textCapitalization: this.widget.textCapitalization,
                    style: style,
                    textAlign: this.widget.textAlign,
                    textDirection: this.widget.textDirection,
                    autofocus: this.widget.autofocus,
                    obscureText: this.widget.obscureText,
                    autocorrect: this.widget.autocorrect,
                    maxLines: this.widget.maxLines,
                    selectionColor: themeData.textSelectionColor,
                    selectionControls: this.widget.selectionEnabled ? textSelectionControls : null,
                    onChanged: this.widget.onChanged,
                    onSelectionChanged: this._handleSelectionChanged,
                    onEditingComplete: this.widget.onEditingComplete,
                    onSubmitted: this.widget.onSubmitted,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: this.widget.cursorWidth,
                    cursorRadius: cursorRadius,
                    cursorColor: cursorColor,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    cursorOffset: cursorOffset,
                    paintCursorAboveText: paintCursorAboveText,
                    backgroundCursorColor: new Color(0xFF8E8E93),// TODO: CupertinoColors.inactiveGray,
                    scrollPadding: this.widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: this.widget.enableInteractiveSelection == true,
                    dragStartBehavior: this.widget.dragStartBehavior
                    )
                );

            if (this.widget.decoration != null)
            {
                child = new AnimatedBuilder(
                    animation: ListenableUtils.merge(new List <Listenable> {
                    focusNode, controller
                }),
                    builder:
                    (_context, _child) => {
                    return(new InputDecorator(
                               decoration: this._getEffectiveDecoration(),
                               baseStyle: this.widget.style,
                               textAlign: this.widget.textAlign,
                               isFocused: focusNode.hasFocus,
                               isEmpty: controller.value.text.isEmpty(),
                               child: _child
                               ));
                },
                    child: child
                    );
            }

            return(new IgnorePointer(
                       ignoring: !(this.widget.enabled ?? this.widget.decoration?.enabled ?? true),
                       child: new TextSelectionGestureDetector(
                           onTapDown: this._handleTapDown,
                           // onForcePressStart: forcePressEnabled ? this._handleForcePressStarted : null, // TODO: Remove this when force press is added
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }
Esempio n. 5
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterial(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(
                !(widget.style != null && widget.style.inherit == false &&
                  (widget.style.fontSize == null || widget.style.textBaseline == null)),
                () => "inherit false style must supply fontSize and textBaseline"
                );
            ThemeData                 themeData          = Theme.of(context);
            TextStyle                 style              = themeData.textTheme.subtitle1.merge(widget.style);
            Brightness                keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness;
            TextEditingController     controller         = _effectiveController;
            FocusNode                 focusNode          = _effectiveFocusNode;
            List <TextInputFormatter> formatters         = widget.inputFormatters ?? new List <TextInputFormatter>();

            if (widget.maxLength != null && widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(widget.maxLength));
            }

            TextSelectionControls textSelectionControls = MaterialUtils.materialTextSelectionControls;

            ;
            bool   paintCursorAboveText  = false;
            bool   cursorOpacityAnimates = false;
            Offset cursorOffset          = null;
            Color  cursorColor           = widget.cursorColor ?? themeData.cursorColor;
            Radius cursorRadius          = widget.cursorRadius;

            _forcePressEnabled    = false;
            textSelectionControls = _MaterialTextSelectionControls.materialTextSelectionControls;
            paintCursorAboveText  = false;
            cursorOpacityAnimates = false;
            cursorColor           = cursorColor ?? themeData.cursorColor;

            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: editableTextKey,
                    readOnly: widget.readOnly,
                    toolbarOptions: widget.toolbarOptions,
                    showCursor: widget.showCursor,
                    showSelectionHandles: _showSelectionHandles,
                    controller: controller,
                    focusNode: focusNode,
                    keyboardType: widget.keyboardType,
                    textInputAction: widget.textInputAction,
                    textCapitalization: widget.textCapitalization,
                    style: style,
                    strutStyle: widget.strutStyle,
                    textAlign: widget.textAlign,
                    textDirection: widget.textDirection,
                    autofocus: widget.autofocus,
                    obscureText: widget.obscureText,
                    autocorrect: widget.autocorrect,
                    smartDashesType: widget.smartDashesType,
                    smartQuotesType: widget.smartQuotesType,
                    enableSuggestions: widget.enableSuggestions,
                    maxLines: widget.maxLines,
                    minLines: widget.minLines,
                    expands: widget.expands,
                    selectionColor: themeData.textSelectionColor,
                    selectionControls: widget.selectionEnabled ? textSelectionControls : null,
                    onChanged: widget.onChanged,
                    onSelectionChanged: _handleSelectionChanged,
                    onEditingComplete: widget.onEditingComplete,
                    onSubmitted: widget.onSubmitted,
                    onSelectionHandleTapped: _handleSelectionHandleTapped,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: widget.cursorWidth.Value,
                    cursorRadius: cursorRadius,
                    cursorColor: cursorColor,
                    selectionHeightStyle: widget.selectionHeightStyle,
                    selectionWidthStyle: widget.selectionWidthStyle,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    cursorOffset: cursorOffset,
                    paintCursorAboveText: paintCursorAboveText,
                    backgroundCursorColor: CupertinoColors.inactiveGray,
                    scrollPadding: widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: widget.enableInteractiveSelection == true,
                    dragStartBehavior: widget.dragStartBehavior,
                    scrollController: widget.scrollController,
                    scrollPhysics: widget.scrollPhysics
                    )
                );

            if (widget.decoration != null)
            {
                child = new AnimatedBuilder(
                    animation: ListenableUtils.merge(new List <Listenable> {
                    focusNode, controller
                }),
                    builder:
                    (_context, _child) => {
                    return(new InputDecorator(
                               decoration: _getEffectiveDecoration(),
                               baseStyle: widget.style,
                               textAlign: widget.textAlign,
                               textAlignVertical: widget.textAlignVertical,
                               isHovering: _isHovering,
                               isFocused: focusNode.hasFocus,
                               isEmpty: controller.value.text.isEmpty(),
                               expands: widget.expands,
                               child: _child
                               ));
                },
                    child: child
                    );
            }

            void onEnter(PointerEnterEvent pEvent)
            {
                _handleHover(true);
            }

            void onExit(PointerExitEvent pEvent)
            {
                _handleHover(false);
            }

            return(new IgnorePointer(
                       ignoring: !_isEnabled,
                       child: new MouseRegion(
                           onEnter: onEnter,
                           onExit: onExit,
                           child: new AnimatedBuilder(
                               animation: controller,
                               builder: (BuildContext buildContext, Widget buildChild) => { return buildChild; },
                               child: _selectionGestureDetectorBuilder.buildGestureDetector(
                                   behavior: HitTestBehavior.translucent,
                                   child: child
                                   )
                               )
                           )
                       ));
        }