Skip to content

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

@timekone

Description

@timekone

When shape of BoxDecoration is BoxShape.circular the image is clipped with an oval instead of circle.
Dimensions of this oval are tightly constrained by the size of the decorated widget.

Screenshot

The problem is more obvious when decoration has png picture and background color.

Example with Flutter logo png

Expected behavior is that the image would be clipped to circle just like background color.

Expected this
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'),
          ),
        ),
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel master, 1.21.0-8.0.pre.122, on Mac OS X 10.15.5 19F101,
    locale en-UA)
    • Flutter version 1.21.0-8.0.pre.122 at /Users/timekone/development/flutter
    • Framework revision 7c6f9dd239 (5 hours ago), 2020-08-09 10:31:03 -0400
    • Engine revision 6d86e67f04
    • Dart version 2.10.0 (build 2.10.0-4.0.dev 0341576448)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/timekone/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Users/timekone/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6514223/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.8.4

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Users/timekone/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6514223/Android
      Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.47.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.12.2

 
[✓] Connected device (3 available)            
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    •
      Android 10 (API 29) (emulator)
    • Web Server (web)                   • web-server    • web-javascript •
      Flutter Tools
    • Chrome (web)                       • chrome        • web-javascript •
      Google Chrome 84.0.4147.105

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: qualityA truly polished experiencef: material designflutter/packages/flutter/material repository.found in release: 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions