mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Create enum for service extensions in services library (#111412)
This commit is contained in:
parent
11fdced50f
commit
a34e6b0792
@ -37,6 +37,7 @@ export 'src/services/raw_keyboard_macos.dart';
|
|||||||
export 'src/services/raw_keyboard_web.dart';
|
export 'src/services/raw_keyboard_web.dart';
|
||||||
export 'src/services/raw_keyboard_windows.dart';
|
export 'src/services/raw_keyboard_windows.dart';
|
||||||
export 'src/services/restoration.dart';
|
export 'src/services/restoration.dart';
|
||||||
|
export 'src/services/service_extensions.dart';
|
||||||
export 'src/services/spell_check.dart';
|
export 'src/services/spell_check.dart';
|
||||||
export 'src/services/system_channels.dart';
|
export 'src/services/system_channels.dart';
|
||||||
export 'src/services/system_chrome.dart';
|
export 'src/services/system_chrome.dart';
|
||||||
|
@ -15,6 +15,7 @@ import 'binary_messenger.dart';
|
|||||||
import 'hardware_keyboard.dart';
|
import 'hardware_keyboard.dart';
|
||||||
import 'message_codec.dart';
|
import 'message_codec.dart';
|
||||||
import 'restoration.dart';
|
import 'restoration.dart';
|
||||||
|
import 'service_extensions.dart';
|
||||||
import 'system_channels.dart';
|
import 'system_channels.dart';
|
||||||
import 'text_input.dart';
|
import 'text_input.dart';
|
||||||
|
|
||||||
@ -213,11 +214,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
|
|||||||
|
|
||||||
assert(() {
|
assert(() {
|
||||||
registerStringServiceExtension(
|
registerStringServiceExtension(
|
||||||
// ext.flutter.evict value=foo.png will cause foo.png to be evicted from
|
name: ServicesServiceExtensions.evict.name,
|
||||||
// the rootBundle cache and cause the entire image cache to be cleared.
|
|
||||||
// This is used by hot reload mode to clear out the cache of resources
|
|
||||||
// that have changed.
|
|
||||||
name: 'evict',
|
|
||||||
getter: () async => '',
|
getter: () async => '',
|
||||||
setter: (String value) async {
|
setter: (String value) async {
|
||||||
evict(value);
|
evict(value);
|
||||||
|
26
packages/flutter/lib/src/services/service_extensions.dart
Normal file
26
packages/flutter/lib/src/services/service_extensions.dart
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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 services 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 ServicesServiceExtensions {
|
||||||
|
/// Name of service extension that, when called, will evict an image from the
|
||||||
|
/// rootBundle cache and cause the image cache to be cleared.
|
||||||
|
///
|
||||||
|
/// This is used by hot reload mode to clear out the cache of resources that
|
||||||
|
/// have changed. This service extension should be called with a String value
|
||||||
|
/// of the image path (e.g. foo.png).
|
||||||
|
///
|
||||||
|
/// See also:
|
||||||
|
///
|
||||||
|
/// * [ServicesBinding.initServiceExtensions], where the service extension is
|
||||||
|
/// registered.
|
||||||
|
evict,
|
||||||
|
}
|
@ -563,7 +563,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
expect(data, isTrue);
|
expect(data, isTrue);
|
||||||
expect(completed, isFalse);
|
expect(completed, isFalse);
|
||||||
result = await binding.testExtension('evict', <String, String>{'value': 'test'});
|
result = await binding.testExtension(ServicesServiceExtensions.evict.name, <String, String>{'value': 'test'});
|
||||||
expect(result, <String, String>{'value': ''});
|
expect(result, <String, String>{'value': ''});
|
||||||
expect(completed, isFalse);
|
expect(completed, isFalse);
|
||||||
data = await rootBundle.loadStructuredData<bool>('test', (String value) async {
|
data = await rootBundle.loadStructuredData<bool>('test', (String value) async {
|
||||||
|
Loading…
Reference in New Issue
Block a user