Pārlūkot izejas kodu

[flutter] Support hot-reload of SpineWidget and controller.

Mario Zechner 2 gadi atpakaļ
vecāks
revīzija
425e5a5f2c
1 mainītis faili ar 12 papildinājumiem un 0 dzēšanām
  1. 12 0
      spine-flutter/lib/spine_widget.dart

+ 12 - 0
spine-flutter/lib/spine_widget.dart

@@ -373,6 +373,18 @@ class _SpineWidgetState extends State<SpineWidget> {
     }
   }
 
+  @override
+  void didUpdateWidget(covariant SpineWidget oldWidget) {
+    super.didUpdateWidget(oldWidget);
+    widget._controller._drawable?.dispose();
+    _drawable = null;
+    if (widget._assetType == _AssetType.drawable) {
+      loadDrawable(widget._drawable!);
+    } else {
+      loadFromAsset(widget._bundle, widget._atlasFile!, widget._skeletonFile!, widget._assetType);
+    }
+  }
+
   void loadDrawable(SkeletonDrawable drawable) {
     _drawable = drawable;
     _computedBounds = widget._boundsProvider.computeBounds(drawable);