touches_scenario.dart 777 字节
Newer Older
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:ui';

import 'scenario.dart';

/// A scenario that sends back messages when touches are received.
class TouchesScenario extends Scenario {
  /// Constructor for `TouchesScenario`.
  TouchesScenario(Window window) : super(window);

  @override
  void onPointerDataPacket(PointerDataPacket packet) {
    window.sendPlatformMessage(
      'touches_scenario',
      utf8.encoder
          .convert(const JsonCodec().encode(<String, dynamic>{
            'change': packet.data[0].change.toString(),
          }))
          .buffer
          .asByteData(),
      null,
    );
  }
}