re-add resize timer to FilamentWidget return initial widget when resizing

This commit is contained in:
Nick Fisher
2024-06-01 12:50:27 +08:00
parent 382d68ee77
commit df777585e2

View File

@@ -28,7 +28,6 @@ class FilamentWidget extends StatefulWidget {
class _FilamentWidgetState extends State<FilamentWidget> { class _FilamentWidgetState extends State<FilamentWidget> {
FlutterFilamentTexture? _texture; FlutterFilamentTexture? _texture;
Rect get _rect { Rect get _rect {
final renderBox = (context.findRenderObject()) as RenderBox; final renderBox = (context.findRenderObject()) as RenderBox;
final size = renderBox.size; final size = renderBox.size;
@@ -61,18 +60,18 @@ class _FilamentWidgetState extends State<FilamentWidget> {
super.dispose(); super.dispose();
} }
bool _resizing = false; bool _resizing = false;
Timer? _resizeTimer;
Future _resizeTexture(Size newSize) async { Future _resizeTexture(Size newSize) async {
_resizeTimer?.cancel();
_resizeTimer = Timer(Duration(milliseconds: 100), () async {
if (_resizing) { if (_resizing) {
return; return;
} }
await Future.delayed(Duration.zero); _resizeTimer!.cancel();
if (_resizing) {
return;
}
_resizing = true; _resizing = true;
setState(() {});
var dpr = MediaQuery.of(context).devicePixelRatio; var dpr = MediaQuery.of(context).devicePixelRatio;
@@ -82,11 +81,12 @@ class _FilamentWidgetState extends State<FilamentWidget> {
"Resized texture, new flutter ID is ${_texture!.flutterTextureId} (hardware ID ${_texture!.hardwareTextureId})"); "Resized texture, new flutter ID is ${_texture!.flutterTextureId} (hardware ID ${_texture!.hardwareTextureId})");
setState(() {}); setState(() {});
_resizing = false; _resizing = false;
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_texture == null) { if (_texture == null || _resizing) {
return widget.initial ?? return widget.initial ??
Container(color: kIsWeb ? Colors.transparent : Colors.red); Container(color: kIsWeb ? Colors.transparent : Colors.red);
} }