Skip to content

Conversation

@ksokolovskyi
Copy link
Contributor

Fixes #163972

Description

  • Fixes Gradient.scale methods to not lose transform
BEFORE AFTER
before after
Code sample
import 'package:flutter/material.dart';

void main() => runApp(const GradientScaleBug());

class GradientScaleBug extends StatelessWidget {
  const GradientScaleBug({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.all(10),
          child: Column(
            spacing: 10,
            children: [
              Expanded(
                child: Row(
                  spacing: 10,
                  children: [
                    _buildGradientContainer(
                      LinearGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                        ],
                        transform: GradientRotation(0.7853981634),
                      ),
                    ),
                    _buildGradientContainer(
                      LinearGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                        ],
                        transform: GradientRotation(0.7853981634),
                      ).scale(0.5),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Row(
                  spacing: 10,
                  children: [
                    _buildGradientContainer(
                      RadialGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                        ],
                        center: Alignment.topCenter,
                        transform: GradientRotation(0.7853981634),
                      ),
                    ),
                    _buildGradientContainer(
                      RadialGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                        ],
                        center: Alignment.topCenter,
                        transform: GradientRotation(0.7853981634),
                      ).scale(0.5),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Row(
                  spacing: 10,
                  children: [
                    _buildGradientContainer(
                      SweepGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                          Color(0xFFCC5555),
                        ],
                        center: Alignment.topCenter,
                        transform: GradientRotation(0.7853981634),
                      ),
                    ),
                    _buildGradientContainer(
                      SweepGradient(
                        colors: [
                          Color(0xFFCC5555),
                          Color(0xFF55BB55),
                          Color(0xFF5555CC),
                          Color(0xFFCC5555),
                        ],
                        center: Alignment.topCenter,
                        transform: GradientRotation(0.7853981634),
                      ).scale(0.5),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildGradientContainer(Gradient gradient) {
    return Expanded(
      child: DecoratedBox(
        decoration: BoxDecoration(gradient: gradient),
        child: const SizedBox.expand(),
      ),
    );
  }
}

Pre-launch Checklist

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Dec 5, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue where Gradient.scale did not preserve the transform property on LinearGradient, RadialGradient, and SweepGradient. The changes in gradient.dart properly pass the transform to the new gradient instances. The accompanying tests in gradient_test.dart effectively verify this fix. I've found a minor issue in the expected color values within the new tests and have provided suggestions to correct them.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 5, 2026

autosubmit label was removed for flutter/flutter/179493, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@ksokolovskyi ksokolovskyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Jan 5, 2026
Merged via the queue into flutter:master with commit 46c8606 Jan 5, 2026
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gradient subclasses' scale methods lose the GradientTransform

2 participants