forked from firka/flutter
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: avoid_dynamic_calls
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
@@ -53,19 +55,19 @@ class AndroidSemanticsNode {
|
||||
/// ]
|
||||
/// }
|
||||
factory AndroidSemanticsNode.deserialize(String value) {
|
||||
return AndroidSemanticsNode._(json.decode(value) as Map<String, Object>);
|
||||
return AndroidSemanticsNode._(json.decode(value));
|
||||
}
|
||||
|
||||
final Map<String, Object> _values;
|
||||
final dynamic _values;
|
||||
final List<AndroidSemanticsNode> _children = <AndroidSemanticsNode>[];
|
||||
|
||||
Map<String, Object> get _flags => _values['flags'] as Map<String, Object>;
|
||||
dynamic get _flags => _values['flags'];
|
||||
|
||||
/// The text value of the semantics node.
|
||||
///
|
||||
/// This is produced by combining the value, label, and hint fields from
|
||||
/// the Flutter [SemanticsNode].
|
||||
String get text => _values['text'] as String;
|
||||
String? get text => _values['text'] as String?;
|
||||
|
||||
/// The contentDescription of the semantics node.
|
||||
///
|
||||
@@ -75,7 +77,7 @@ class AndroidSemanticsNode {
|
||||
///
|
||||
/// This is produced by combining the value, label, and hint fields from
|
||||
/// the Flutter [SemanticsNode].
|
||||
String get contentDescription => _values['contentDescription'] as String;
|
||||
String? get contentDescription => _values['contentDescription'] as String?;
|
||||
|
||||
/// The className of the semantics node.
|
||||
///
|
||||
@@ -84,10 +86,10 @@ class AndroidSemanticsNode {
|
||||
///
|
||||
/// If a more specific value isn't provided, it defaults to
|
||||
/// "android.view.View".
|
||||
String get className => _values['className'] as String;
|
||||
String? get className => _values['className'] as String?;
|
||||
|
||||
/// The identifier for this semantics node.
|
||||
int get id => _values['id'] as int;
|
||||
int? get id => _values['id'] as int?;
|
||||
|
||||
/// The children of this semantics node.
|
||||
List<AndroidSemanticsNode> get children => _children;
|
||||
@@ -95,50 +97,52 @@ class AndroidSemanticsNode {
|
||||
/// Whether the node is currently in a checked state.
|
||||
///
|
||||
/// Equivalent to [SemanticsFlag.isChecked].
|
||||
bool get isChecked => _flags['isChecked'] as bool;
|
||||
bool? get isChecked => _flags['isChecked'] as bool?;
|
||||
|
||||
/// Whether the node can be in a checked state.
|
||||
///
|
||||
/// Equivalent to [SemanticsFlag.hasCheckedState]
|
||||
bool get isCheckable => _flags['isCheckable'] as bool;
|
||||
bool? get isCheckable => _flags['isCheckable'] as bool?;
|
||||
|
||||
/// Whether the node is editable.
|
||||
///
|
||||
/// This is usually only applied to text fields, which map
|
||||
/// to "android.widget.EditText".
|
||||
bool get isEditable => _flags['isEditable'] as bool;
|
||||
bool? get isEditable => _flags['isEditable'] as bool?;
|
||||
|
||||
/// Whether the node is enabled.
|
||||
bool get isEnabled => _flags['isEnabled'] as bool;
|
||||
bool? get isEnabled => _flags['isEnabled'] as bool?;
|
||||
|
||||
/// Whether the node is focusable.
|
||||
bool get isFocusable => _flags['isFocusable'] as bool;
|
||||
bool? get isFocusable => _flags['isFocusable'] as bool?;
|
||||
|
||||
/// Whether the node is focused.
|
||||
bool get isFocused => _flags['isFocused'] as bool;
|
||||
bool? get isFocused => _flags['isFocused'] as bool?;
|
||||
|
||||
/// Whether the node is considered a heading.
|
||||
bool get isHeading => _flags['isHeading'] as bool;
|
||||
bool? get isHeading => _flags['isHeading'] as bool?;
|
||||
|
||||
/// Whether the node represents a password field.
|
||||
///
|
||||
/// Equivalent to [SemanticsFlag.isObscured].
|
||||
bool get isPassword => _flags['isPassword'] as bool;
|
||||
bool? get isPassword => _flags['isPassword'] as bool?;
|
||||
|
||||
/// Whether the node is long clickable.
|
||||
///
|
||||
/// Equivalent to having [SemanticsAction.longPress].
|
||||
bool get isLongClickable => _flags['isLongClickable'] as bool;
|
||||
bool? get isLongClickable => _flags['isLongClickable'] as bool?;
|
||||
|
||||
/// Gets a [Rect] which defines the position and size of the semantics node.
|
||||
Rect getRect() {
|
||||
final Map<String, Object> rawRect = _values['rect'] as Map<String, Object>;
|
||||
final Map<String, int> rect = rawRect.cast<String, int>();
|
||||
final dynamic rawRect = _values['rect'];
|
||||
if (rawRect == null) {
|
||||
return const Rect.fromLTRB(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
return Rect.fromLTRB(
|
||||
rect['left'].toDouble(),
|
||||
rect['top'].toDouble(),
|
||||
rect['right'].toDouble(),
|
||||
rect['bottom'].toDouble(),
|
||||
(rawRect['left']! as int).toDouble(),
|
||||
(rawRect['top']! as int).toDouble(),
|
||||
(rawRect['right']! as int).toDouble(),
|
||||
(rawRect['bottom']! as int).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -149,9 +153,20 @@ class AndroidSemanticsNode {
|
||||
}
|
||||
|
||||
/// Gets a list of [AndroidSemanticsActions] which are defined for the node.
|
||||
List<AndroidSemanticsAction> getActions() => <AndroidSemanticsAction>[
|
||||
for (final int id in (_values['actions'] as List<dynamic>).cast<int>()) AndroidSemanticsAction.deserialize(id),
|
||||
];
|
||||
List<AndroidSemanticsAction> getActions() {
|
||||
final List<int>? actions = (_values['actions'] as List<dynamic>?)?.cast<int>();
|
||||
if (actions == null) {
|
||||
return const <AndroidSemanticsAction>[];
|
||||
}
|
||||
final List<AndroidSemanticsAction> convertedActions = <AndroidSemanticsAction>[];
|
||||
for (final int id in actions) {
|
||||
final AndroidSemanticsAction? action = AndroidSemanticsAction.deserialize(id);
|
||||
if (action != null) {
|
||||
convertedActions.add(action);
|
||||
}
|
||||
}
|
||||
return convertedActions;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
Reference in New Issue
Block a user