Repository navigation
Closed
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagescustomer: azulefound in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team
Description
Steps to reproduce
(Flutter 3.29) The aspect ratio is distorted when using the prefer value for the webHtmlElementStrategy property in Stack > Positioned.fill > Image.network.
- Open the DartPad page.
- Select the beta channel.
- Run the code sample.
You can check the distorted images with incorrect aspect ratios.
Expected results
Images with correct aspect ratio.
Actual results
Images with distorted aspect ratio.
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text('Broken Images')),
body: Center(child: BrokenImages()),
),
);
}
}
class BrokenImages extends StatelessWidget {
const BrokenImages({super.key});
@override
Widget build(BuildContext context) {
return ListView(
children: [
...locations
.map((item) => ImageItem(imageUrl: item.imageUrl, name: item.name))
.expand((item) => [item, SizedBox(height: 12)]),
],
);
}
}
class ImageItem extends StatelessWidget {
const ImageItem({super.key, required this.imageUrl, required this.name});
final String imageUrl;
final String name;
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: 9 / 16,
child: Stack(
children: [
Positioned.fill(
child: Image.network(
imageUrl,
fit: BoxFit.cover,
webHtmlElementStrategy: WebHtmlElementStrategy.prefer,
),
),
Positioned(
left: 16,
top: 24,
child: Text(
style: Theme.of(
context,
).textTheme.headlineMedium?.copyWith(color: Colors.white),
name,
),
),
],
),
);
}
}
class Location {
const Location({
required this.name,
required this.place,
required this.imageUrl,
});
final String name;
final String place;
final String imageUrl;
}
const urlPrefix =
'https://docs.flutter.dev/cookbook/img-files/effects/parallax';
const locations = [
Location(
name: 'Mount Rushmore',
place: 'U.S.A',
imageUrl: '$urlPrefix/01-mount-rushmore.jpg',
),
Location(
name: 'Gardens By The Bay',
place: 'Singapore',
imageUrl: '$urlPrefix/02-singapore.jpg',
),
Location(
name: 'Machu Picchu',
place: 'Peru',
imageUrl: '$urlPrefix/03-machu-picchu.jpg',
),
Location(
name: 'Vitznau',
place: 'Switzerland',
imageUrl: '$urlPrefix/04-vitznau.jpg',
),
Location(
name: 'Bali',
place: 'Indonesia',
imageUrl: '$urlPrefix/05-bali.jpg',
),
Location(
name: 'Mexico City',
place: 'Mexico',
imageUrl: '$urlPrefix/06-mexico-city.jpg',
),
Location(name: 'Cairo', place: 'Egypt', imageUrl: '$urlPrefix/07-cairo.jpg'),
];
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
Set `style.height` to any appropriate value to stop this message.
Width of Platform View type: [Flutter__ImgElementImage__] may not be set. Defaulting to `width: 100%`.
Set `style.width` to any appropriate value to stop this message.
Height of Platform View type: [Flutter__ImgElementImage__] may not be set. Defaulting to `height: 100%`.Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.2 24C101 darwin-arm64, locale ko-KR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.1)
[✓] Connected device (3 available)
[✓] Network resourcesReacted by kristoffer-zliide, SoaAlex and Mohammad Rakib Bhuiyan
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagescustomer: azulefound in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyWeb applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team
Activity
felipendc commentedon Feb 14, 2025
I'm also facing this same problem when I close a windows which has a text filed, when the window (screen) is closed the image gets all distorted on Flutter 3.29.0 on Windows 11 x64
darshankawar commentedon Feb 17, 2025
@mycalls Thanks for the report. What's the expected result upon running the code ? Did it start to occur after upgrading to 3.29 ? Can you provide us correct results before it started to show distorted ones ?
mycalls commentedon Feb 17, 2025
@darshankawar
Thank you for your response. I apologize for the lack of information. So I have edited Steps to reproduce.
This issue occurs in version 3.29. If you run the code sample in DartPad's beta channel, you can see the distorted images with incorrect aspect ratios.
darshankawar commentedon Feb 18, 2025
Thanks for the update. I do see the same distorted behavior. Since
webHtmlElementStrategy: WebHtmlElementStrategy.prefer,is used whose description readswhether to display images in HTML elements. Could it be related to the html renderer being deprecated ?mycalls commentedon Feb 18, 2025
@darshankawar
Thanks for your check. I don't believe it's related to the HTML renderer being deprecated. Based on #149843, #157755, #159917 , I suspect it's related to the CORS configuration for images with CanvasKit and Skwasm.
8 remaining items
harryterkelsen commentedon Jul 9, 2025
I have a fix which seems to work. We were improperly sizing the
<img>element before. Now I just need to add tests and I'll upload the PR.Properly lay out and position RenderWebImage (#171916)
Properly lay out and position RenderWebImage (flutter#171916)
github-actions commentedon Jul 31, 2025
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.Properly lay out and position RenderWebImage (flutter#171916)
Properly lay out and position RenderWebImage (flutter#171916)
Properly lay out and position RenderWebImage (flutter#171916)
Properly lay out and position RenderWebImage (#171916)