diff --git a/README.md b/README.md index dfaa7e9..57b3649 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ An APM library for detecting UI jank in Flutter for mobile (Android/iOS). **NOTE:** This package is experimental. APIs may change without notice before the stable version 1.0. -`glance` detects UI jank during the build phase and from "external sources", such as `WidgetBindingObserver` callbacks, touch events, and method channel callbacks. These cover most cases that cause UI jank. It works only when you build your application with the `--split-debug-info` option, see https://docs.flutter.dev/deployment/obfuscate#obfuscate-your-app for more detail. - -Run `glance` in release or profile build, as detecting UI jank in debug mode is not meaningful. +`glance` detects UI jank during the build phase as well as through various callbacks, such as, `WidgetBindingObserver` callbacks, touch events, and method channel callbacks. These cover most cases that cause UI jank. It works only in release or profile builds when your application is built with the [`--split-debug-info` option](https://docs.flutter.dev/deployment/obfuscate#obfuscate-your-app). ## Getting Started diff --git a/lib/src/glance.dart b/lib/src/glance.dart index c8e6c6f..d210c42 100644 --- a/lib/src/glance.dart +++ b/lib/src/glance.dart @@ -93,7 +93,7 @@ abstract class Glance { static Glance? _instance; static Glance get instance { - _instance ??= GlanceImpl(); + _instance ??= GlanceImpl.create(kDebugMode); return _instance!; } diff --git a/lib/src/glance_impl.dart b/lib/src/glance_impl.dart index 9b915f7..3633e4e 100644 --- a/lib/src/glance_impl.dart +++ b/lib/src/glance_impl.dart @@ -11,9 +11,27 @@ import 'package:glance/src/glance.dart'; import 'package:glance/src/sampler.dart'; import 'package:meta/meta.dart' show visibleForTesting, internal; +/// No-op implementation of [Glance]. +class GlanceNoOpImpl implements Glance { + @override + Future end() async {} + + @override + Future start( + {GlanceConfiguration config = const GlanceConfiguration()}) async {} +} + /// Implementation of [Glance] class GlanceImpl implements Glance { - GlanceImpl(); + static Glance create(bool isNoOp) { + if (isNoOp) { + return GlanceNoOpImpl(); + } + + return GlanceImpl._(); + } + + GlanceImpl._(); @visibleForTesting GlanceImpl.forTesting(Sampler sampler) : _sampler = sampler; diff --git a/test/glance_impl_test.dart b/test/glance_impl_test.dart index 5322c70..874c4ad 100644 --- a/test/glance_impl_test.dart +++ b/test/glance_impl_test.dart @@ -51,6 +51,18 @@ void main() { glance = GlanceImpl.forTesting(sampler); }); + group('GlanceImpl.create', () { + test('return GlanceImpl', () { + final instance = GlanceImpl.create(false); + expect(instance, isInstanceOf()); + }); + + test('return GlanceNoOpImpl', () { + final instance = GlanceImpl.create(true); + expect(instance, isInstanceOf()); + }); + }); + group('GlanceWidgetBindingMixin', () { test( 'call onCheckJank when calling traceFunctionCall if it is in SchedulerPhase.idle',