From d99fa9f4cdb8f5c25c45cf484d8eeb66658fb2ef Mon Sep 17 00:00:00 2001 From: Adil Hanney Date: Sat, 29 Jun 2024 01:25:38 +0100 Subject: [PATCH] ref(onyxsdk_pen_area): use Duration instead of milliseconds --- .../onyxsdk_pen/lib/onyxsdk_pen_area.dart | 26 ++++++++++++------- .../lib/onyxsdk_pen_area.dart | 4 +-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart b/packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart index 76e4f9be5..2b3e69f33 100644 --- a/packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart +++ b/packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart @@ -11,7 +11,7 @@ import 'onyxsdk_pen_platform_interface.dart'; class OnyxSdkPenArea extends StatefulWidget { const OnyxSdkPenArea({ super.key, - this.refreshDelayMs = 1000, + this.refreshDelay = const Duration(seconds: 1), required this.child, }); @@ -20,7 +20,7 @@ class OnyxSdkPenArea extends StatefulWidget { /// Setting this too low will cause the screen to refresh while the user /// is still writing, which will make the screen get stuck in a half-drawn /// state. - final int refreshDelayMs; + final Duration refreshDelay; final Widget child; @@ -40,7 +40,6 @@ class OnyxSdkPenArea extends StatefulWidget { class _OnyxSdkPenAreaState extends State { static bool? _isOnyxDevice = (kIsWeb || !Platform.isAndroid) ? false : null; - static Future _findIsOnyxDevice() async { if (_isOnyxDevice != null) return _isOnyxDevice!; @@ -63,17 +62,24 @@ class _OnyxSdkPenAreaState extends State { return _isOnyxDevice = true; } + /// Parameters to pass to the platform side + late final creationParams = { + "refreshDelayMs": widget.refreshDelay.inMilliseconds, + }; + + /// This is used in the platform side to register the view. + static const String viewType = 'onyxsdk_pen_area'; + + @override + void didUpdateWidget(OnyxSdkPenArea oldWidget) { + super.didUpdateWidget(oldWidget); + creationParams['refreshDelayMs'] = widget.refreshDelay.inMilliseconds; + } + @override Widget build(BuildContext context) { if (!isOnyxDevice) return widget.child; - // This is used in the platform side to register the view. - const String viewType = 'onyxsdk_pen_area'; - // Pass parameters to the platform side. - final Map creationParams = { - "refreshDelayMs": widget.refreshDelayMs, - }; - return Stack( fit: StackFit.expand, children: [ diff --git a/packages/onyxsdk_pen_dummy/lib/onyxsdk_pen_area.dart b/packages/onyxsdk_pen_dummy/lib/onyxsdk_pen_area.dart index 38cdce6b4..306b5e461 100644 --- a/packages/onyxsdk_pen_dummy/lib/onyxsdk_pen_area.dart +++ b/packages/onyxsdk_pen_dummy/lib/onyxsdk_pen_area.dart @@ -3,11 +3,11 @@ import 'package:flutter/material.dart'; class OnyxSdkPenArea extends StatelessWidget { const OnyxSdkPenArea({ super.key, - this.refreshDelayMs = 1000, + this.refreshDelay = const Duration(seconds: 1), required this.child, }); - final int refreshDelayMs; + final Duration refreshDelay; final Widget child;