コード例 #1
0
        public override Widget build(BuildContext context)
        {
            ThemeData theme  = Theme.of(context);
            Widget    picker = new Flexible(
                child: new SizedBox(
                    height: DatePickerUtils._kMaxDayPickerHeight,
                    child: this._buildPicker()
                    )
                );
            Widget actions = ButtonTheme.bar(
                child: new ButtonBar(
                    children: new List <Widget> {
                new FlatButton(
                    child: new Text(this.localizations.cancelButtonLabel),
                    onPressed: this._handleCancel
                    ),
                new FlatButton(
                    child: new Text(this.localizations.okButtonLabel),
                    onPressed: this._handleOk
                    )
            }
                    )
                );
            Dialog dialog = new Dialog(
                child: new OrientationBuilder(
                    builder: (BuildContext _context, Orientation orientation) => {
                Widget header = new _DatePickerHeader(
                    selectedDate: this._selectedDate,
                    mode: this._mode,
                    onModeChanged: this._handleModeChanged,
                    orientation: orientation
                    );

                switch (orientation)
                {
                case Orientation.portrait:
                    return(new SizedBox(
                               width: DatePickerUtils._kMonthPickerPortraitWidth,
                               child: new Column(
                                   mainAxisSize: MainAxisSize.min,
                                   crossAxisAlignment: CrossAxisAlignment.stretch,
                                   children: new List <Widget> {
                        header,
                        new Container(
                            color: theme.dialogBackgroundColor,
                            child: new Column(
                                mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.stretch,
                                children: new List <Widget> {
                            picker,
                            actions,
                        }
                                )
                            )
                    }
                                   )
                               ));

                case Orientation.landscape:
                    return(new SizedBox(
                               height: DatePickerUtils._kDatePickerLandscapeHeight,
                               child: new Row(
                                   mainAxisSize: MainAxisSize.min,
                                   crossAxisAlignment: CrossAxisAlignment.stretch,
                                   children: new List <Widget> {
                        header,
                        new Flexible(
                            child: new Container(
                                width: DatePickerUtils._kMonthPickerLandscapeWidth,
                                color: theme.dialogBackgroundColor,
                                child: new Column(
                                    mainAxisSize: MainAxisSize.min,
                                    crossAxisAlignment: CrossAxisAlignment.stretch,
                                    children: new List <Widget> {
                            picker, actions
                        }
                                    )
                                )
                            )
                    }
                                   )
                               ));
                }

                return(null);
            }
                    )
                );

            return(new Theme(
                       data: theme.copyWith(
                           dialogBackgroundColor: Colors.transparent
                           ),
                       child: dialog
                       ));
        }
コード例 #2
0
        public override Widget build(BuildContext context)
        {
            MaterialLocalizations localizations   = MaterialLocalizations.of(context);
            ThemeData             themeData       = Theme.of(context);
            TextTheme             headerTextTheme = themeData.primaryTextTheme;
            Color dayColor  = null;
            Color yearColor = null;

            switch (themeData.primaryColorBrightness)
            {
            case Brightness.light:
                dayColor  = this.mode == DatePickerMode.day ? Colors.black87 : Colors.black54;
                yearColor = this.mode == DatePickerMode.year ? Colors.black87 : Colors.black54;
                break;

            case Brightness.dark:
                dayColor  = this.mode == DatePickerMode.day ? Colors.white : Colors.white70;
                yearColor = this.mode == DatePickerMode.year ? Colors.white : Colors.white70;
                break;
            }

            TextStyle dayStyle        = headerTextTheme.display1.copyWith(color: dayColor, height: 1.4f);
            TextStyle yearStyle       = headerTextTheme.subhead.copyWith(color: yearColor, height: 1.4f);
            Color     backgroundColor = null;

            switch (themeData.brightness)
            {
            case Brightness.light:
                backgroundColor = themeData.primaryColor;
                break;

            case Brightness.dark:
                backgroundColor = themeData.backgroundColor;
                break;
            }

            float             width             = 0f;
            float             height            = 0f;
            EdgeInsets        padding           = null;
            MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center;

            switch (this.orientation)
            {
            case Orientation.portrait:
                height            = DatePickerUtils._kDatePickerHeaderPortraitHeight;
                padding           = EdgeInsets.symmetric(horizontal: 16.0f);
                mainAxisAlignment = MainAxisAlignment.center;
                break;

            case Orientation.landscape:
                width             = DatePickerUtils._kDatePickerHeaderLandscapeWidth;
                padding           = EdgeInsets.all(8.0f);
                mainAxisAlignment = MainAxisAlignment.start;
                break;
            }

            Widget yearButton = new IgnorePointer(
                ignoring: this.mode != DatePickerMode.day,
                child: new _DateHeaderButton(
                    color: backgroundColor,
                    onTap: Feedback.wrapForTap(() => this._handleChangeMode(DatePickerMode.year), context),
                    child: new Text(localizations.formatYear(this.selectedDate), style: yearStyle)
                    )
                );
            Widget dayButton = new IgnorePointer(
                ignoring: this.mode == DatePickerMode.day,
                child: new _DateHeaderButton(
                    color: backgroundColor,
                    onTap: Feedback.wrapForTap(() => this._handleChangeMode(DatePickerMode.day), context),
                    child: new Text(localizations.formatMediumDate(this.selectedDate), style: dayStyle)
                    )
                );

            return(new Container(
                       width: width,
                       height: height,
                       padding: padding,
                       color: backgroundColor,
                       child: new Column(
                           mainAxisAlignment: mainAxisAlignment,
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                yearButton, dayButton
            }
                           )
                       ));
        }
コード例 #3
0
        public override Widget build(BuildContext context)
        {
            ThemeData             themeData     = Theme.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            int           year           = this.displayedMonth.Year;
            int           month          = this.displayedMonth.Month;
            int           daysInMonth    = getDaysInMonth(year, month);
            int           firstDayOffset = this._computeFirstDayOffset(year, month, localizations);
            List <Widget> labels         = new List <Widget>();

            labels.AddRange(this._getDayHeaders(themeData.textTheme.caption, localizations));
            for (int i = 0; true; i += 1)
            {
                int day = i - firstDayOffset + 1;
                if (day > daysInMonth)
                {
                    break;
                }

                if (day < 1)
                {
                    labels.Add(new Container());
                }
                else
                {
                    DateTime dayToBuild = new DateTime(year, month, day);
                    bool     disabled   = dayToBuild > this.lastDate ||
                                          dayToBuild < this.firstDate ||
                                          (this.selectableDayPredicate != null &&
                                           !this.selectableDayPredicate(dayToBuild));
                    BoxDecoration decoration    = null;
                    TextStyle     itemStyle     = themeData.textTheme.body1;
                    bool          isSelectedDay = this.selectedDate.Year == year && this.selectedDate.Month == month &&
                                                  this.selectedDate.Day == day;
                    if (isSelectedDay)
                    {
                        itemStyle  = themeData.accentTextTheme.body2;
                        decoration = new BoxDecoration(
                            color: themeData.accentColor,
                            shape: BoxShape.circle
                            );
                    }
                    else if (disabled)
                    {
                        itemStyle = themeData.textTheme.body1.copyWith(color: themeData.disabledColor);
                    }
                    else if (this.currentDate.Year == year && this.currentDate.Month == month &&
                             this.currentDate.Day == day)
                    {
                        itemStyle = themeData.textTheme.body2.copyWith(color: themeData.accentColor);
                    }

                    Widget dayWidget = new Container(
                        decoration: decoration,
                        child: new Center(
                            child: new Text(localizations.formatDecimal(day), style: itemStyle)
                            )
                        );
                    if (!disabled)
                    {
                        dayWidget = new GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: () => { this.onChanged(dayToBuild); },
                            child: dayWidget,
                            dragStartBehavior: this.dragStartBehavior
                            );
                    }

                    labels.Add(dayWidget);
                }
            }

            return(new Padding(
                       padding: EdgeInsets.symmetric(horizontal: 8.0f),
                       child: new Column(
                           children: new List <Widget> {
                new Container(
                    height: DatePickerUtils._kDayPickerRowHeight,
                    child: new Center(
                        child: new Text(
                            localizations.formatMonthYear(this.displayedMonth),
                            style: themeData.textTheme.subhead
                            )
                        )
                    ),
                new Flexible(
                    child: GridView.custom(
                        gridDelegate: DatePickerUtils._kDayPickerGridDelegate,
                        childrenDelegate: new SliverChildListDelegate(labels, addRepaintBoundaries: false)
                        )
                    )
            }
                           )
                       ));
        }
コード例 #4
0
        public override Widget buildPage(BuildContext context, Animation <float> animation,
                                         Animation <float> secondaryAnimation)
        {
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            float screenHeight  = MediaQuery.of(context).size.height;
            float maxMenuHeight = screenHeight - 2.0f * DropdownConstants._kMenuItemHeight;

            float buttonTop    = this.buttonRect.top;
            float buttonBottom = this.buttonRect.bottom;

            float topLimit    = Mathf.Min(DropdownConstants._kMenuItemHeight, buttonTop);
            float bottomLimit = Mathf.Max(screenHeight - DropdownConstants._kMenuItemHeight, buttonBottom);

            float?selectedItemOffset = this.selectedIndex * DropdownConstants._kMenuItemHeight +
                                       Constants.kMaterialListPadding.top;

            float?menuTop = (buttonTop - selectedItemOffset) -
                            (DropdownConstants._kMenuItemHeight - this.buttonRect.height) / 2.0f;
            float preferredMenuHeight = (this.items.Count * DropdownConstants._kMenuItemHeight) +
                                        Constants.kMaterialListPadding.vertical;

            float menuHeight = Mathf.Min(maxMenuHeight, preferredMenuHeight);

            float?menuBottom = menuTop + menuHeight;

            if (menuTop < topLimit)
            {
                menuTop = Mathf.Min(buttonTop, topLimit);
            }

            if (menuBottom > bottomLimit)
            {
                menuBottom = Mathf.Max(buttonBottom, bottomLimit);
                menuTop    = menuBottom - menuHeight;
            }

            if (this.scrollController == null)
            {
                float scrollOffset = preferredMenuHeight > maxMenuHeight
                    ? Mathf.Max(0.0f, selectedItemOffset ?? 0.0f - (buttonTop - (menuTop ?? 0.0f)))
                    : 0.0f;

                this.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
            }

            Widget menu = new _DropdownMenu <T>(
                route: this,
                padding: this.padding
                );

            if (this.theme != null)
            {
                menu = new Theme(data: this.theme, child: menu);
            }

            return(MediaQuery.removePadding(
                       context: context,
                       removeTop: true,
                       removeBottom: true,
                       removeLeft: true,
                       removeRight: true,
                       child: new Builder(
                           builder: (BuildContext _context) => {
                return new CustomSingleChildLayout(
                    layoutDelegate: new _DropdownMenuRouteLayout <T>(
                        buttonRect: this.buttonRect,
                        menuTop: menuTop ?? 0.0f,
                        menuHeight: menuHeight
                        ),
                    child: menu
                    );
            }
                           )
                       ));
        }
コード例 #5
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            List <Widget> items     = this._enabled ? new List <Widget>(this.widget.items) : new List <Widget>();
            int           hintIndex = 0;

            if (this.widget.hint != null || (!this._enabled && this.widget.disabledHint != null))
            {
                Widget emplacedHint =
                    this._enabled
                        ? this.widget.hint
                        : new DropdownMenuItem <Widget>(child: this.widget.disabledHint ?? this.widget.hint);
                hintIndex = items.Count;
                items.Add(new DefaultTextStyle(
                              style: this._textStyle.copyWith(color: Theme.of(context).hintColor),
                              child: new IgnorePointer(
                                  child: emplacedHint
                                  )
                              ));
            }

            EdgeInsets padding = ButtonTheme.of(context).alignedDropdown
                ? DropdownConstants._kAlignedButtonPadding
                : DropdownConstants._kUnalignedButtonPadding;

            IndexedStack innerItemsWidget = new IndexedStack(
                index: this._enabled ? (this._selectedIndex ?? hintIndex) : hintIndex,
                alignment: Alignment.centerLeft,
                children: items
                );

            Widget result = new DefaultTextStyle(
                style: this._textStyle,
                child: new Container(
                    padding: padding,
                    height: this.widget.isDense ? this._denseButtonHeight : null,
                    child: new Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        mainAxisSize: MainAxisSize.min,
                        children: new List <Widget> {
                this.widget.isExpanded ? new Expanded(child: innerItemsWidget) : (Widget)innerItemsWidget,
                new Icon(Icons.arrow_drop_down,
                         size: this.widget.iconSize,
                         color: this._downArrowColor
                         )
            }
                        )
                    )
                );

            if (!DropdownButtonHideUnderline.at(context))
            {
                float bottom = this.widget.isDense ? 0.0f : 8.0f;
                result = new Stack(
                    children: new List <Widget> {
                    result,
                    new Positioned(
                        left: 0.0f,
                        right: 0.0f,
                        bottom: bottom,
                        child: new Container(
                            height: 1.0f,
                            decoration: new BoxDecoration(
                                border: new Border(
                                    bottom: new BorderSide(color: new Color(0xFFBDBDBD), width: 0.0f))
                                )
                            )
                        )
                }
                    );
            }

            return(new GestureDetector(
                       onTap: this._enabled ? (GestureTapCallback)this._handleTap : null,
                       behavior: HitTestBehavior.opaque,
                       child: result
                       ));
        }
コード例 #6
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
                                   )
                               )
                           )
                       ));
        }
コード例 #7
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            _DropdownRoute <T>    route         = this.widget.route;
            float         unit     = 0.5f / (route.items.Count + 1.5f);
            List <Widget> children = new List <Widget>();

            for (int itemIndex = 0; itemIndex < route.items.Count; ++itemIndex)
            {
                CurvedAnimation opacity;
                if (itemIndex == route.selectedIndex)
                {
                    opacity = new CurvedAnimation(parent: route.animation, curve: new Threshold(0.0f));
                }
                else
                {
                    float start = (0.5f + (itemIndex + 1) * unit).clamp(0.0f, 1.0f);
                    float end   = (start + 1.5f * unit).clamp(0.0f, 1.0f);
                    opacity = new CurvedAnimation(parent: route.animation, curve: new Interval(start, end));
                }

                var index = itemIndex;
                children.Add(new FadeTransition(
                                 opacity: opacity,
                                 child: new InkWell(
                                     child: new Container(
                                         padding: this.widget.padding,
                                         child: route.items[itemIndex]
                                         ),
                                     onTap: () => Navigator.pop(
                                         context,
                                         new _DropdownRouteResult <T>(route.items[index].value)
                                         )
                                     )
                                 ));
            }

            return(new FadeTransition(
                       opacity: this._fadeOpacity,
                       child: new CustomPaint(
                           painter: new _DropdownMenuPainter(
                               color: Theme.of(context).canvasColor,
                               elevation: route.elevation,
                               selectedIndex: route.selectedIndex,
                               resize: this._resize
                               ),
                           child: new Material(
                               type: MaterialType.transparency,
                               textStyle: route.style,
                               child: new ScrollConfiguration(
                                   behavior: new _DropdownScrollBehavior(),
                                   child: new Scrollbar(
                                       child: new ListView(
                                           controller: this.widget.route.scrollController,
                                           padding: Constants.kMaterialListPadding,
                                           itemExtent: DropdownConstants._kMenuItemHeight,
                                           shrinkWrap: true,
                                           children: children
                                           )
                                       )
                                   )
                               )
                           )
                       ));
        }
コード例 #8
0
        InputDecoration _getEffectiveDecoration()
        {
            MaterialLocalizations localizations       = MaterialLocalizations.of(context);
            ThemeData             themeData           = Theme.of(context);
            InputDecoration       effectiveDecoration = (widget.decoration ?? new InputDecoration())
                                                        .applyDefaults(themeData.inputDecorationTheme)
                                                        .copyWith(
                enabled: widget.enabled,
                hintMaxLines: widget.decoration?.hintMaxLines ?? widget.maxLines
                );

            if (effectiveDecoration.counter != null || effectiveDecoration.counterText != null)
            {
                return(effectiveDecoration);
            }

            Widget counter       = null;
            int    currentLength = _currentLength;

            if (effectiveDecoration.counter == null &&
                effectiveDecoration.counterText == null &&
                widget.buildCounter != null)
            {
                bool   isFocused    = _effectiveFocusNode.hasFocus;
                Widget builtCounter = widget.buildCounter(
                    context,
                    currentLength: currentLength,
                    maxLength: widget.maxLength,
                    isFocused: isFocused
                    );
                if (builtCounter != null)
                {
                    counter = builtCounter;
                }

                return(effectiveDecoration.copyWith(counter: counter));
            }

            if (widget.maxLength == null)
            {
                return(effectiveDecoration);
            }

            string counterText = $"{currentLength}";

            if (widget.maxLength > 0)
            {
                counterText += $"/{widget.maxLength}";
                if (_effectiveController.value.text.Length > widget.maxLength)
                {
                    return(effectiveDecoration.copyWith(
                               errorText: effectiveDecoration.errorText ?? "",
                               counterStyle: effectiveDecoration.errorStyle
                               ?? themeData.textTheme.caption.copyWith(color: themeData.errorColor),
                               counterText: counterText
                               ));
                }
            }

            return(effectiveDecoration.copyWith(
                       counterText: counterText
                       ));
        }
コード例 #9
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; // TODO: wait for force press is ready
            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,
                    strutStyle: this.widget.strutStyle,
                    textAlign: this.widget.textAlign,
                    textDirection: this.widget.textDirection,
                    autofocus: this.widget.autofocus,
                    obscureText: this.widget.obscureText,
                    autocorrect: this.widget.autocorrect,
                    maxLines: this.widget.maxLines,
                    minLines: this.widget.minLines,
                    expands: this.widget.expands,
                    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,
                    scrollPhysics: this.widget.scrollPhysics
                    )
                );

            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(),
                               expands: this.widget.expands,
                               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._handleSingleLongTapStart,
                           onSingleLongTapMoveUpdate: this._handleSingleLongTapMoveUpdate,
                           onSingleLongTapEnd: this._handleSingleLongTapEnd,
                           onDoubleTapDown: this._handleDoubleTapDown,
                           onDragSelectionStart: this._handleMouseDragSelectionStart,
                           onDragSelectionUpdate: this._handleMouseDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }
コード例 #10
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 TextSelectionGestureDetector(
                           onTapDown: this._handleTapDown,
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }
コード例 #11
0
ファイル: app_bar.cs プロジェクト: billbai0102/Lollipop-Racer
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            ThemeData     themeData   = Theme.of(context);
            AppBarTheme   appBarTheme = AppBarTheme.of(context);
            ScaffoldState scaffold    = Scaffold.of(context, nullOk: true);
            ModalRoute    parentRoute = ModalRoute.of(context);

            bool hasDrawer      = scaffold?.hasDrawer ?? false;
            bool hasEndDrawer   = scaffold?.hasEndDrawer ?? false;
            bool canPop         = parentRoute?.canPop ?? false;
            bool useCloseButton = parentRoute is PageRoute && ((PageRoute)parentRoute).fullscreenDialog;

            IconThemeData appBarIconTheme = this.widget.iconTheme
                                            ?? appBarTheme.iconTheme
                                            ?? themeData.primaryIconTheme;
            TextStyle centerStyle = this.widget.textTheme?.title
                                    ?? appBarTheme.textTheme?.title
                                    ?? themeData.primaryTextTheme.title;
            TextStyle sideStyle = this.widget.textTheme?.body1
                                  ?? appBarTheme.textTheme?.body1
                                  ?? themeData.primaryTextTheme.body1;

            if (this.widget.toolbarOpacity != 1.0f)
            {
                float opacity =
                    new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget.toolbarOpacity);
                if (centerStyle?.color != null)
                {
                    centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
                }

                if (sideStyle?.color != null)
                {
                    sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity));
                }

                appBarIconTheme = appBarIconTheme.copyWith(
                    opacity: opacity * (appBarIconTheme.opacity ?? 1.0f)
                    );
            }

            Widget leading = this.widget.leading;

            if (leading == null && this.widget.automaticallyImplyLeading)
            {
                if (hasDrawer)
                {
                    leading = new IconButton(
                        icon: new Icon(Icons.menu),
                        onPressed: this._handleDrawerButton,
                        tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
                }
                else
                {
                    if (canPop)
                    {
                        leading = useCloseButton ? (Widget) new CloseButton() : new BackButton();
                    }
                }
            }

            if (leading != null)
            {
                leading = new ConstrainedBox(
                    constraints: BoxConstraints.tightFor(width: AppBarUtils._kLeadingWidth),
                    child: leading);
            }

            Widget title = this.widget.title;

            if (title != null)
            {
                title = new DefaultTextStyle(
                    style: centerStyle,
                    softWrap: false,
                    overflow: TextOverflow.ellipsis,
                    child: title);
            }

            Widget actions = null;

            if (this.widget.actions != null && this.widget.actions.isNotEmpty())
            {
                actions = new Row(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: this.widget.actions);
            }
            else if (hasEndDrawer)
            {
                actions = new IconButton(
                    icon: new Icon(Icons.menu),
                    onPressed: this._handleDrawerButtonEnd,
                    tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
            }

            Widget toolbar = new NavigationToolbar(
                leading: leading,
                middle: title,
                trailing: actions,
                centerMiddle: this.widget._getEffectiveCenterTitle(themeData).Value,
                middleSpacing: this.widget.titleSpacing);

            Widget appBar = new ClipRect(
                child: new CustomSingleChildLayout(
                    layoutDelegate: new _ToolbarContainerLayout(),
                    child: IconTheme.merge(
                        data: appBarIconTheme,
                        child: new DefaultTextStyle(
                            style: sideStyle,
                            child: toolbar)
                        )
                    )
                );

            if (this.widget.bottom != null)
            {
                appBar = new Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: new List <Widget> {
                    new Flexible(
                        child: new ConstrainedBox(
                            constraints: new BoxConstraints(maxHeight: Constants.kToolbarHeight),
                            child: appBar
                            )
                        ),
                    this.widget.bottomOpacity == 1.0f
                            ? (Widget)this.widget.bottom
                            : new Opacity(
                        opacity: new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.widget
                                                                                                  .bottomOpacity),
                        child: this.widget.bottom
                        )
                }
                    );
            }

            if (this.widget.primary)
            {
                appBar = new SafeArea(
                    top: true,
                    child: appBar);
            }

            appBar = new Align(
                alignment: Alignment.topCenter,
                child: appBar);

            if (this.widget.flexibleSpace != null)
            {
                appBar = new Stack(
                    fit: StackFit.passthrough,
                    children: new List <Widget> {
                    this.widget.flexibleSpace,
                    appBar
                }
                    );
            }

            Brightness brightness = this.widget.brightness
                                    ?? appBarTheme.brightness
                                    ?? themeData.primaryColorBrightness;
            SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
                ? SystemUiOverlayStyle.light
                : SystemUiOverlayStyle.dark;

            return(new AnnotatedRegion <SystemUiOverlayStyle>(
                       value: overlayStyle,
                       child: new Material(
                           color: this.widget.backgroundColor
                           ?? appBarTheme.color
                           ?? themeData.primaryColor,
                           elevation: this.widget.elevation
                           ?? appBarTheme.elevation
                           ?? _defaultElevation,
                           child: appBar
                           )));
        }
コード例 #12
0
 public override Widget build(BuildContext context)
 {
     return(new Icon(_getIconData(Theme.of(context).platform)));
 }