From f800e36232fb34ce2ca5f1df1716ac38018b1a49 Mon Sep 17 00:00:00 2001 From: Natesh Bhat Date: Fri, 24 Oct 2025 21:38:00 +0530 Subject: [PATCH] fix: add listen: false to showToolbar() and hideToolbar() Fixes #278 Added `listen: false` parameter to Provider.of calls in showToolbar() and hideToolbar() methods to prevent assertion errors when called from event handlers. --- device_preview/lib/src/device_preview.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/device_preview/lib/src/device_preview.dart b/device_preview/lib/src/device_preview.dart index 143d763..c889154 100644 --- a/device_preview/lib/src/device_preview.dart +++ b/device_preview/lib/src/device_preview.dart @@ -239,7 +239,7 @@ class DevicePreview extends StatefulWidget { BuildContext context, { bool enablePreview = true, }) { - final store = Provider.of(context); + final store = Provider.of(context, listen: false); store.data = store.data.copyWith( isToolbarVisible: true, isEnabled: enablePreview, @@ -254,7 +254,7 @@ class DevicePreview extends StatefulWidget { BuildContext context, { bool disablePreview = true, }) { - final store = Provider.of(context); + final store = Provider.of(context, listen: false); store.data = store.data.copyWith( isToolbarVisible: false, isEnabled: !disablePreview, @@ -494,9 +494,10 @@ class _DevicePreviewState extends State { return ChangeNotifierProvider( create: (context) => DevicePreviewStore( defaultDevice: widget.defaultDevice ?? Devices.ios.iPhone13, - devices: widget.devices, - locales: widget.availableLocales, + devices: widget.devices ?? Devices.all, + locales: widget.availableLocales ?? defaultAvailableLocales, storage: storage, + data: widget.data, ), builder: (context, child) { final isInitialized = context.select(