Create enum for scheduler service extension names so they can be accessed from tooling (#111222)
* Create enum for scheduler service extension names so they can be accessed from tooling * fix two more strings
This commit is contained in:
@@ -16,4 +16,5 @@ library scheduler;
|
||||
export 'src/scheduler/binding.dart';
|
||||
export 'src/scheduler/debug.dart';
|
||||
export 'src/scheduler/priority.dart';
|
||||
export 'src/scheduler/service_extensions.dart';
|
||||
export 'src/scheduler/ticker.dart';
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'debug.dart';
|
||||
import 'priority.dart';
|
||||
import 'service_extensions.dart';
|
||||
|
||||
export 'dart:developer' show Flow;
|
||||
export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback;
|
||||
@@ -355,7 +356,7 @@ mixin SchedulerBinding on BindingBase {
|
||||
|
||||
if (!kReleaseMode) {
|
||||
registerNumericServiceExtension(
|
||||
name: 'timeDilation',
|
||||
name: SchedulerServiceExtensions.timeDilation.name,
|
||||
getter: () async => timeDilation,
|
||||
setter: (double value) async {
|
||||
timeDilation = value;
|
||||
|
||||
24
packages/flutter/lib/src/scheduler/service_extensions.dart
Normal file
24
packages/flutter/lib/src/scheduler/service_extensions.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// Service extension constants for the scheduler library.
|
||||
///
|
||||
/// These constants will be used when registering service extensions in the
|
||||
/// framework, and they will also be used by tools and services that call these
|
||||
/// service extensions.
|
||||
///
|
||||
/// The String value for each of these extension names should be accessed by
|
||||
/// calling the `.name` property on the enum value.
|
||||
enum SchedulerServiceExtensions {
|
||||
/// Name of service extension that, when called, will change the value of
|
||||
/// [timeDilation], which determines the factor by which to slow down
|
||||
/// animations for help in development.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [timeDilation], which is the field that this service extension exposes.
|
||||
/// * [SchedulerBinding.initServiceExtensions], where the service extension is
|
||||
/// registered.
|
||||
timeDilation,
|
||||
}
|
||||
@@ -894,30 +894,30 @@ void main() {
|
||||
|
||||
expect(binding.frameScheduled, isFalse);
|
||||
expect(timeDilation, 1.0);
|
||||
result = await binding.testExtension('timeDilation', <String, String>{});
|
||||
expect(result, <String, String>{'timeDilation': 1.0.toString()});
|
||||
result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
|
||||
expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
|
||||
expect(timeDilation, 1.0);
|
||||
expect(extensionChangedEvents, isEmpty);
|
||||
result = await binding.testExtension('timeDilation', <String, String>{'timeDilation': '100.0'});
|
||||
expect(result, <String, String>{'timeDilation': 100.0.toString()});
|
||||
result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{SchedulerServiceExtensions.timeDilation.name: '100.0'});
|
||||
expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 100.0.toString()});
|
||||
expect(timeDilation, 100.0);
|
||||
expect(extensionChangedEvents.length, 1);
|
||||
extensionChangedEvent = extensionChangedEvents.last;
|
||||
expect(extensionChangedEvent['extension'], 'ext.flutter.timeDilation');
|
||||
expect(extensionChangedEvent['extension'], 'ext.flutter.${SchedulerServiceExtensions.timeDilation.name}');
|
||||
expect(extensionChangedEvent['value'], 100.0.toString());
|
||||
result = await binding.testExtension('timeDilation', <String, String>{});
|
||||
expect(result, <String, String>{'timeDilation': 100.0.toString()});
|
||||
result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
|
||||
expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 100.0.toString()});
|
||||
expect(timeDilation, 100.0);
|
||||
expect(extensionChangedEvents.length, 1);
|
||||
result = await binding.testExtension('timeDilation', <String, String>{'timeDilation': '1.0'});
|
||||
expect(result, <String, String>{'timeDilation': 1.0.toString()});
|
||||
result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{SchedulerServiceExtensions.timeDilation.name: '1.0'});
|
||||
expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
|
||||
expect(timeDilation, 1.0);
|
||||
expect(extensionChangedEvents.length, 2);
|
||||
extensionChangedEvent = extensionChangedEvents.last;
|
||||
expect(extensionChangedEvent['extension'], 'ext.flutter.timeDilation');
|
||||
expect(extensionChangedEvent['extension'], 'ext.flutter.${SchedulerServiceExtensions.timeDilation.name}');
|
||||
expect(extensionChangedEvent['value'], 1.0.toString());
|
||||
result = await binding.testExtension('timeDilation', <String, String>{});
|
||||
expect(result, <String, String>{'timeDilation': 1.0.toString()});
|
||||
result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
|
||||
expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
|
||||
expect(timeDilation, 1.0);
|
||||
expect(extensionChangedEvents.length, 2);
|
||||
expect(binding.frameScheduled, isFalse);
|
||||
|
||||
Reference in New Issue
Block a user