Skip to content

colorFilter on BoxDecoration image causes gap between image and top of screen for some fit modes on web only #59451

@mrmax99

Description

@mrmax99

Steps to Reproduce

Create an app with a transparent AppBar and a DecoratedBox with a BoxDecoration with a DecorationImage with certain fits (e.g. BoxFit.cover) with a colorFilter. Full code of an app reproducing the issue are pasted below, based on the default 'flutter create' app.

I only notice this issue on flutter web. I have also tested on an android emulator and I do not see the issue there.

Code to reproduce:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @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 StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        title: Text(widget.title, style: TextStyle(color: Colors.black),),
        elevation: 0,
        backgroundColor: Colors.transparent,
      ),
      body: Stack(
        children: [
          Container(
            constraints: BoxConstraints.expand(height:500),
            child: DecoratedBox(
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: Image.asset('assets/clouds.jpeg').image,
                  fit: BoxFit.cover,
                  alignment: Alignment.topCenter,
                  colorFilter: ColorFilter.mode(Colors.grey[850], BlendMode.overlay)
                )
              ),
            ),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

Expected results:
Photo reaches all the way to the top of the screen.

Working, all the way to the top, if you comment out the line adding the colorFilter:
working

Actual results:
There is a small gap between the top of the screen and the image.

Broken, including the colorFilter:
broken

Logs
> flutter run -d chrome --verbose
[  +12 ms] executing: [C:\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[  +91 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +1 ms] f994b769743368b36b9c03fb359f62230b60ab92
[   +1 ms] executing: [C:\flutter/] git tag --contains HEAD
[ +284 ms] Exit code 0 from: git tag --contains HEAD
[   +3 ms] 1.19.0-4.1.pre
[  +17 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +70 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[   +2 ms] origin/beta
[   +1 ms] executing: [C:\flutter/] git ls-remote --get-url origin
[  +47 ms] Exit code 0 from: git ls-remote --get-url origin
[   +3 ms] https://github.com/flutter/flutter.git
[ +109 ms] executing: [C:\flutter/] git rev-parse --abbrev-ref HEAD
[  +54 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +2 ms] beta
[  +96 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.    
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +5 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[  +23 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[  +12 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[   +3 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.        
[   +2 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.        
[  +34 ms] executing: C:\Users\MrMax\AppData\Local\Android\sdk\platform-tools\adb.exe devices -l
[  +67 ms] List of devices attached
[   +8 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[  +11 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.    
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[  +11 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[  +12 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.        
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.        
[ +270 ms] Generating
C:\Users\MrMax\Documents\bash_work\debug_bg_img_flutter\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[ +160 ms] Launching lib\main.dart on Chrome in debug mode...
[  +97 ms] Updating assets
[ +124 ms] Syncing files to device Chrome...
[  +66 ms] Generating
C:\Users\MrMax\Documents\bash_work\debug_bg_img_flutter\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java
[  +92 ms] <- reset
[   +8 ms] C:\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev --old_gen_heap_size=2000
C:\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root
C:\flutter\bin\cache\flutter_web_sdk/ --incremental --target=dartdevc --debugger-module-names        
-Ddart.developer.causal_async_stacks=true --output-dill
C:\Users\MrMax\AppData\Local\Temp\flutter_tools.e5d4b49c\flutter_tool.869f6ae8\app.dill
--libraries-spec file:///C:/flutter/bin/cache/flutter_web_sdk/libraries.json --packages .packages    
-Ddart.vm.profile=false -Ddart.vm.product=false
--bytecode-options=source-positions,local-var-info,debugger-stops,instance-field-initializers,keep-unreachable-code,avoid-closure-call-instructions --enable-asserts --track-widget-creation
--filesystem-root C:\Users\MrMax\AppData\Local\Temp\flutter_tools.e5d4b49c\flutter_tools.5a7e3f7c    
--filesystem-scheme org-dartlang-app --initialize-from-dill build\cache.dill.track.dill --platform   
file:///C:/flutter/bin/cache/flutter_web_sdk/kernel/flutter_ddc_sdk.dill
[  +41 ms] <- compile org-dartlang-app:/web_entrypoint.dart
[+16660 ms] Syncing files to device Chrome... (completed in 16,860ms, longer than expected)
[   +3 ms] Synced 22.6MB.
[  +18 ms] <- accept
[ +313 ms] [CHROME]:
[  +16 ms] [CHROME]:DevTools listening on
ws://127.0.0.1:65247/devtools/browser/6488f8f2-3ea0-4728-85a9-63870dfebfc4
[+5080 ms] Debug service listening on ws://127.0.0.1:65292/aCMh30r3d9w=

[ +819 ms] Debug service listening on ws://127.0.0.1:65292/aCMh30r3d9w=
[   +4 ms] Warning: Flutter's support for web development is not stable yet and hasn't
[  +26 ms] been thoroughly tested in production environments.
[   +1 ms] For more information see https://flutter.dev/web
[   +2 ms]   To hot restart changes while running, press "r" or "R".
[   +2 ms] For a more detailed help message, press "h". To quit, press "q".
> flutter analyze
Analyzing debug_bg_img_flutter...
No issues found! (ran in 30.2s)

Output of flutter doctor -v:

> flutter doctor -v
[√] Flutter (Channel beta, 1.19.0-4.1.pre, on Microsoft Windows [Version 10.0.18363.900], locale
    en-US)
    • Flutter version 1.19.0-4.1.pre at C:\flutter
    • Framework revision f994b76974 (5 days ago), 2020-06-09 15:53:13 -0700
    • Engine revision 9a28c3bcf4
    • Dart version 2.9.0 (build 2.9.0-14.1.beta)


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\MrMax\AppData\Local\Android\sdk
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.8052
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] VS Code (version 1.46.0)
    • VS Code at C:\Users\MrMax\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.11.0

[√] Connected device (2 available)
    • Web Server • web-server • web-javascript • Flutter Tools
    • Chrome     • chrome     • web-javascript • Google Chrome 83.0.4103.97

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: imagesLoading, displaying, rendering imagesengineflutter/engine related. See also e: labels.found in release: 1.19Found to occur in 1.19found in release: 1.20Found to occur in 1.20has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallywaiting for PR to land (fixed)A fix is in flight

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions