// 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.import'dart:async';import'package:flutter_driver/driver_extension.dart';typedefDriverHandler=Future<String>Function();/// Wraps a flutter driver [DataHandler] with one that waits until a delegate is set.////// This allows the driver test to call [FlutterDriver.requestData] before the handler was/// set by the app in which case the requestData call will only complete once the app is ready/// for it.classFutureDataHandler{finalMap<String,Completer<DriverHandler>>_handlers=<String,Completer<DriverHandler>>{};/// Registers a lazy handler that will be invoked on the next message from the driver.Completer<DriverHandler>registerHandler(Stringkey){_handlers[key]=Completer<DriverHandler>();return_handlers[key];}Future<String>handleMessage(Stringmessage)async{if(_handlers[message]==null){return'Unsupported driver message: $message.\n''Supported messages are: ${_handlers.keys}.';}finalDriverHandlerhandler=await_handlers[message].future;returnhandler();}}FutureDataHandlerdriverDataHandler=FutureDataHandler();