setShowTouches method

Future<TouchesOutcome> setShowTouches(
  1. bool on
)

Shows or hides a dot for each touch inside the app; never throws.

Implementation

Future<TouchesOutcome> setShowTouches(bool on) async {
  showTouches = on;
  final system = await _setSystemTouches(on);
  final rt = runtime;
  final agent = rt == null || deviceMode ? null : AppAgent.of(rt);
  if (agent == null && system.on) return const TouchesOutcome(true, system: true);
  if (agent == null) {
    return TouchesOutcome(false,
        errorKind: GlintErrorKind.flutterModeRequired,
        detail: 'touches are drawn inside the Flutter app, and $label is in device mode with no Flutter VM',
        nextSteps: const ['attach to the running Flutter app (without mode:"device") to show touches']);
  }
  try {
    final reply = await agent.setTouches(on, ownOnly: system.on);
    if (reply['on'] == on) return TouchesOutcome(on, system: system.on, systemDetail: system.why);
    return TouchesOutcome(false,
        errorKind: GlintErrorKind.unsupportedBackendAction,
        detail: reply['reason'] == 'notDebug'
            ? 'the app runs without asserts (not a debug build), and Flutter only draws debug overlays in debug builds'
            : 'the in-app agent answered ${reply['reason'] ?? reply}',
        nextSteps: const ['run the app in debug mode (flutter run), then attach again']);
  } on RuntimeConnectionLostError catch (e) {
    return TouchesOutcome(false,
        errorKind: GlintErrorKind.connectionLost,
        detail: '$e',
        nextSteps: const ['relaunch the app, then `attach` again']);
  } on RuntimeUnresponsiveError catch (e) {
    return TouchesOutcome(false,
        errorKind: GlintErrorKind.appUnresponsive,
        detail: '$e',
        nextSteps: const ['if a debugger paused the app, resume it; then set showTouches again']);
  } on Object catch (e) {
    return TouchesOutcome(false,
        errorKind: GlintErrorKind.backendToolError,
        detail: '$e',
        nextSteps: const ['set showTouches again; if it keeps failing, `report_issue` with the user\'s OK']);
  }
}