-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Shapes] - Implement Rectangle widget (resolves #26) #28
[Shapes] - Implement Rectangle widget (resolves #26) #28
Conversation
That's a setting that doesn't apply until you merge this PR into the main repository. This repo shouldn't cause any restrictions with regard to what you're able to do with your own branch on your own machine. Let me know if there's a specific action you can't seem to execute. |
Unless specific hurdles come up, we should reflect the same API that exists in Swift UI. Are there any details that you're blocked from replicating in this case?
Is there a corresponding Swift UI API that you're thinking of? If not, let's just stick to replicating the public Swift UI APIs. If at a later point we find an opportunity to de-duplicate a bunch of implementation details behind the scenes, then we can consider that. |
Ah, I see. That's good to know. I was thinking that having multiple commits here would make your review harder by having view the commits separately.
In SwiftUI, Rectangle()
.fill(Color.green)
Rectangle()
.fill(LinearGradient(gradient: Gradient(colors: [.yellow, .orange]), startPoint: .leading, endPoint: .trailing)) However, in Dart, Rectangle(
fill: Colors.blue,
),
Rectangle(
fill: LinearGradient(colors: [Colors.yellow, Colors.orange]),
), In my current PR I created a
Is that the best way to do it given the constraints? After thinking more about it, making
There is a Shape protocol with the following types that conform to it:
But I agree that we should just implement the concrete shapes themselves for now. ConclusionUnless you have a new idea, I'm going to make |
@matthew-carroll Ready for a final review. The SwiftUI I dropped the I mentioned my intention previously to have color be an optional unnamed parameter of ShapeStyle:
However, it isn't possible in Dart to mix optional positional and named parameters. Upvote this issue if you think it should be. So I'm reverting to the previous version:
Originally I implemented |
@suragch is there anything that the If not, is there any reason not to take a One option there would be to use two properties: I'm open to multiple approaches, but I wanted to check the rationale for |
@matthew-carroll The sole purpose for |
Sounds good. Let's do that. |
@matthew-carroll I removed There is no visual difference in the painted rectangles. |
@matthew-carroll You're suggestions are implemented now. Let me know if there are any further adjustments to make. |
@@ -0,0 +1,117 @@ | |||
enum HorizontalAlignment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that you moved HorizontalAlignment
and VerticalAlignment
into this file. Any reason why? Is that because you're preparing for the alignments to be used by widgets other than HStack
and Vstack
?
As for the directory name - does the term layout_adjustments
exist in Swift UI? If not, I'd say this file can go in the layout
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment
in SwiftUI can be defined in terms of HorizontalAlignment
and VerticalAlignment
so that's why I moved them to a common file rather than importing HStack
and VStack
into the Frame
file.
The layout_adjustments
already existed for the Frame
widget, so that's why I put alignment.dart
there. That sounds good to move alignment.dart
to the layout
directory. I assume I should move frame.dart
there too?
@matthew-carroll Assuming the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks.
@matthew-carroll I'm going to create an initial PR now so that I can get feedback before continuing too far in a direction that we don't want to go.
This PR implements a minimal
Rectangle
widget in Flutter. Specifically you'll find the following additions to the repo:Rectangle
examples in the SwiftUI gallery app. I also added Shapes to the More bottom nav bar.Issues to consider
fill
is aShapeStyle
, which can be a color, gradient, or other pattern. I'm not really sure what the best way is to implement this in Flutter. I created a ShapeStyle class but maybe it would be better to just have color and gradient be properties on Rectangle. Also,ShapeStyle
in SwiftUI doesn't have a color property. I think it might get color from the ForegroundStyle. It doesn't have agradient
property either. Instead it has alinearGradient
,radialGradient
, etc. That didn't seem very Flutter-like to add all of those properties when they can all be expressed withGradient
.Shape
class that ties all of the shapes together, or should we implement each shape widget independently?I don't think squashing is currently enabled for this repo. Could you enable it so I don't have to rebase the individual commits on my fork?