Skip to content

Clip image of BoxDecoration to circle when shape is BoxShape.circle#63352

Merged
fluttergithubbot merged 3 commits intoflutter:masterfrom
timekone:box-decoration-image
Aug 21, 2020
Merged

Clip image of BoxDecoration to circle when shape is BoxShape.circle#63352
fluttergithubbot merged 3 commits intoflutter:masterfrom
timekone:box-decoration-image

Conversation

@timekone
Copy link
Contributor

@timekone timekone commented Aug 10, 2020

Description

Clips image of BoxDecoration to circle when shape is BoxShape.circular.

Current behavior is the image is clipped to an oval. Dimensions of this oval are tightly constrained by the size of the decorated widget.

Before
After
Source code
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Container(
        height: double.infinity,
        width: double.infinity,
        decoration: BoxDecoration(
          shape: BoxShape.circle,
          color: Colors.red,
          image: DecorationImage(
            fit: BoxFit.cover,
            image: AssetImage('assets/logo_flutter.png'),
          ),
        ),
      ),
    );
  }
}

See more in the related issue.

Also, I changed Boxdecoration.getClipPath() to reflect changes in clipping behavior.

Related Issues

Fixes #63351

Tests

I added a test for Boxdecoration.getClipPath() for the case when shape of Box decoration is BoxShape.circle.

https://github.com/timekone/flutter/blob/84594a2dbdfa5d1e3156c9b649c82ae5b8bdd488/packages/flutter/test/painting/box_decoration_test.dart#L88-L99

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 10, 2020
@Piinks Piinks added the a: quality A truly polished experience label Aug 10, 2020
@goderbauer goderbauer requested a review from chunhtai August 12, 2020 21:52
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@fluttergithubbot fluttergithubbot merged commit f777ead into flutter:master Aug 21, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: quality A truly polished experience framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image of BoxDecoration isn't clipped to circle when shape is BoxShape.circle

4 participants