[英]Flutter web renderer (not CanvasKit): Nested Y Axis rotation causes a child widget to disappear
While nesting two Transform
widgets, child widget (IE a picture) is disappearing in some cases.在嵌套两个Transform
小部件时,子小部件(即图片)在某些情况下会消失。
It happens with Animation
and AnimatedBuilder
as well. Animation
和AnimatedBuilder
也会发生这种情况。
Conditions for reproducing:再生条件:
CanvasKit
) Flutter Web 仅带 HTML web 渲染器(不是 Android 也不是 Flutter Web 带CanvasKit
)Minimal reproduce:最小重现:
Create new folder flutter_web_bug
新建文件夹flutter_web_bug
Open terminal inside that folder and execute flutter create.
在该文件夹中打开终端并执行flutter create.
Replace ./lib/main.dart
contents with the following code将./lib/main.dart
内容替换为以下代码
Open terminal and execute flutter run -d chrome --web-renderer html
打开终端并执行flutter run -d chrome --web-renderer html
import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}): super(key: key); @override Widget build(BuildContext context) { return const MaterialApp( title: 'Flutter web bug', home: MyHomePage(title: 'Flutter web bug'), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}): super(key: key); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { double angle = 0.0; @override void initState() { super.initState(); Timer.periodic(const Duration(milliseconds: 20), (timer) { setState(() { angle += 0.01; }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Transform( transform: Matrix4.identity()..setEntry(3, 2, 0.001)..rotateY(pi * angle), alignment: Alignment.center, child: Align( alignment: Alignment.center, child: Container( color: const Color(0xffaaffff), child: Transform( alignment: Alignment.center, transform: Matrix4.identity()..rotateY(pi), child: Image.network('https://docs.flutter.dev/assets/images/dash/dash-fainting.gif'))))), )); } }
Demonstration:示范:
The issue seems to be with Image.network()
where the image is rebuilding.问题似乎出在重建图像的Image.network()
上。 I tested using the cached.network_image library and was able to get the image to stay rendered while animating.我使用cached.network_image库进行了测试,并且能够让图像在设置动画时保持渲染状态。 Hopefully this helps!希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.