예제 #1
0
        public static IEnumerable <Widget> divideTiles(BuildContext context = null, IEnumerable <Widget> tiles = null,
                                                       Color color          = null)
        {
            D.assert(tiles != null);
            D.assert(color != null || context != null);

            IEnumerator <Widget> enumerator = tiles.GetEnumerator();
            List <Widget>        result     = new List <Widget> {
            };

            Decoration decoration = new BoxDecoration(
                border: new Border(
                    bottom: Divider.createBorderSide(context, color: color)
                    )
                );

            Widget tile = enumerator.Current;

            while (enumerator.MoveNext())
            {
                result.Add(new DecoratedBox(
                               position: DecorationPosition.foreground,
                               decoration: decoration,
                               child: tile
                               ));
                tile = enumerator.Current;
            }

            return(result);
        }
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterial(context));
            ThemeData theme           = Theme.of(context);
            float     statusBarHeight = MediaQuery.of(context).padding.top;

            return(new Container(
                       height: statusBarHeight + DrawerHeaderUtils._kDrawerHeaderHeight,
                       margin: this.margin,
                       decoration: new BoxDecoration(
                           border: new Border(
                               bottom: Divider.createBorderSide(context)
                               )
                           ),
                       child: new AnimatedContainer(
                           padding: this.padding.add(EdgeInsets.only(top: statusBarHeight)),
                           decoration: this.decoration,
                           duration: this.duration,
                           curve: this.curve,
                           child: this.child == null
                        ? null
                        : new DefaultTextStyle(
                               style: theme.textTheme.body2,
                               child: MediaQuery.removePadding(
                                   context: context,
                                   removeTop: true,
                                   child: this.child)
                               )
                           )
                       ));
        }
예제 #3
0
        public override Widget build(BuildContext context)
        {
            DividerThemeData dividerTheme = DividerTheme.of(context);
            float            width        = this.width ?? dividerTheme.space ?? 16.0f;
            float            thickness    = this.thickness ?? dividerTheme.thickness ?? 0.0f;
            float            indent       = this.indent ?? dividerTheme.indent ?? 0.0f;
            float            endIndent    = this.endIndent ?? dividerTheme.endIndent ?? 0.0f;

            return(new SizedBox(
                       width: width,
                       child: new Center(
                           child: new Container(
                               width: thickness,
                               margin: EdgeInsetsDirectional.only(top: indent,
                                                                  bottom: endIndent),
                               decoration: new BoxDecoration(
                                   border: new Border(
                                       left: Divider.createBorderSide(context, color: color, width: thickness)
                                       )
                                   )
                               )
                           )
                       ));
        }
예제 #4
0
        public override Widget build(BuildContext context)
        {
            this._removeEmptyGaps();

            List <Widget> widgets = new List <Widget>();
            List <Widget> slices  = new List <Widget>();
            int           i;

            for (i = 0; i < this._children.Count; i++)
            {
                if (this._children[i] is MaterialGap)
                {
                    D.assert(slices.isNotEmpty());
                    widgets.Add(
                        new Container(
                            decoration: new BoxDecoration(
                                color: Theme.of(context).cardColor,
                                borderRadius: this._borderRadius(i - 1, widgets.isEmpty(), false),
                                shape: BoxShape.rectangle),
                            child: new ListBody(
                                mainAxis: this.widget.mainAxis,
                                children: slices)
                            )
                        );

                    slices = new List <Widget>();
                    widgets.Add(
                        new SizedBox(
                            width: this.widget.mainAxis == Axis.horizontal ? this._getGapSize(i) : (float?)null,
                            height: this.widget.mainAxis == Axis.vertical ? this._getGapSize(i) : (float?)null)
                        );
                }
                else
                {
                    MaterialSlice slice = (MaterialSlice)this._children[i];
                    Widget        child = slice.child;

                    if (this.widget.hasDividers)
                    {
                        bool hasTopDivider    = this._willNeedDivider(i - 1);
                        bool hasBottomDivider = this._willNeedDivider(i + 1);

                        Border     border;
                        BorderSide divider = Divider.createBorderSide(
                            context,
                            width: 0.5f
                            );

                        if (i == 0)
                        {
                            border = new Border(
                                bottom: hasBottomDivider ? divider : BorderSide.none);
                        }
                        else if (i == this._children.Count - 1)
                        {
                            border = new Border(
                                top: hasTopDivider ? divider : BorderSide.none);
                        }
                        else
                        {
                            border = new Border(
                                top: hasTopDivider ? divider : BorderSide.none,
                                bottom: hasBottomDivider ? divider : BorderSide.none
                                );
                        }

                        D.assert(border != null);

                        child = new AnimatedContainer(
                            key: new _MergeableMaterialSliceKey(this._children[i].key),
                            decoration: new BoxDecoration(border: border),
                            duration: ThemeUtils.kThemeAnimationDuration,
                            curve: Curves.fastOutSlowIn,
                            child: child
                            );
                    }

                    slices.Add(
                        new Material(
                            type: MaterialType.transparency,
                            child: child
                            )
                        );
                }
            }

            if (slices.isNotEmpty())
            {
                widgets.Add(
                    new Container(
                        decoration: new BoxDecoration(
                            color: Theme.of(context).cardColor,
                            borderRadius: this._borderRadius(i - 1, widgets.isEmpty(), true),
                            shape: BoxShape.rectangle
                            ),
                        child: new ListBody(
                            mainAxis: this.widget.mainAxis,
                            children: slices
                            )
                        )
                    );
                slices = new List <Widget>();
            }

            return(new _MergeableMaterialListBody(
                       mainAxis: this.widget.mainAxis,
                       boxShadows: ShadowConstants.kElevationToShadow[this.widget.elevation],
                       items: this._children,
                       children: widgets
                       ));
        }
예제 #5
0
        public override Widget build(BuildContext context)
        {
            D.assert(!_debugInteractive || material_.debugCheckHasMaterial(context));

            ThemeData     theme = Theme.of(context);
            BoxDecoration _kSelectedDecoration = new BoxDecoration(
                border: new Border(bottom: Divider.createBorderSide(context, width: dividerThickness)),
                // The backgroundColor has to be transparent so you can see the ink on the material
                color: (Theme.of(context).brightness == Brightness.light) ? _grey100Opacity : _grey300Opacity
                );
            BoxDecoration _kUnselectedDecoration = new BoxDecoration(
                border: new Border(bottom: Divider.createBorderSide(context, width: dividerThickness))
                );

            bool displayCheckboxColumn =
                showCheckboxColumn && rows.Any((DataRow row) => row.onSelectChanged != null);
            bool allChecked = displayCheckboxColumn &&
                              !rows.Any((DataRow row) => row.onSelectChanged != null && !row.selected);

            List <TableColumnWidth> tableColumns =
                new List <TableColumnWidth>(new TableColumnWidth[columns.Count + (displayCheckboxColumn ? 1 : 0)]);

            List <TableRow> tableRows = LinqUtils <TableRow, int> .SelectList(Enumerable.Range(0, rows.Count + 1), (index) => {
                return(new TableRow(
                           key: index == 0 ? _headingRowKey : rows[index - 1].key,
                           decoration: index > 0 && rows[index - 1].selected
                            ? _kSelectedDecoration
                            : _kUnselectedDecoration,
                           children: new List <Widget>(new Widget[tableColumns.Count])
                           ));
            });

            int rowIndex;

            int displayColumnIndex = 0;

            if (displayCheckboxColumn)
            {
                tableColumns[0]          = new FixedColumnWidth(horizontalMargin + Checkbox.width + horizontalMargin / 2.0f);
                tableRows[0].children[0] = _buildCheckbox(
                    color: theme.accentColor,
                    isChecked: allChecked,
                    onCheckboxChanged: _check => _handleSelectAll(_check ?? false)
                    );
                rowIndex = 1;
                foreach (DataRow row in rows)
                {
                    tableRows[rowIndex].children[0] = _buildCheckbox(
                        color: theme.accentColor,
                        isChecked: row.selected,
                        onRowTap: () => {
                        if (row.onSelectChanged != null)
                        {
                            row.onSelectChanged(!row.selected);
                        }
                    },
                        onCheckboxChanged: _select => row.onSelectChanged(_select ?? false)
                        );
                    rowIndex += 1;
                }

                displayColumnIndex += 1;
            }

            for (int dataColumnIndex = 0; dataColumnIndex < columns.Count; dataColumnIndex += 1)
            {
                DataColumn column = columns[dataColumnIndex];

                float paddingStart;
                if (dataColumnIndex == 0 && displayCheckboxColumn)
                {
                    paddingStart = horizontalMargin / 2.0f;
                }
                else if (dataColumnIndex == 0 && !displayCheckboxColumn)
                {
                    paddingStart = horizontalMargin;
                }
                else
                {
                    paddingStart = columnSpacing / 2.0f;
                }

                float paddingEnd;
                if (dataColumnIndex == columns.Count - 1)
                {
                    paddingEnd = horizontalMargin;
                }
                else
                {
                    paddingEnd = columnSpacing / 2.0f;
                }

                EdgeInsetsDirectional padding = EdgeInsetsDirectional.only(
                    start: paddingStart,
                    end: paddingEnd
                    );
                if (dataColumnIndex == _onlyTextColumn)
                {
                    tableColumns[displayColumnIndex] = new IntrinsicColumnWidth(flex: 1.0f);
                }
                else
                {
                    tableColumns[displayColumnIndex] = new IntrinsicColumnWidth();
                }

                var currentColumnIndex = dataColumnIndex;
                tableRows[0].children[displayColumnIndex] = _buildHeadingCell(
                    context: context,
                    padding: padding,
                    label: column.label,
                    tooltip: column.tooltip,
                    numeric: column.numeric,
                    onSort: column.onSort != null
                        ? () => column.onSort(currentColumnIndex, sortColumnIndex != currentColumnIndex || !sortAscending)
                        : (VoidCallback)null,
                    sorted: dataColumnIndex == sortColumnIndex,
                    ascending: sortAscending
                    );
                rowIndex = 1;
                foreach (DataRow row in rows)
                {
                    DataCell cell   = row.cells[dataColumnIndex];
                    var      curRow = row;
                    tableRows[rowIndex].children[displayColumnIndex] = _buildDataCell(
                        context: context,
                        padding: padding,
                        label: cell.child,
                        numeric: column.numeric,
                        placeholder: cell.placeholder,
                        showEditIcon: cell.showEditIcon,
                        onTap: cell.onTap,
                        onSelectChanged: () => {
                        if (curRow.onSelectChanged != null)
                        {
                            curRow.onSelectChanged(!curRow.selected);
                        }
                    });
                    rowIndex += 1;
                }

                displayColumnIndex += 1;
            }
            return(new Table(
                       columnWidths: LinqUtils <int, TableColumnWidth> .SelectDictionary(tableColumns, ((TableColumnWidth x) => tableColumns.IndexOf(x))),
                       children: tableRows
                       ));
        }