Introduce DoctorValidatorsProvider to improve extensibility of flutter_tools (#16918)
DoctorValidatorsProvider is injected into Doctor to allow overriding of DoctorValidators without needing to override the whole Doctor instance.
This commit is contained in:
@@ -56,7 +56,8 @@ Future<T> runInContext<T>(
|
||||
Config: () => new Config(),
|
||||
DevFSConfig: () => new DevFSConfig(),
|
||||
DeviceManager: () => new DeviceManager(),
|
||||
Doctor: () => new Doctor(),
|
||||
Doctor: () => const Doctor(),
|
||||
DoctorValidatorsProvider: () => DoctorValidatorsProvider.defaultInstance,
|
||||
Flags: () => const EmptyFlags(),
|
||||
FlutterVersion: () => new FlutterVersion(const Clock()),
|
||||
GenSnapshot: () => const GenSnapshot(),
|
||||
|
||||
@@ -26,15 +26,19 @@ import 'vscode/vscode_validator.dart';
|
||||
|
||||
Doctor get doctor => context[Doctor];
|
||||
|
||||
class ValidatorTask {
|
||||
ValidatorTask(this.validator, this.result);
|
||||
final DoctorValidator validator;
|
||||
final Future<ValidationResult> result;
|
||||
abstract class DoctorValidatorsProvider {
|
||||
/// The singleton instance, pulled from the [AppContext].
|
||||
static DoctorValidatorsProvider get instance => context[DoctorValidatorsProvider];
|
||||
|
||||
static final DoctorValidatorsProvider defaultInstance = new _DefaultDoctorValidatorsProvider();
|
||||
|
||||
List<DoctorValidator> get validators;
|
||||
}
|
||||
|
||||
class Doctor {
|
||||
class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
List<DoctorValidator> _validators;
|
||||
|
||||
@override
|
||||
List<DoctorValidator> get validators {
|
||||
if (_validators == null) {
|
||||
_validators = <DoctorValidator>[];
|
||||
@@ -60,6 +64,20 @@ class Doctor {
|
||||
}
|
||||
return _validators;
|
||||
}
|
||||
}
|
||||
|
||||
class ValidatorTask {
|
||||
ValidatorTask(this.validator, this.result);
|
||||
final DoctorValidator validator;
|
||||
final Future<ValidationResult> result;
|
||||
}
|
||||
|
||||
class Doctor {
|
||||
const Doctor();
|
||||
|
||||
List<DoctorValidator> get validators {
|
||||
return DoctorValidatorsProvider.instance.validators;
|
||||
}
|
||||
|
||||
/// Return a list of [ValidatorTask] objects and starts validation on all
|
||||
/// objects in [validators].
|
||||
|
||||
Reference in New Issue
Block a user