Пример #1
0
        static Widget _buildButtons(List <ActionSheetItem> items)
        {
            if (items == null || items.Count <= 0)
            {
                return(new Container());
            }

            List <Widget> widgets            = new List <Widget>();
            List <Widget> normalWidgets      = new List <Widget>();
            List <Widget> destructiveWidgets = new List <Widget>();
            List <Widget> cancelWidgets      = new List <Widget>();

            items.ForEach(item => {
                Color titleColor;
                switch (item.type)
                {
                case ActionType.normal:
                    titleColor = CColors.TextBody;
                    break;

                case ActionType.cancel:
                    titleColor = CColors.Cancel;
                    break;

                case ActionType.destructive:
                    titleColor = CColors.Error;
                    break;

                default:
                    titleColor = CColors.TextBody;
                    break;
                }

                Widget widget = new GestureDetector(
                    onTap: () => {
                    ActionSheetUtils.hiddenModalPopup();
                    item.onTap?.Invoke();
                },
                    child: new Container(
                        alignment: Alignment.center,
                        height: 49,
                        color: CColors.White,
                        child: new Text(
                            data: item.title,
                            style: CTextStyle.PLargeBody.copyWith(color: titleColor)
                            )
                        )
                    );
                var divider = new CustomDivider(
                    height: 1,
                    color: CColors.Separator2
                    );
                if (item.type == ActionType.destructive)
                {
                    destructiveWidgets.Add(item: widget);
                    destructiveWidgets.Add(item: divider);
                }
                else if (item.type == ActionType.cancel)
                {
                    cancelWidgets.Add(new CustomDivider(height: 4, color: CColors.Separator2));
                    cancelWidgets.Add(item: widget);
                }
                else
                {
                    normalWidgets.Add(item: widget);
                    normalWidgets.Add(item: divider);
                }
            });
            widgets.AddRange(collection: normalWidgets);
            widgets.AddRange(collection: destructiveWidgets);
            widgets.AddRange(collection: cancelWidgets);
            return(new Column(
                       children: widgets
                       ));
        }
Пример #2
0
        static Widget _buildButtons(List <ActionSheetItem> items)
        {
            if (items.isNullOrEmpty())
            {
                return(new Container());
            }

            List <Widget> widgets            = new List <Widget>();
            List <Widget> normalWidgets      = new List <Widget>();
            List <Widget> destructiveWidgets = new List <Widget>();
            List <Widget> cancelWidgets      = new List <Widget>();

            items.ForEach(item => {
                Color titleColor;
                switch (item.type)
                {
                case ActionType.normal:
                    titleColor = CColors.TextBody;
                    break;

                case ActionType.cancel:
                    titleColor = CColors.Cancel;
                    break;

                case ActionType.destructive:
                    titleColor = CColors.Error;
                    break;

                default:
                    titleColor = CColors.TextBody;
                    break;
                }

                Widget widget = new GestureDetector(
                    onTap: () => {
                    ActionSheetUtils.hiddenModalPopup();
                    item.onTap?.Invoke();
                },
                    child: new Container(
                        alignment: Alignment.center,
                        height: 49,
                        padding: EdgeInsets.symmetric(horizontal: 16),
                        color: CColors.White,
                        child: new Text(
                            data: item.title,
                            style: CTextStyle.PLargeBody.copyWith(color: titleColor),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis
                            )
                        )
                    );
                var divider = new CustomDivider(
                    height: 1,
                    color: CColors.Separator2
                    );
                if (item.type == ActionType.destructive)
                {
                    destructiveWidgets.Add(item: widget);
                    destructiveWidgets.Add(item: divider);
                }
                else if (item.type == ActionType.cancel)
                {
                    cancelWidgets.Add(new CustomDivider(height: 4, color: CColors.Separator2));
                    cancelWidgets.Add(item: widget);
                }
                else
                {
                    normalWidgets.Add(item: widget);
                    normalWidgets.Add(item: divider);
                }
            });
            widgets.AddRange(collection: normalWidgets);
            widgets.AddRange(collection: destructiveWidgets);
            widgets.AddRange(collection: cancelWidgets);
            if (widgets.isNotEmpty() && widgets.last() is CustomDivider)
            {
                widgets.removeLast();
            }

            return(new Column(
                       children: widgets
                       ));
        }