Example #1
0
        public override Widget build(BuildContext context)
        {
            MediaQueryData        mediaQuery    = MediaQuery.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            return(new GestureDetector(
                       onTap: () => Navigator.pop(context),
                       child: new AnimatedBuilder(
                           animation: this.widget.route.animation,
                           builder: (BuildContext _context, Widget child) => {
                float animationValue =
                    mediaQuery.accessibleNavigation ? 1.0f : this.widget.route.animation.value;
                return new ClipRect(
                    child: new CustomSingleChildLayout(
                        layoutDelegate: new _ModalBottomSheetLayout(animationValue),
                        child: new BottomSheet(
                            animationController: this.widget.route._animationController,
                            onClosing: () => Navigator.pop(_context),
                            builder: this.widget.route.builder
                            )
                        )
                    );
            }
                           )
                       ));
        }
Example #2
0
        void _handleTap()
        {
            RenderBox  itemBox    = (RenderBox)this.context.findRenderObject();
            Rect       itemRect   = itemBox.localToGlobal(Offset.zero) & itemBox.size;
            EdgeInsets menuMargin = ButtonTheme.of(this.context).alignedDropdown
                ? DropdownConstants._kAlignedMenuMargin
                : DropdownConstants._kUnalignedMenuMargin;

            D.assert(this._dropdownRoute == null);
            this._dropdownRoute = new _DropdownRoute <T>(
                items: this.widget.items,
                buttonRect: menuMargin.inflateRect(itemRect),
                padding: DropdownConstants._kMenuItemPadding,
                selectedIndex: this._selectedIndex ?? 0,
                elevation: this.widget.elevation,
                theme: Theme.of(this.context, shadowThemeOnly: true),
                style: this._textStyle,
                barrierLabel: MaterialLocalizations.of(this.context).modalBarrierDismissLabel
                );

            Navigator.push(this.context, this._dropdownRoute).Then(newValue => {
                _DropdownRouteResult <T> value = newValue as _DropdownRouteResult <T>;
                this._dropdownRoute            = null;
                if (!this.mounted || newValue == null)
                {
                    return;
                }

                if (this.widget.onChanged != null)
                {
                    this.widget.onChanged(value.result);
                }
            });
        }
Example #3
0
        public override Widget build(BuildContext context)
        {
            List <Widget>         items         = new List <Widget>();
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            if (this.handleCut != null)
            {
                items.Add(new FlatButton(child: new Text(localizations.cutButtonLabel), onPressed: this.handleCut));
            }

            if (this.handleCopy != null)
            {
                items.Add(new FlatButton(child: new Text(localizations.copyButtonLabel), onPressed: this.handleCopy));
            }

            if (this.handlePaste != null)
            {
                items.Add(new FlatButton(child: new Text(localizations.pasteButtonLabel), onPressed: this.handlePaste));
            }

            if (this.handleSelectAll != null)
            {
                items.Add(new FlatButton(child: new Text(localizations.selectAllButtonLabel),
                                         onPressed: this.handleSelectAll));
            }

            return(new Material(
                       elevation: 1.0f,
                       child: new Container(
                           color: new Color(0xFFEFEFEF),
                           height: 44.0f, child: new Row(mainAxisSize: MainAxisSize.min, children: items))
                       ));
        }
Example #4
0
        InputDecoration _getEffectiveDecoration()
        {
            MaterialLocalizations localizations       = MaterialLocalizations.of(this.context);
            ThemeData             themeData           = Theme.of(this.context);
            InputDecoration       effectiveDecoration = (this.widget.decoration ?? new InputDecoration())
                                                        .applyDefaults(themeData.inputDecorationTheme)
                                                        .copyWith(
                enabled: this.widget.enabled,
                hintMaxLines: this.widget.decoration?.hintMaxLines ?? this.widget.maxLines
                );

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

            Widget counter;
            int    currentLength = this._effectiveController.value.text.Length;

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

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

            string counterText = $"{currentLength}";

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

            // Handle length exceeds maxLength

            return(effectiveDecoration.copyWith(
                       counterText: counterText
                       ));
        }
Example #5
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            string name         = applicationName ?? material_._defaultApplicationName(context);
            string version      = applicationVersion ?? material_._defaultApplicationVersion(context);
            Widget icon         = applicationIcon ?? material_._defaultApplicationIcon(context);
            var    listChildren = new List <Widget>();
            var    rowChildren  = new List <Widget>();

            if (icon != null)
            {
                rowChildren.Add(new IconTheme(data: Theme.of(context).iconTheme, child: icon));
            }

            rowChildren.Add(new Expanded(
                                child: new Padding(
                                    padding: EdgeInsets.symmetric(horizontal: 24.0f),
                                    child: new ListBody(
                                        children: new List <Unity.UIWidgets.widgets.Widget>()
            {
                new Text(name, style: Theme.of(context).textTheme.headline5),
                new Text(version, style: Theme.of(context).textTheme.bodyText2),
                new Container(height: 18.0f),
                new Text(applicationLegalese ?? "", style: Theme.of(context).textTheme.caption)
            }
                                        )
                                    )
                                ));
            listChildren.Add(new Row(
                                 crossAxisAlignment: CrossAxisAlignment.start,
                                 children: rowChildren
                                 )
                             );
            listChildren.AddRange(children);
            return(new AlertDialog(
                       content: new ListBody(
                           children: listChildren
                           ),
                       actions: new List <Unity.UIWidgets.widgets.Widget>()
            {
                new FlatButton(
                    child: new Text(MaterialLocalizations.of(context).viewLicensesButtonLabel),
                    onPressed: () => {
                    material_.showLicensePage(
                        context: context,
                        applicationName: applicationName,
                        applicationVersion: applicationVersion,
                        applicationIcon: applicationIcon,
                        applicationLegalese: applicationLegalese
                        );
                }
                    ),
                new FlatButton(
                    child: new Text(MaterialLocalizations.of(context).closeButtonLabel),
                    onPressed: () => { Navigator.pop <object>(context); }
                    )
            },
                       scrollable: true
                       ));
        }
Example #6
0
        void _handleTap()
        {
            RenderBox          itemBox       = (RenderBox)context.findRenderObject();
            Rect               itemRect      = itemBox.localToGlobal(Offset.zero) & itemBox.size;
            TextDirection      textDirection = Directionality.of(context);
            EdgeInsetsGeometry menuMargin    = ButtonTheme.of(context).alignedDropdown
                ? material_._kAlignedMenuMargin
                : material_._kUnalignedMenuMargin;

            List <_MenuItem <T> > menuItems = new List <_MenuItem <T> >(new _MenuItem <T> [widget.items.Count]);

            for (int index = 0; index < widget.items.Count; index += 1)
            {
                var pindex = index;
                menuItems[pindex] = new _MenuItem <T>(
                    item: widget.items[pindex],
                    onLayout: (Size size) => {
                    if (_dropdownRoute == null)
                    {
                        return;
                    }

                    _dropdownRoute.itemHeights[pindex] = size.height;
                }
                    );
            }

            D.assert(_dropdownRoute == null);
            _dropdownRoute = new _DropdownRoute <T>(
                items: menuItems,
                buttonRect: menuMargin.resolve(textDirection).inflateRect(itemRect),
                padding: material_._kMenuItemPadding.resolve(textDirection),
                selectedIndex: _selectedIndex ?? 0,
                elevation: widget.elevation,
                theme: Theme.of(context, shadowThemeOnly: true),
                style: _textStyle,
                barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
                itemHeight: widget.itemHeight,
                dropdownColor: widget.dropdownColor
                );

            Navigator.push <T>(context, _dropdownRoute).then(newValue => {
                _DropdownRouteResult <T> value = newValue as _DropdownRouteResult <T>;
                _removeDropdownRoute();
                if (!mounted || newValue == null)
                {
                    return;
                }

                if (widget.onChanged != null)
                {
                    widget.onChanged(value.result);
                }
            });
            if (widget.onTap != null)
            {
                widget.onTap();
            }
        }
Example #7
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            string name    = widget.applicationName ?? material_._defaultApplicationName(context);
            string version = widget.applicationVersion ?? material_._defaultApplicationVersion(context);
            Widget icon    = widget.applicationIcon ?? material_._defaultApplicationIcon(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            var list = new List <Widget>();

            list.Add(new Text(name, style: Theme.of(context).textTheme.headline5, textAlign: TextAlign.center));

            if (icon != null)
            {
                list.Add(new IconTheme(data: Theme.of(context).iconTheme, child: icon));
            }

            list.Add(new Text(version, style: Theme.of(context).textTheme.bodyText2, textAlign: TextAlign.center));
            list.Add(new Container(height: 18.0f));
            list.Add(new Text(widget.applicationLegalese ?? "", style: Theme.of(context).textTheme.caption,
                              textAlign: TextAlign.center));
            list.Add(new Container(height: 18.0f));
            list.Add(new Text("Powered by Flutter", style: Theme.of(context).textTheme.bodyText2,
                              textAlign: TextAlign.center));
            list.Add(new Container(height: 24.0f));
            list.AddRange(_licenses);
            if (!_loaded)
            {
                list.Add(new Padding(
                             padding: EdgeInsets.symmetric(vertical: 24.0f),
                             child: new Center(
                                 child: new CircularProgressIndicator()
                                 )
                             ));
            }

            return(new Scaffold(
                       appBar: new AppBar(
                           title: new Text(localizations.licensesPageTitle)
                           ),
                       // All of the licenses page text is English. We don"t want localized text
                       // or text direction.
                       body: Localizations.overrides(
                           locale: new Locale("en", "US"),
                           context: context,
                           child: new DefaultTextStyle(
                               style: Theme.of(context).textTheme.caption,
                               child: new SafeArea(
                                   bottom: false,
                                   child: new Scrollbar(
                                       child: new ListView(
                                           padding: EdgeInsets.symmetric(horizontal: 8.0f, vertical: 12.0f),
                                           children: list
                                           )
                                       )
                                   )
                               )
                           )
                       ));
        }
Example #8
0
 public override Widget build(BuildContext context)
 {
     return(new IconButton(
                icon: new BackButtonIcon(),
                color: this.color,
                tooltip: MaterialLocalizations.of(context).backButtonTooltip,
                onPressed: () => { Navigator.maybePop(context); }));
 }
Example #9
0
 public override Widget build(BuildContext context)
 {
     D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
     return(new IconButton(
                icon: new Icon(Icons.close),
                tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
                onPressed: () => { Navigator.maybePop(context); }));
 }
Example #10
0
 public override void didChangeDependencies()
 {
     base.didChangeDependencies();
     this.localizations = MaterialLocalizations.of(this.context);
     if (!this._announcedInitialDate)
     {
         this._announcedInitialDate = true;
     }
 }
Example #11
0
        Widget _buildVerticalControls()
        {
            if (widget.controlsBuilder != null)
            {
                return(widget.controlsBuilder(
                           context,
                           onStepContinue: widget.onStepContinue,
                           onStepCancel: widget.onStepCancel
                           ));
            }

            Color cancelColor = null;

            switch (Theme.of(context).brightness)
            {
            case Brightness.light:
                cancelColor = Colors.black54;
                break;

            case Brightness.dark:
                cancelColor = Colors.white70;
                break;
            }

            D.assert(cancelColor != null);

            ThemeData             themeData     = Theme.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            return(new Container(
                       margin: EdgeInsets.only(top: 16.0f),
                       child: new ConstrainedBox(
                           constraints: BoxConstraints.tightFor(height: 48.0f),
                           child: new Row(
                               children: new List <Widget> {
                new FlatButton(
                    onPressed: widget.onStepContinue,
                    color: _isDark() ? themeData.backgroundColor : themeData.primaryColor,
                    textColor: Colors.white,
                    textTheme: ButtonTextTheme.normal,
                    child: new Text(localizations.continueButtonLabel)
                    ),
                new Container(
                    margin: EdgeInsets.only(8.0f),
                    child: new FlatButton(
                        onPressed: widget.onStepCancel,
                        textColor: cancelColor,
                        textTheme: ButtonTextTheme.normal,
                        child: new Text(localizations.cancelButtonLabel)
                        )
                    )
            }
                               )
                           )
                       ));
        }
        public override Widget build(BuildContext context)
        {
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            List <Widget>         items         = new List <Widget>();

            if (widget.handleCut != null)
            {
                items.Add(_getItem(widget.handleCut, localizations.cutButtonLabel));
            }

            if (widget.handleCopy != null)
            {
                items.Add(_getItem(widget.handleCopy, localizations.copyButtonLabel));
            }

            if (widget.handlePaste != null)
            {
                items.Add(_getItem(widget.handlePaste, localizations.pasteButtonLabel));
            }

            if (widget.handleSelectAll != null)
            {
                items.Add(_getItem(widget.handleSelectAll, localizations.selectAllButtonLabel));
            }

            if (items.isEmpty())
            {
                return(new Container(width: 0.0f, height: 0.0f));
            }

            items.Insert(0, new IconButton(
                             icon: new Icon(_overflowOpen ? Icons.arrow_back : Icons.more_vert),
                             onPressed: () => { setState(() => { _overflowOpen = !_overflowOpen; }); },
                             tooltip: _overflowOpen
                        ? localizations.backButtonTooltip
                        : localizations.moreButtonTooltip
                             )
                         );

            return(new _TextSelectionToolbarContainer(
                       key: _containerKey,
                       overflowOpen: _overflowOpen,
                       child: new AnimatedSize(
                           vsync: this,
                           duration: new TimeSpan(0, 0, 0, 0, 140),
                           child: new Material(
                               elevation: 1.0f,
                               child: new _TextSelectionToolbarItems(
                                   isAbove: widget.isAbove,
                                   overflowOpen: _overflowOpen,
                                   children: items)
                               )
                           )
                       ));
        }
Example #13
0
        public string format(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            return(localizations.formatTimeOfDay(
                       this,
                       alwaysUse24HourFormat: MediaQuery.of(context).alwaysUse24HourFormat
                       ));
        }
Example #14
0
 public static IPromise <object> showModalBottomSheet <T>(
     BuildContext context,
     WidgetBuilder builder
     )
 {
     D.assert(context != null);
     D.assert(builder != null);
     D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
     return(Navigator.push(context, new _ModalBottomSheetRoute <T>(
                               builder: builder,
                               theme: Theme.of(context, shadowThemeOnly: true),
                               barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel
                               )));
 }
Example #15
0
 public override void didChangeDependencies()
 {
     base.didChangeDependencies();
     _localizations = MaterialLocalizations.of(context);
     _textDirection = Directionality.of(context);
     if (!_announcedInitialDate)
     {
         _announcedInitialDate = true;
         // SemanticsService.announce(
         //   _localizations.formatFullDate(_selectedDate),
         //   _textDirection,
         // );
     }
 }
Example #16
0
 public override Widget build(BuildContext context)
 {
     D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
     return(this.widget.child != null
         ? (Widget) new InkWell(
                onTap: this.showButtonMenu,
                child: this.widget.child
                )
         : new IconButton(
                icon: this.widget.icon ?? this._getIcon(Theme.of(context).platform),
                padding: this.widget.padding,
                tooltip: this.widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
                onPressed: this.showButtonMenu
                ));
 }
Example #17
0
        int _computeFirstDayOffset(int year, int month, MaterialLocalizations localizations)
        {
            int weekdayFromMonday = new DateTime(year, month, 1).DayOfWeek.GetHashCode();

            if (weekdayFromMonday == 0)
            {
                weekdayFromMonday = 7;
            }

            weekdayFromMonday--;

            int firstDayOfWeekFromSunday = localizations.firstDayOfWeekIndex;
            int firstDayOfWeekFromMonday = (firstDayOfWeekFromSunday - 1) % 7;

            return((weekdayFromMonday - firstDayOfWeekFromMonday) % 7);
        }
Example #18
0
        List <Widget> _getDayHeaders(TextStyle headerStyle, MaterialLocalizations localizations)
        {
            List <Widget> result = new List <Widget>();

            for (int i = localizations.firstDayOfWeekIndex; true; i = (i + 1) % 7)
            {
                string weekday = localizations.narrowWeekdays[i];
                result.Add(new Center(child: new Text(weekday, style: headerStyle)));
                if (i == (localizations.firstDayOfWeekIndex + 6) % 7)
                {
                    break;
                }
            }

            return(result);
        }
        public static int firstDayOffset(int year, int month, MaterialLocalizations localizations)
        {
            // 0-based day of week for the month and year, with 0 representing Monday.
            int weekdayFromMonday = (int)((new DateTime(year, month, 1)).DayOfWeek) - 1;

            // 0-based start of week depending on the locale, with 0 representing Sunday.
            int firstDayOfWeekIndex = localizations.firstDayOfWeekIndex;

            // firstDayOfWeekIndex recomputed to be Monday-based, in order to compare with
            // weekdayFromMonday.
            firstDayOfWeekIndex = (firstDayOfWeekIndex - 1) % 7;

            // Number of days between the first day of week appearing on the calendar,
            // and the day corresponding to the first of the month.
            return((weekdayFromMonday - firstDayOfWeekIndex) % 7);
        }
Example #20
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            _DropdownRoute <T>    route         = widget.route;
            List <Widget>         children      = new List <Widget>();

            for (int itemIndex = 0; itemIndex < route.items.Count; ++itemIndex)
            {
                children.Add(new _DropdownMenuItemButton <T>(
                                 route: widget.route,
                                 padding: widget.padding,
                                 buttonRect: widget.buttonRect,
                                 constraints: widget.constraints,
                                 itemIndex: itemIndex
                                 ));
            }

            return(new FadeTransition(
                       opacity: _fadeOpacity,
                       child: new CustomPaint(
                           painter: new _DropdownMenuPainter(
                               color: widget.dropdownColor ?? Theme.of(context).canvasColor,
                               elevation: route.elevation,
                               selectedIndex: route.selectedIndex,
                               resize: _resize,
                               getSelectedItemOffset: () => route.getItemOffset(route.selectedIndex ?? 0)
                               ),
                           child: new Material(
                               type: MaterialType.transparency,
                               textStyle: route.style,
                               child: new ScrollConfiguration(
                                   behavior: new _DropdownScrollBehavior(),
                                   child: new Scrollbar(
                                       child: new ListView(
                                           controller: widget.route.scrollController,
                                           padding: material_.kMaterialListPadding,
                                           shrinkWrap: true,
                                           children: children
                                           )
                                       )
                                   )
                               )
                           )
                       ));
        }
Example #21
0
 public override Widget build(BuildContext context)
 {
     D.assert(material_.debugCheckHasMaterialLocalizations(context));
     return(new IconButton(
                icon: new Icon(Icons.close),
                color: color,
                tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
                onPressed: () => {
         if (onPressed != null)
         {
             onPressed();
         }
         else
         {
             Navigator.maybePop(context);
         }
     }));
 }
Example #22
0
        public static ThemeData of(BuildContext context, bool shadowThemeOnly = false)
        {
            _InheritedTheme inheritedTheme = context.dependOnInheritedWidgetOfExactType <_InheritedTheme>();

            if (shadowThemeOnly)
            {
                if (inheritedTheme == null || inheritedTheme.theme.isMaterialAppTheme)
                {
                    return(null);
                }

                return(inheritedTheme.theme.data);
            }

            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            ScriptCategory        category      = ScriptCategory.englishLike;
            ThemeData             theme         = inheritedTheme?.theme?.data ?? _kFallbackTheme;

            return(ThemeData.localize(theme, theme.typography.geometryThemeFor(category)));
        }
Example #23
0
        public override void didChangeDependencies()
        {
            base.didChangeDependencies();
            if (_selectedDate != null)
            {
                MaterialLocalizations localizations = MaterialLocalizations.of(context);
                _inputText = localizations.formatCompactDate(_selectedDate.Value);
                TextEditingValue textEditingValue = _controller.value.copyWith(text: _inputText);

                if (widget.autofocus && !_autoSelected)
                {
                    textEditingValue = textEditingValue.copyWith(selection: new TextSelection(
                                                                     baseOffset: 0,
                                                                     extentOffset: _inputText.Length
                                                                     ));
                    _autoSelected = true;
                }

                _controller.value = textEditingValue;
            }
        }
Example #24
0
 public override Widget build(BuildContext context)
 {
     D.assert(material_.debugCheckHasMaterial(context));
     D.assert(material_.debugCheckHasMaterialLocalizations(context));
     return(new ListTile(
                leading: icon,
                title: child ?? new Text(MaterialLocalizations.of(context).aboutListTileTitle(
                                             applicationName ?? material_._defaultApplicationName(context)
                                             )),
                dense: dense,
                onTap: () => {
         material_.showAboutDialog(
             context: context,
             applicationName: applicationName,
             applicationVersion: applicationVersion,
             applicationIcon: applicationIcon,
             applicationLegalese: applicationLegalese,
             children: aboutBoxChildren
             );
     }
                ));
 }
        InputDecoration _getEffectiveDecoration()
        {
            MaterialLocalizations localizations       = MaterialLocalizations.of(this.context);
            InputDecoration       effectiveDecoration = (this.widget.decoration ?? new InputDecoration())
                                                        .applyDefaults(Theme.of(this.context).inputDecorationTheme)
                                                        .copyWith(
                enabled: this.widget.enabled
                );

            if (!this.needsCounter)
            {
                return(effectiveDecoration);
            }

            int    currentLength = this._effectiveController.value.text.Length;
            string counterText   = $"{currentLength}";


            if (this.widget.maxLength != TextField.noMaxLength)
            {
                counterText += $"/{this.widget.maxLength}";
            }

            // Handle length exceeds maxLength
            if (this._effectiveController.value.text.Length > this.widget.maxLength)
            {
                ThemeData themeData = Theme.of(this.context);
                return(effectiveDecoration.copyWith(
                           errorText: effectiveDecoration.errorText ?? "",
                           counterStyle: effectiveDecoration.errorStyle
                           ?? themeData.textTheme.caption.copyWith(color: themeData.errorColor),
                           counterText: counterText
                           ));
            }

            return(effectiveDecoration.copyWith(
                       counterText: counterText
                       ));
        }
Example #26
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            if (widget.child != null)
            {
                return(new Tooltip(
                           message: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
                           child: new InkWell(
                               onTap: widget.enabled ? showButtonMenu : (GestureTapCallback)null,
                               canRequestFocus: widget.enabled,
                               child: widget.child
                               )
                           ));
            }


            return(new IconButton(
                       icon: widget.icon ?? _getIcon(Theme.of(context).platform),
                       padding: widget.padding,
                       tooltip: widget.tooltip ?? MaterialLocalizations.of(context).showMenuTooltip,
                       onPressed: widget.enabled ? showButtonMenu : (VoidCallback)null
                       ));
        }
Example #27
0
        public override Widget build(BuildContext context)
        {
            ThemeData   theme          = Theme.of(context);
            ColorScheme colorScheme    = theme.colorScheme;
            TextStyle   dayHeaderStyle = theme.textTheme.caption?.apply(
                color: colorScheme.onSurface.withOpacity(0.60f)
                );
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            List <Widget>
            labels = _getDayHeaders(dayHeaderStyle, localizations);

            return(new Padding(
                       padding: EdgeInsets.symmetric(horizontal: material_._monthPickerHorizontalPadding),
                       child:
                       GridView.custom(
                           shrinkWrap: true,
                           gridDelegate: material_._dayPickerGridDelegate,
                           childrenDelegate: new SliverChildListDelegate(
                               labels,
                               addRepaintBoundaries: false
                               )
                           )
                       ));
        }
        List <Widget> _createTiles()
        {
            MaterialLocalizations localizations = MaterialLocalizations.of(this.context);

            D.assert(localizations != null);
            ThemeData themeData = Theme.of(this.context);
            Color     themeColor;

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

            case Brightness.dark:
                themeColor = themeData.accentColor;
                break;

            default:
                throw new Exception("Unknown brightness: " + themeData.brightness);
            }

            ColorTween colorTween;

            switch (this.widget.type)
            {
            case BottomNavigationBarType.fix:
                colorTween = new ColorTween(
                    begin: this.widget.unselectedItemColor ?? themeData.textTheme.caption.color,
                    end: this.widget.selectedItemColor ?? this.widget.fixedColor ?? themeColor
                    );
                break;

            case BottomNavigationBarType.shifting:
                colorTween = new ColorTween(
                    begin: this.widget.unselectedItemColor ?? Colors.white,
                    end: this.widget.selectedItemColor ?? Colors.white
                    );
                break;

            default:
                throw new UIWidgetsError($"Unknown bottom navigation bar type: {this.widget.type}");
            }

            List <Widget> tiles = new List <Widget>();

            for (int i = 0; i < this.widget.items.Count; i++)
            {
                int index = i;
                tiles.Add(new _BottomNavigationTile(
                              this.widget.type,
                              this.widget.items[i],
                              this._animations[i],
                              this.widget.iconSize,
                              selectedFontSize: this.widget.selectedFontSize,
                              unselectedFontSize: this.widget.unselectedFontSize,
                              onTap: () => {
                    if (this.widget.onTap != null)
                    {
                        this.widget.onTap(index);
                    }
                },
                              colorTween: colorTween,
                              flex: this._evaluateFlex(this._animations[i]),
                              selected: i == this.widget.currentIndex,
                              showSelectedLabels: this.widget.showSelectedLabels,
                              showUnselectedLabels: this.widget.showUnselectedLabels,
                              indexLabel: localizations.tabLabel(tabIndex: i + 1, tabCount: this.widget.items.Count)
                              ));
            }

            return(tiles);
        }
Example #29
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)
                        )
                    )
            }
                           )
                       ));
        }
Example #30
0
 public override void didChangeDependencies()
 {
     base.didChangeDependencies();
     this.localizations = MaterialLocalizations.of(this.context);
 }