File size: 2,525 Bytes
4e917e6 346a42c 4e917e6 346a42c 4e917e6 346a42c 4e917e6 346a42c 4e917e6 346a42c 4e917e6 346a42c 4e917e6 | 1 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | // 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 'enum_util.dart';
import 'find.dart';
import 'message.dart';
/// Offset types that can be requested by [GetOffset].
enum OffsetType {
/// The top left point.
topLeft,
/// The top right point.
topRight,
/// The bottom left point.
bottomLeft,
/// The bottom right point.
bottomRight,
/// The center point.
center,
}
EnumIndex<OffsetType> _offsetTypeIndex = EnumIndex<OffsetType>(OffsetType.values);
/// A Flutter Driver command that returns the [offsetType] from the RenderObject
/// identified by [finder].
///
/// The requested offset is returned in logical pixels, which can be translated
/// to device pixels via [dart:ui.FlutterView.devicePixelRatio].
class GetOffset extends CommandWithTarget {
/// The `finder` looks for an element to get its rect.
GetOffset(super.finder, this.offsetType, {super.timeout});
/// Deserializes this command from the value generated by [serialize].
GetOffset.deserialize(super.json, super.finderFactory)
: offsetType = _offsetTypeIndex.lookupBySimpleName(json['offsetType']!),
super.deserialize();
@override
Map<String, String> serialize() =>
super.serialize()
..addAll(<String, String>{'offsetType': _offsetTypeIndex.toSimpleName(offsetType)});
/// The type of the requested offset.
final OffsetType offsetType;
@override
String get kind => 'get_offset';
}
/// The result of the [GetOffset] command.
///
/// The offset is provided in logical pixels, which can be translated
/// to device pixels via [dart:ui.FlutterView.devicePixelRatio].
class GetOffsetResult extends Result {
/// Creates a result with the offset defined by [dx] and [dy].
const GetOffsetResult({this.dx = 0.0, this.dy = 0.0});
/// The x component of the offset in logical pixels.
///
/// The value can be translated to device pixels via
/// [dart:ui.FlutterView.devicePixelRatio].
final double dx;
/// The y component of the offset in logical pixels.
///
/// The value can be translated to device pixels via
/// [dart:ui.FlutterView.devicePixelRatio].
final double dy;
/// Deserializes the result from JSON.
static GetOffsetResult fromJson(Map<String, dynamic> json) {
return GetOffsetResult(dx: json['dx'] as double, dy: json['dy'] as double);
}
@override
Map<String, dynamic> toJson() => <String, double>{'dx': dx, 'dy': dy};
}
|