Skip to content

Constructor of Border: Border.symmetric #45524

Closed

Description

@hoshinokanade

Use case

Currently, Border has 3 constructors:

  • Border from 4 (top, right, bottom, left) BorderSide
  • Border.fromBorderSide from single BorderSide that apply to all sides (top, right, bottom, left)
  • Border.all factory that internally instantiate a BorderSide and call Border.fromBorderSide

I suggest a new factory constructor Border.symmetric.
A typical use case:

Container(
    padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 2.0),
    decoration: const BoxDecoration(
      border: Border.symmetric(
        horizontal: BorderSide(width: 1.0, color: Color(0xFFFFDFDFDF)),
        vertical: BorderSide(width: 1.0, color: Color(0xFFFF7F7F7F)),
      ),
      color: Color(0xFFBFBFBF),
    ),
)

Although it is rare for borders that is not in the same width or same color. It is convenient for widgets having only either horizontal or vertical border, in which is rather more common.

Proposal

factory Border.symmetric({ BorderSide vertical = BorderSide.none, BorderSide horizontal = BorderSide.none })
or
const Border.symmetric({ BorderSide vertical = BorderSide.none, BorderSide horizontal = BorderSide.none })

Reason for having factory of this name:

TableBorder is a class similar to Border and it has these constructors.

  • TableBorder from 6 BorderSide
  • TableBorder factory that internally instantiate a BorderSide and call constructor
  • TableBorder.symmetric factory which accepts two BorderSide for inside and outside

Reason for having parameters of name:

EdgeInsets also handles top, right, bottom, left sides, has EdgeInsets.symmetric that accepts horizontal and vertical as parameter.

I can work a PR.

Activity

  1. added
    a: imagesLoading, displaying, rendering images
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    on Nov 25, 2019
  2. github-actions commented on Aug 24, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  3. locked as resolved and limited conversation to collaborators on Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: imagesLoading, displaying, rendering imagesc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions