Skip to content

Commit

Permalink
ref(onyxsdk_pen_area): use Duration instead of milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
adil192 committed Jun 29, 2024
1 parent a0ab454 commit d99fa9f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions packages/onyxsdk_pen/lib/onyxsdk_pen_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand All @@ -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;

Expand All @@ -40,7 +40,6 @@ class OnyxSdkPenArea extends StatefulWidget {

class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> {
static bool? _isOnyxDevice = (kIsWeb || !Platform.isAndroid) ? false : null;

static Future<bool> _findIsOnyxDevice() async {
if (_isOnyxDevice != null) return _isOnyxDevice!;

Expand All @@ -63,17 +62,24 @@ class _OnyxSdkPenAreaState extends State<OnyxSdkPenArea> {
return _isOnyxDevice = true;
}

/// Parameters to pass to the platform side
late final creationParams = <String, dynamic>{
"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<String, dynamic> creationParams = <String, dynamic>{
"refreshDelayMs": widget.refreshDelayMs,
};

return Stack(
fit: StackFit.expand,
children: [
Expand Down
4 changes: 2 additions & 2 deletions packages/onyxsdk_pen_dummy/lib/onyxsdk_pen_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d99fa9f

Please sign in to comment.