In the following code nothing is displayed if the angle of the innermost Transform
widget is -90 deg:
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:vector_math/vector_math.dart' as vm;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Transform(
transform: Matrix4.identity()
..setEntry(3, 2, 0.001)
..rotateX(vm.radians(20))
..rotateY(vm.radians(-30)),
child: Stack(children: [
Transform(
alignment: Alignment.topLeft,
transform: Matrix4.identity()..rotateX(vm.radians(-90)), // (1) Change this angle
child: Container(
width: 100,
height: 200,
color: Colors.grey.shade200,
),
),
Positioned.fill(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Container(color: Colors.transparent),
),
),
]),
),
),
),
);
}
}
If I change the angle to -91, the blurred widget is displayed. If the blur filter is removed (by removing the Positioned
widget), the rectangle is displayed. How can I get the blurred widget to display if the angle is -90?
2
Answers
I've come to the conclusion that using
ImageFilter.blur
the way I'm doing it does not work in Flutter. Even wrapping the greyContainer
in my answer with aImageFiltered
widget and not usingBackdropFilter
does not work.However, my goal is to have a rectangle with blurry edges in order to simulate a shadow. I can achieve this by using
BoxDecoration
for theContainer
widget:When you rotate a widget by 90 degrees around the X-axis (rotateX(vm.radians(-90))), it can cause the widget to disappear because the rotation effectively flips the widget so that it faces away from the camera, making it invisible from the current viewpoint.
To solve this issue, you can try the following approaches:
1. Adjust the rotation angle: Instead of rotating by -90 degrees, try a smaller angle like -89 degrees. This will rotate the widget almost vertically but keep it slightly tilted towards the camera, making it partially visible.
2. Use a different transformation: Instead of rotating around the X-axis, you can try rotating around the Y-axis or Z-axis to achieve the desired effect while keeping the widget visible.
This rotates the widget by 180 degrees around the Y-axis, which flips it horizontally.
3. Change the widget’s position: If rotating the widget causes it to disappear, you can try adjusting its position in the Stack to ensure it remains visible after the rotation.
This are three things you can try