From 3e769d8ddbc2903ba810ed6b667e870de3bf3452 Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Fri, 25 Oct 2024 18:11:27 +0700 Subject: [PATCH 1/7] refactor: delete unused file --- .../lib/src/coordinate_system_painter.dart | 235 ------------------ 1 file changed, 235 deletions(-) delete mode 100644 example/lib/src/coordinate_system_painter.dart diff --git a/example/lib/src/coordinate_system_painter.dart b/example/lib/src/coordinate_system_painter.dart deleted file mode 100644 index 120d7aa..0000000 --- a/example/lib/src/coordinate_system_painter.dart +++ /dev/null @@ -1,235 +0,0 @@ -import 'dart:math'; - -import 'package:flutter/material.dart'; - -enum _Axis { - x, - y, - z; - - String get text => switch (this) { - x => 'Roll', - y => 'Pitch', - z => 'Yaw', - }; -} - -class CoordinateSystemPainter extends CustomPainter { - const CoordinateSystemPainter(); - - @override - void paint(Canvas canvas, Size size) { - final double side = size.shortestSide / 2; - final Offset center = size.center(Offset.zero); - - final Paint paint = Paint() - ..color = Colors.black - ..style = PaintingStyle.stroke - ..strokeWidth = 2 - ..strokeCap = StrokeCap.round; - final Paint iconPaint = Paint() - ..color = Colors.orange - ..strokeWidth = 2 - ..style = PaintingStyle.stroke; - - _drawAxis( - _Axis.x, - canvas, - paint, - iconPaint, - side: side, - start: center, - end: center - Offset(side, 0), - arrowOffset1: const Offset(8, 8), - arrowOffset2: const Offset(8, -8), - arcStartAngle: pi - pi / 6, - arcSweepAngle: -2 * pi + pi / 3, - text: 'Roll', - ); - - _drawAxis( - _Axis.y, - canvas, - paint, - iconPaint, - side: side, - start: center, - end: center + Offset(0, side), - arrowOffset1: const Offset(-8, -8), - arrowOffset2: const Offset(8, -8), - arcStartAngle: pi - pi / 6, - arcSweepAngle: -2 * pi + pi / 3, - text: 'Pitch', - ); - - _drawAxis( - _Axis.z, - canvas, - paint, - iconPaint, - side: side, - start: center, - end: center + Offset(0, side), - arrowOffset1: const Offset(-8, -8), - arrowOffset2: const Offset(8, -8), - arcStartAngle: pi - pi / 6, - arcSweepAngle: -2 * pi + pi / 3, - text: 'Yaw', - ); - - final double cathetus = sqrt(side * side / 2); - final Offset zAxisEnd = center + Offset(cathetus, -cathetus); - canvas.drawLine( - center, - zAxisEnd, - paint, - ); - canvas.drawLine( - zAxisEnd, - zAxisEnd + const Offset(0, 12), - paint, - ); - canvas.drawLine( - zAxisEnd, - zAxisEnd - const Offset(12, 0), - paint, - ); - } - - void _drawAxis( - _Axis axis, - Canvas canvas, - Paint paint, - Paint iconPaint, { - required double side, - required Offset start, - required Offset end, - required Offset arrowOffset1, - required Offset arrowOffset2, - required double arcStartAngle, - required double arcSweepAngle, - required String text, - }) { - _drawLine( - canvas, - paint, - from: start, - to: end, - arrowOffset1: arrowOffset1, - arrowOffset2: arrowOffset2, - ); - _drawArc( - canvas, - iconPaint, - side: side, - start: end, - startAngle: arcStartAngle, - sweepAngle: arcSweepAngle, - ); - _paintText( - canvas, - text: text, - maxWidth: side / 2, - offset: Offset( - end.dx + side / 4 + 16, - end.dy - 64, - ), - ); - } - - void _drawLine( - Canvas canvas, - Paint paint, { - required Offset from, - required Offset to, - required Offset arrowOffset1, - required Offset arrowOffset2, - }) { - canvas.drawLine( - from, - to, - paint, - ); - canvas.drawLine( - to, - to + arrowOffset1, - paint, - ); - canvas.drawLine( - to, - to + arrowOffset2, - paint, - ); - } - - void _drawArc( - Canvas canvas, - Paint paint, { - required double side, - required Offset start, - required double startAngle, - required double sweepAngle, - }) { - const double yOffset = 40; - const sideFactor = 0.25; - - final double xOffset = -side * sideFactor; - - canvas.drawArc( - start - Offset(xOffset, yOffset) & const Size.square(32), - startAngle, - sweepAngle, - false, - paint, - ); - canvas.drawLine( - start - Offset(xOffset - 3, yOffset - 7), - start - Offset(xOffset - 6, yOffset + 2), - paint, - ); - canvas.drawLine( - start - Offset(xOffset - 3, yOffset - 7), - start - Offset(xOffset - 12, yOffset - 7), - paint, - ); - } - - void _paintText( - Canvas canvas, { - required String text, - required double maxWidth, - required Offset offset, - }) { - final TextPainter textPainter = TextPainter( - text: TextSpan( - text: text, - style: const TextStyle( - color: Colors.orange, - fontSize: 16, - ), - ), - textDirection: TextDirection.ltr, - ); - - textPainter.layout( - minWidth: 0, - maxWidth: maxWidth, - ); - - textPainter.paint( - canvas, - offset - - Offset( - textPainter.width, - textPainter.height, - ) / - 2, - ); - } - - @override - bool shouldRepaint(CoordinateSystemPainter oldDelegate) => false; - - @override - bool shouldRebuildSemantics(CoordinateSystemPainter oldDelegate) => false; -} From 7af1d914e98ef5626892a76e47a4db7dfe59cd3b Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Fri, 25 Oct 2024 18:31:20 +0700 Subject: [PATCH 2/7] refactor: added missing doc --- lib/gravity_sensor.dart | 1 + lib/gravity_sensor_method_channel.dart | 18 ++++++++++-------- lib/gravity_sensor_platform_interface.dart | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/gravity_sensor.dart b/lib/gravity_sensor.dart index 74bf7d2..32bc06d 100644 --- a/lib/gravity_sensor.dart +++ b/lib/gravity_sensor.dart @@ -2,6 +2,7 @@ import 'gravity_sensor_platform_interface.dart'; export 'src/gravity_event.dart'; +/// API for accessing information from gravity sensor of the device. class GravitySensor extends GravitySensorPlatform { GravitySensor._(); diff --git a/lib/gravity_sensor_method_channel.dart b/lib/gravity_sensor_method_channel.dart index f23e89c..fd6f977 100644 --- a/lib/gravity_sensor_method_channel.dart +++ b/lib/gravity_sensor_method_channel.dart @@ -10,13 +10,15 @@ class MethodChannelGravitySensor extends GravitySensorPlatform { @override Stream get gravityEvents { - return _gravityEvents ??= _gravityEventChannel.receiveBroadcastStream().map((dynamic event) { - final list = event.cast(); - return GravityEvent( - list[0]!, - list[1]!, - list[2]!, - ); - }); + return _gravityEvents ??= _gravityEventChannel.receiveBroadcastStream().map( + (dynamic event) { + final list = event.cast(); + return GravityEvent( + list[0]!, + list[1]!, + list[2]!, + ); + }, + ); } } diff --git a/lib/gravity_sensor_platform_interface.dart b/lib/gravity_sensor_platform_interface.dart index 13b2da3..0943169 100644 --- a/lib/gravity_sensor_platform_interface.dart +++ b/lib/gravity_sensor_platform_interface.dart @@ -5,6 +5,7 @@ import 'src/gravity_event.dart'; export 'src/gravity_event.dart'; +/// The common platform interface for gravity sensor. abstract class GravitySensorPlatform extends PlatformInterface { /// Constructs a GravitySensorPlatform. GravitySensorPlatform() : super(token: _token); From cb87e2464abb2fd4a38310f8736a6e862a73577c Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Fri, 25 Oct 2024 18:33:38 +0700 Subject: [PATCH 3/7] refactor: bump flutter_lints to 5.0.0 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 67d72e8..f33eaa9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,7 +18,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^3.0.1 + flutter_lints: ^5.0.0 flutter: plugin: From 0825d522f220bc97a9ba3b3b265f6dbccf33f251 Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Mon, 28 Oct 2024 18:50:47 +0700 Subject: [PATCH 4/7] refactor: reorganize source files in `src` --- lib/gravity_sensor.dart | 5 +++-- lib/{ => src}/gravity_sensor_method_channel.dart | 1 + lib/{ => src}/gravity_sensor_platform_interface.dart | 4 +--- lib/src/{ => models}/gravity_event.dart | 0 4 files changed, 5 insertions(+), 5 deletions(-) rename lib/{ => src}/gravity_sensor_method_channel.dart (94%) rename lib/{ => src}/gravity_sensor_platform_interface.dart (94%) rename lib/src/{ => models}/gravity_event.dart (100%) diff --git a/lib/gravity_sensor.dart b/lib/gravity_sensor.dart index 32bc06d..ee00425 100644 --- a/lib/gravity_sensor.dart +++ b/lib/gravity_sensor.dart @@ -1,6 +1,7 @@ -import 'gravity_sensor_platform_interface.dart'; +import 'src/gravity_sensor_platform_interface.dart'; +import 'src/models/gravity_event.dart'; -export 'src/gravity_event.dart'; +export 'src/models/gravity_event.dart'; /// API for accessing information from gravity sensor of the device. class GravitySensor extends GravitySensorPlatform { diff --git a/lib/gravity_sensor_method_channel.dart b/lib/src/gravity_sensor_method_channel.dart similarity index 94% rename from lib/gravity_sensor_method_channel.dart rename to lib/src/gravity_sensor_method_channel.dart index fd6f977..c4f3fc0 100644 --- a/lib/gravity_sensor_method_channel.dart +++ b/lib/src/gravity_sensor_method_channel.dart @@ -1,6 +1,7 @@ import 'package:flutter/services.dart'; import 'gravity_sensor_platform_interface.dart'; +import 'models/gravity_event.dart'; /// An implementation of [GravitySensorPlatform] that uses method channels. class MethodChannelGravitySensor extends GravitySensorPlatform { diff --git a/lib/gravity_sensor_platform_interface.dart b/lib/src/gravity_sensor_platform_interface.dart similarity index 94% rename from lib/gravity_sensor_platform_interface.dart rename to lib/src/gravity_sensor_platform_interface.dart index 0943169..f5d53ec 100644 --- a/lib/gravity_sensor_platform_interface.dart +++ b/lib/src/gravity_sensor_platform_interface.dart @@ -1,9 +1,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'gravity_sensor_method_channel.dart'; -import 'src/gravity_event.dart'; - -export 'src/gravity_event.dart'; +import 'models/gravity_event.dart'; /// The common platform interface for gravity sensor. abstract class GravitySensorPlatform extends PlatformInterface { diff --git a/lib/src/gravity_event.dart b/lib/src/models/gravity_event.dart similarity index 100% rename from lib/src/gravity_event.dart rename to lib/src/models/gravity_event.dart From e8b42e063149d7327d100ce85f39b6841cfd18a9 Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Mon, 28 Oct 2024 18:52:17 +0700 Subject: [PATCH 5/7] feat: throwing `FormatException` on invalid event --- lib/src/gravity_sensor_method_channel.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/gravity_sensor_method_channel.dart b/lib/src/gravity_sensor_method_channel.dart index c4f3fc0..293d125 100644 --- a/lib/src/gravity_sensor_method_channel.dart +++ b/lib/src/gravity_sensor_method_channel.dart @@ -13,11 +13,15 @@ class MethodChannelGravitySensor extends GravitySensorPlatform { Stream get gravityEvents { return _gravityEvents ??= _gravityEventChannel.receiveBroadcastStream().map( (dynamic event) { + if (event is! List || event.length < 3) { + throw FormatException('Invalid event format'); + } final list = event.cast(); + return GravityEvent( - list[0]!, - list[1]!, - list[2]!, + list[0], + list[1], + list[2], ); }, ); From 94d2bfb5110a493af8f132142245fb1608fc69b6 Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Mon, 28 Oct 2024 18:55:13 +0700 Subject: [PATCH 6/7] chore: bump version to 1.0.1 --- CHANGELOG.md | 6 ++++++ pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d8803f..32e9de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.0.1 + +- **DOCS**: Provided documentation for `GravitySensor` and `GravitySensorPlatform`. +- **CHORE**: Updated `flutter_lints` to `^5.0.0`. +- **FEAT**: gravityEvents now can throw `FormatException` if the event format is invalid. + ## 1.0.0 * Initial release. diff --git a/pubspec.yaml b/pubspec.yaml index f33eaa9..9054735 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: gravity_sensor -version: 1.0.0 +version: 1.0.1 description: Flutter plugin to access the gravity sensor of the device. homepage: https://madbrains.ru/ repository: https://github.com/MadBrains/Gravity-Sensor-Flutter From 24a090f1d65becc78553f44ddd7f0be91854fe6f Mon Sep 17 00:00:00 2001 From: kishkihihi Date: Tue, 29 Oct 2024 12:21:23 +0700 Subject: [PATCH 7/7] chore: example uses same environment constraints as plugin --- example/pubspec.lock | 6 +++--- example/pubspec.yaml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 816d6b3..50e4235 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -99,7 +99,7 @@ packages: path: ".." relative: true source: path - version: "1.0.0" + version: "1.0.1" integration_test: dependency: "direct dev" description: flutter @@ -279,5 +279,5 @@ packages: source: hosted version: "3.0.3" sdks: - dart: ">=3.3.0 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" + dart: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 49354eb..bea61b7 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,8 @@ description: "Demonstrates how to use the gravity_sensor plugin." publish_to: 'none' # Remove this line if you wish to publish to pub.dev environment: - sdk: '>=3.2.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' + flutter: '>=3.10.0' # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions