Fix filtering of emulator list
`flutter emulators nexus` will now return only those that'd match (eg. same things that `flutter emulators --start nexus` would match).
This commit is contained in:
committed by
Danny Tuppeny
parent
3626556d21
commit
445273f7d5
@@ -37,13 +37,17 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
if (argResults.wasParsed('start')) {
|
||||
await _startEmulator(argResults['start']);
|
||||
} else {
|
||||
await _listEmulators();
|
||||
final String searchText =
|
||||
argResults.rest != null && argResults.rest.isNotEmpty
|
||||
? argResults.rest.first
|
||||
: null;
|
||||
await _listEmulators(searchText);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _startEmulator(String id) async {
|
||||
final List<Emulator> emulators =
|
||||
await emulatorManager.getEmulatorsById(id).toList();
|
||||
await emulatorManager.getEmulatorsMatching(id).toList();
|
||||
|
||||
if (emulators.isEmpty) {
|
||||
printStatus("No emulator found that matches '$id'.");
|
||||
@@ -55,9 +59,11 @@ class EmulatorsCommand extends FlutterCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _listEmulators() async {
|
||||
Future<Null> _listEmulators(String searchText) async {
|
||||
final List<Emulator> emulators =
|
||||
await emulatorManager.getAllAvailableEmulators().toList();
|
||||
searchText == null
|
||||
? await emulatorManager.getAllAvailableEmulators().toList()
|
||||
: await emulatorManager.getEmulatorsMatching(searchText).toList();
|
||||
|
||||
if (emulators.isEmpty) {
|
||||
printStatus('No emulators available.\n\n'
|
||||
|
||||
@@ -24,15 +24,15 @@ class EmulatorManager {
|
||||
|
||||
final List<EmulatorDiscovery> _emulatorDiscoverers = <EmulatorDiscovery>[];
|
||||
|
||||
Stream<Emulator> getEmulatorsById(String emulatorId) async* {
|
||||
Stream<Emulator> getEmulatorsMatching(String searchText) async* {
|
||||
final List<Emulator> emulators = await getAllAvailableEmulators().toList();
|
||||
emulatorId = emulatorId.toLowerCase();
|
||||
searchText = searchText.toLowerCase();
|
||||
bool exactlyMatchesEmulatorId(Emulator emulator) =>
|
||||
emulator.id?.toLowerCase() == emulatorId ||
|
||||
emulator.name?.toLowerCase() == emulatorId;
|
||||
emulator.id?.toLowerCase() == searchText ||
|
||||
emulator.name?.toLowerCase() == searchText;
|
||||
bool startsWithEmulatorId(Emulator emulator) =>
|
||||
emulator.id?.toLowerCase()?.startsWith(emulatorId) == true ||
|
||||
emulator.name?.toLowerCase()?.startsWith(emulatorId) == true;
|
||||
emulator.id?.toLowerCase()?.startsWith(searchText) == true ||
|
||||
emulator.name?.toLowerCase()?.startsWith(searchText) == true;
|
||||
|
||||
final Emulator exactMatch = emulators.firstWhere(
|
||||
exactlyMatchesEmulatorId, orElse: () => null);
|
||||
|
||||
@@ -26,7 +26,7 @@ void main() {
|
||||
final EmulatorManager emulatorManager = new TestEmulatorManager(emulators);
|
||||
|
||||
Future<Null> expectEmulator(String id, List<Emulator> expected) async {
|
||||
expect(await emulatorManager.getEmulatorsById(id).toList(), expected);
|
||||
expect(await emulatorManager.getEmulatorsMatching(id).toList(), expected);
|
||||
}
|
||||
expectEmulator('Nexus_5', <Emulator>[emulator1]);
|
||||
expectEmulator('Nexus_5X', <Emulator>[emulator2]);
|
||||
|
||||
Reference in New Issue
Block a user