-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Deprecate BoxDecoration.shape.
#108052
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
Deprecate BoxDecoration.shape.
#108052
Conversation
2016d17 to
62a3280
Compare
We could consider adding |
|
The biggest question is how to go from |
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.
For better clarity let's say something replace BoxDecoration(shape: BoxShape.circle, border: Border.all(...)) with ShapeDecoration(shape: CircleBorder(...)) or something. Actually we might even be able to automigrate this, cc @Piinks.
(Before we do an automigration we really should see what the performance impact of this change is.)
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.
Is it possible to verify the performance impact now? Ignoring some tests?
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.
you can run some of the benchmarks locally before and after, sure. see the dev/benchmarks directory.
d423c64 to
f4088d1
Compare
|
To fix the tests, you'll want to find the expectations that say |
|
cc @goderbauer who owns the framework and may have opinions on whether this is worth doing. |
|
Luckily there seem to be only a few of these cases, but I still have no idea how to go from a RenderThing to paint. Yes, we should adjust, but how do I "print" what a Render is painting so I can compare (and possibly adjust) the test? I don't know how to do this. Comparing |
Seems like a nice cleanup. If it does not have any performance impact, I am for this change. |
dev/benchmarks/macrobenchmarks/lib/src/web/bench_wrapbox_scroll.dart
Outdated
Show resolved
Hide resolved
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.
This should probably be more generic, some users may not be using circle.
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.
BoxShape.rectangle doesn't do anything. I guess, "If BoxShape.rectangle, don't do anything. If BoxShape.circle, replace with ShapeDecoration"?
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.
yeah the default is rectangle, and the only other option is circle.
67492c3 to
3cd5c23
Compare
Ignore the ...you want to find where we |
|
Thanks. I'm doing this right now, already got many tests passing. Check 3cd5c23. Running flutter test locally to see what else is missing. Edit: it seems there is only one test remaining, expansion tile. I'll check later. |
3cd5c23 to
e8e6b4e
Compare
|
Is there a way to understand what this means? I never understood the "???".
[image: image]
<https://user-images.githubusercontent.com/351125/180317579-5f6e2311-67ad-43be-aa43-51c5de889260.png>
The weird line of gibberish is because your console is not set to UTF-8.
|
95598a5 to
696a0fe
Compare
|
Tests now pass 😀 Next up: get some benchmark. |
BenchmarksWe have benchmarks!!!! I made a Switch (the widget that's by far the most affected by this change) many times, applied an animation, and executed the benchmark: 10x, 100x, 1000x, many times. @Hixie is right. ShapeDecoration can be 20% slower than BoxDecoration. But I'm not giving up. I compared ShapeDecoration with BoxDecoration and found the biggest difference. It is not preCache. It is path! DrawPath is slow. DrawCircle is fast. Optimizing While optimizing Circle, I optimized Oval and while optimizing Oval I also optimized RoundedRectangle. You know what, I'm changing everything anyway. First optimized benchmark with Switch (now uses Implementation details:I added a function and a getter to ShapeBorder (Hixie is going to kill me, twice): This is how it works:
As a side effect from my last change, I'm reverting the tests and fixing others. Instead of changing Code I used for benchmark here!You can change that function to anything: MaterialApp(
home: Scaffold(
body: Wrap(children: [
for (int i = 0; i < 100; i++)
SizedBox(
width: 100,
height: 100,
child: Center(
child: _RotatingWidget(
child: Container(
width: 50,
height: 50,
decoration: BoxDecoration(
color: Colors.red,
// shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
// )
),
),
),
)),
]),
),
);// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'recorder.dart';
/// Measures expense of constructing Image widgets.
class BenchBuildCircle extends WidgetRecorder {
BenchBuildCircle() : super(name: benchmarkName);
static const String benchmarkName = 'build_circle';
@override
Widget createWidget() {
return MaterialApp(
home: Scaffold(
body: Wrap(children: [
for (int i = 0; i < 100; i++)
SizedBox(
width: 100,
height: 100,
child: Center(
child: _RotatingWidget(
child: Switch(value: true, onChanged: (value) {}),
),
)),
]),
),
);
}
}
class _RotatingWidget extends StatefulWidget {
const _RotatingWidget({required this.child});
final Widget child;
@override
_RotatingWidgetState createState() => _RotatingWidgetState();
}
class _RotatingWidgetState extends State<_RotatingWidget>
with SingleTickerProviderStateMixin {
late AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 200),
vsync: this,
)..repeat();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget? child) {
return Transform.rotate(
angle: 2 * 3.14 * controller.value,
child: widget.child,
);
},
);
}
} |
|
I added a default (empty) implementation for That's it, for now. |
73fc21f to
789a381
Compare
|
This sounds fantastic and I'll definitely look closer. Thinking out loud, one option might be to have paintBox (or whatever we call it) return a boolean, default implementation returns false, and returning true means you did the work and don't need to use getOuterPath et al. That way you just always call it and don't need to have the decoupled boolean getter. |
|
Sure, that's easy, but can you look the Google testing now? I'll be at home in a few hours, the failure will still be the same. |
|
I think you have to resync first. The old test results are no longer available. |
81ac252 to
be7c2cb
Compare
|
Thank you @bernaferrari for syncing this up. I can see the test results now. I'll take a look and let you know what I find. |
|
Hey @bernaferrari just wanted to check back in to let you know I have been looking at the failing tests, but have not been able to create a minimal reproducible example yet. I'll let you know as soon as I figure it out. |
|
Ok! Thanks. Looking forward to. |
|
After exactly 8 months, I think I'll close this. Even though I think Meanwhile I am, against my will, giving BoxDecoration a reason to exist; I'm adding non-uniform borders there, since we can't have it in ShapeBorder (natively, at least, for now, at least. My package does it: https://github.com/bernaferrari/non_uniform_border). I still like the 'remove boxShape' idea, I'm just thinking on alternatives since it's been a while and we can't move forward. Do you agree with the non-removal and request for a better name? I'm also fine if we remove it, ShapeDecoration is better, if we remove we free the user from a bunch of possible exceptions... but the PR has hit a roadblock for a few months now and no one knows how to solve the internal google bug. If you could also solve that bug, it would be great... Thinking smaller, I wish:
We could make the migration with Dart fix, life would go on.. What do you think? |
|
Yikes! this is taking ages. I was looking forward to this. :( |
|
Ops, wrong button. I'm just thinking on alternative ways to have the issue "out of the way" and be "less confusing" for many people.. But if anyone figures out the internal Google problem, I'm all in.. I hope you can figure out. But so far, nothing. |
|
@bernaferrari I just kicked off a rerun of all the tests, if any of them except Google Testing are failing, we should probably fix those first because otherwise the Google Testing shard will definitely fail anyway (by hitting the same problems). |
|
This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
02b56f7 to
a50f7d1
Compare
Improve wording. Improve deprecation message. Revert Quick Fixes This reverts commit 8b79dacf599f4b362d63d54bc333a9c17baa75eb. Revert "Fix formatting issue due to incorrect index in fix_data.yaml (#6)" This reverts commit 3dc9713d2aab2f0e7662ae7729efbfffa51bbad0. Revert "Fix Quick Fixes" This reverts commit 777675e8b92584e42be5f21795107ee7d1d29457. Revert Quick Fixes Revert Quick Fixes Minor fixes. Fix formatting issue due to incorrect index in fix_data.yaml (#6) Fix analyzer. Fix Quick Fixes * Add comments linking to the PR * Add painting.dart in uris list * Flutter Fix: account for border and backgroundBlendMode and remove borderRadius. * Tests for flutter fix * Flutter fix for rectangle shape in BoxDecoration.copyWith. * Add flutter fix tests for BoxDecoration.copyWith * Include rendering.dart for BoxDecoration flutter fix. Deprecate BoxShape. Co-authored-by: Birju Vachhani <[email protected]>
a50f7d1 to
f6f132d
Compare
|
👀 |
|
(triage): @bernaferrari looks like one of the customer tests failed. Do you still have plans to look into that and fix those up? |
|
I could fix the customer tests, but Google testing is failing on avatar image and no one knows why. |
|
@bernaferrari Do you want to update this PR to the latest master so we can do another google testing run to see what the current status is? Or have you decided to no longer pursue this and we should close it for now? |
|
Sure, I'll. I just need someone brave enough to be able to see what is happening with AvatarImage lol |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Hey @bernaferrari, we came across this PR during triage today. The problem with AvatarImage has eluded all of us, in spite of multiple attempts to diagnose the issue (over almost 2 years!). Regrettably, I don't know that we will be able to land this PR. Do you think we can close this? Or do you think there is another way we can approach this solution? I truly appreciate all of the work you have put into this. Unfortunately we have not been able to find a way to land it. |
|
Yeah, let's close it :( I can't do anything without external help and external help can't figure out. |


Issue: #108051
Discussion: #103833
Might be my first truly breaking change 🎉.
Need help: I don't know how to get tests working. cc @Hixie
Examples of errors: