You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SweepGradient startAngle doesn't work as expected. #23648
[✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.13.6 17G65, locale en-AZ)
• Flutter version 0.9.4 at /Users/mac/development/flutter
• Framework revision f37c235c32 (5 weeks ago), 2018-09-25 17:45:40 -0400
• Engine revision 74625aed32
• Dart version 2.1.0-dev.5.0.flutter-a2eb050044
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.2)
• Android SDK at /Users/mac/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[!] iOS toolchain - develop for iOS devices
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
✗ ios-deploy not installed. To install:
brew install ios-deploy
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
For more info, see https://flutter.io/platform-plugins
To install:
brew install cocoapods
pod setup
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 28.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[✓] Connected devices (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
! Doctor found issues in 1 category.
Is this only in an emulator (ios, Android?) or also on real devices (which ones)?
This is on a real device. It is Xiaomi Redmi 5. But in emulator there is another issue about gradient. Gradient colors doesn't smoothly change. They are rendered like solid colors. Here is a screenshot of emulator. With the same code.
I tried fiddling with the startAngle and endAngle, and also changing the order of my stops (using the example here https://docs.flutter.io/flutter/painting/SweepGradient-class.html, pasted below) and it seems like the SweepGradient always starts in the middle right...which is not ideal. As @fantasy525 points out, I would expect starting at -math.pi/2 to rotate the entire gradient so that the blue (in the example) starts at the top.
Maybe the descriptions of startAngle and stopAngle are what cause confusion. I'm interpreting it as the angle at which the color stop 0 begins, with 0 defined as the middle right of the screen. But maybe it should be interpreted as the angle at which a gradient effect begins (all drawing begins on the middle right of the screen), so you can have a SweepGradient that only has a section that has a blurry gradient?
Container(
decoration: BoxDecoration(
gradient: SweepGradient(
center: FractionalOffset.center,
startAngle: 0.0,
endAngle: math.pi * 2,
colors: const <Color>[
Color(0xFF4285F4), // blue
Color(0xFF34A853), // green
Color(0xFFFBBC05), // yellow
Color(0xFFEA4335), // red
Color(0xFF4285F4), // blue again to seamlessly transition to the start
],
stops: const <double>[0.0, 0.25, 0.5, 0.75, 1.0],
),
),
)
The workaround is wrap the SweepGradient's Container in a RotatedBox, but I would prefer to just draw the gradient already in that orientation.
I've added some examples in the linked PR, but you can now rotate just the gradient by specifying the transform parameter in your gradient. Right now, only GradientRotation is implemented - if you give that the radians to rotate, it should just work.
And FWIW, I spent an inordinate amount of time trying to convince myself that there were no bugs elsewhere in the implementation for this, because I kept messing up the vector math - and of course, instead of thinking "Oh, I'm messing up the vector math", I kept thinking "Oh, maybe there's a bug in the engine code" or something :D. But now it's in there and it should be right :)
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.
Activity
zoechi commentedon Oct 29, 2018
Please add the output of
flutter doctor -v.zoechi commentedon Oct 29, 2018
Is this only in an emulator (ios, Android?) or also on real devices (which ones)?
seniorbee commentedon Oct 29, 2018
seniorbee commentedon Oct 29, 2018
This is on a real device. It is Xiaomi Redmi 5. But in emulator there is another issue about gradient. Gradient colors doesn't smoothly change. They are rendered like solid colors. Here is a screenshot of emulator. With the same code.

yumi0629 commentedon Nov 2, 2018
I got the same problem, it seems that the part I circled above was been redrawn with the end color.
My solution is rotating the canvas:
Now, it looks right:

dubiao commentedon Nov 7, 2018
Good point.
baoxiehao commentedon Mar 26, 2019
Your code is not working for me.
I'm using following working code, hope it helps for someone need it:
where I'm using a square(so width == height), and the outerAngle is an animation value.
fantasy525 commentedon Apr 7, 2019
I set startAngle -90*(pi/180),but it is not working,I expect start point at -90 deg.It's a bug?
maryx commentedon May 14, 2019
I tried fiddling with the
startAngleandendAngle, and also changing the order of my stops (using the example here https://docs.flutter.io/flutter/painting/SweepGradient-class.html, pasted below) and it seems like the SweepGradient always starts in the middle right...which is not ideal. As @fantasy525 points out, I would expect starting at -math.pi/2 to rotate the entire gradient so that the blue (in the example) starts at the top.Maybe the descriptions of
startAngleandstopAngleare what cause confusion. I'm interpreting it asthe angle at which the color stop 0 begins, with 0 defined as the middle right of the screen. But maybe it should be interpreted asthe angle at which a gradient effect begins (all drawing begins on the middle right of the screen), so you can have a SweepGradient that only has a section that has a blurry gradient?The workaround is wrap the SweepGradient's Container in a RotatedBox, but I would prefer to just draw the gradient already in that orientation.
dnfield commentedon May 15, 2019
/cc @xqwzts in case he has any good ideas here..
6 remaining items
dnfield commentedon May 16, 2019
Ah! We're missing the local matrix parameter - with that you could rotate just the gradient.
dark-chocolate commentedon May 25, 2019
In your
build()method, use it like.Implementation (
MyPainterclass)dnfield commentedon Oct 11, 2019
I've added some examples in the linked PR, but you can now rotate just the gradient by specifying the
transformparameter in your gradient. Right now, onlyGradientRotationis implemented - if you give that theradiansto rotate, it should just work.dnfield commentedon Oct 11, 2019
And FWIW, I spent an inordinate amount of time trying to convince myself that there were no bugs elsewhere in the implementation for this, because I kept messing up the vector math - and of course, instead of thinking "Oh, I'm messing up the vector math", I kept thinking "Oh, maybe there's a bug in the engine code" or something :D. But now it's in there and it should be right :)
github-actions commentedon Aug 5, 2021
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 -vand a minimal reproduction of the issue.