Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Semantics properties #2731

Merged
merged 13 commits into from
Mar 2, 2024
4 changes: 2 additions & 2 deletions packages/flet/lib/src/controls/alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class _AlertDialogControlState extends State<AlertDialogControl>
actionsPadding: parseEdgeInsets(widget.control, "actionsPadding"),
actionsAlignment: actionsAlignment,
shape: parseOutlinedBorder(widget.control, "shape"),
semanticLabel: widget.control.attrString("semanticsLabel"),
insetPadding: parseEdgeInsets(widget.control, "insetPadding") ??
const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
backgroundColor: HexColor.fromString(
Expand Down Expand Up @@ -141,8 +142,7 @@ class _AlertDialogControlState extends State<AlertDialogControl>
if (shouldDismiss) {
widget.backend
.updateControlState(widget.control.id, {"open": "false"});
widget.backend
.triggerControlEvent(widget.control.id, "dismiss", "");
widget.backend.triggerControlEvent(widget.control.id, "dismiss");
}
});
});
Expand Down
3 changes: 1 addition & 2 deletions packages/flet/lib/src/controls/bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class _BottomSheetControlState extends State<BottomSheetControl> {

if (shouldDismiss) {
resetOpenState();
widget.backend
.triggerControlEvent(widget.control.id, "dismiss", "");
widget.backend.triggerControlEvent(widget.control.id, "dismiss");
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions packages/flet/lib/src/controls/chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _ChipControlState extends State<ChipControl> {

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down Expand Up @@ -111,14 +111,14 @@ class _ChipControlState extends State<ChipControl> {
Function()? onClickHandler = onClick && !disabled
? () {
debugPrint("Chip ${widget.control.id} clicked!");
widget.backend.triggerControlEvent(widget.control.id, "click", "");
widget.backend.triggerControlEvent(widget.control.id, "click");
}
: null;

Function()? onDeleteHandler = onDelete && !disabled
? () {
debugPrint("Chip ${widget.control.id} deleted!");
widget.backend.triggerControlEvent(widget.control.id, "delete", "");
widget.backend.triggerControlEvent(widget.control.id, "delete");
}
: null;

Expand Down
4 changes: 2 additions & 2 deletions packages/flet/lib/src/controls/container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
onLongPress: onLongPress
? () {
debugPrint("Container ${control.id} long pressed!");
backend.triggerControlEvent(control.id, "long_press", "");
backend.triggerControlEvent(control.id, "long_press");
}
: null,
onHover: onHover
Expand Down Expand Up @@ -306,7 +306,7 @@ class ContainerControl extends StatelessWidget with FletStoreMixin {
onLongPress: onLongPress
? () {
debugPrint("Container ${control.id} clicked!");
backend.triggerControlEvent(control.id, "long_press", "");
backend.triggerControlEvent(control.id, "long_press");
}
: null,
child: result,
Expand Down
14 changes: 14 additions & 0 deletions packages/flet/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flet/src/controls/semantics_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';

Expand Down Expand Up @@ -68,6 +69,7 @@ import 'list_view.dart';
import 'markdown.dart';
import 'menu_bar.dart';
import 'menu_item_button.dart';
import 'merge_semantics.dart';
import 'navigation_bar.dart';
import 'navigation_rail.dart';
import 'outlined_button.dart';
Expand Down Expand Up @@ -552,12 +554,24 @@ Widget createWidget(
backend: backend);
case "semantics":
return SemanticsControl(
key: key,
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive,
backend: backend);
case "mergesemantics":
return MergeSemanticsControl(
key: key,
parent: parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled,
parentAdaptive: parentAdaptive);
case "semanticsservice":
return SemanticsServiceControl(
parent: parent, control: controlView.control, backend: backend);
case "shadermask":
return ShaderMaskControl(
key: key,
Expand Down
3 changes: 1 addition & 2 deletions packages/flet/lib/src/controls/cupertino_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class _CupertinoAlertDialogControlState
if (shouldDismiss) {
widget.backend
.updateControlState(widget.control.id, {"open": "false"});
widget.backend
.triggerControlEvent(widget.control.id, "dismiss", "");
widget.backend.triggerControlEvent(widget.control.id, "dismiss");
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _CupertinoButtonControlState extends State<CupertinoButtonControl> {
openWebBrowser(url,
webWindowName: widget.control.attrString("urlTarget"));
}
widget.backend.triggerControlEvent(widget.control.id, "click", "");
widget.backend.triggerControlEvent(widget.control.id, "click");
}
: null;

Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _CheckboxControlState extends State<CupertinoCheckboxControl> {

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CupertinoDialogActionControl extends StatelessWidget {
Function()? onPressed = !disabled
? () {
debugPrint("CupertinoDialogAction ${control.id} clicked!");
backend.triggerControlEvent(control.id, "click", "");
backend.triggerControlEvent(control.id, "click");
}
: null;

Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CupertinoListTileControl extends StatelessWidget {
openWebBrowser(url, webWindowName: urlTarget);
}
if (onclick) {
backend.triggerControlEvent(control.id, "click", "");
backend.triggerControlEvent(control.id, "click");
}
}
: null;
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _CupertinoRadioControlState extends State<CupertinoRadioControl>

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class _CupertinoSliderControlState extends State<CupertinoSliderControl> {
widget.backend.updateControlState(widget.control.id, props, server: false);
_debouncer.run(() {
widget.backend.updateControlState(widget.control.id, props);
widget.backend.triggerControlEvent(widget.control.id, "change", '');
widget.backend.triggerControlEvent(widget.control.id, "change");
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/cupertino_switch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _CupertinoSwitchControlState extends State<CupertinoSwitchControl> {

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down
4 changes: 3 additions & 1 deletion packages/flet/lib/src/controls/cupertino_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _CupertinoTextFieldControlState extends State<CupertinoTextFieldControl> {
if (!HardwareKeyboard.instance.isShiftPressed &&
evt.logicalKey.keyLabel == 'Enter') {
if (evt is KeyDownEvent) {
widget.backend.triggerControlEvent(widget.control.id, "submit", "");
widget.backend.triggerControlEvent(widget.control.id, "submit");
}
return KeyEventResult.handled;
} else {
Expand Down Expand Up @@ -283,6 +283,8 @@ class _CupertinoTextFieldControlState extends State<CupertinoTextFieldControl> {
cursorRadius: parseRadius(widget.control, "cursorRadius") ??
const Radius.circular(2.0),
keyboardType: keyboardType,
clearButtonSemanticLabel:
widget.control.attrString("clearButtonSemanticsLabel"),
autocorrect: autocorrect,
enableSuggestions: enableSuggestions,
smartDashesType: smartDashesType
Expand Down
11 changes: 5 additions & 6 deletions packages/flet/lib/src/controls/datatable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class _DataTableControlState extends State<DataTableControl>
: null,
onLongPress: row.control.attrBool("onLongPress", false)!
? () {
widget.backend.triggerControlEvent(
row.control.id, "long_press", "");
widget.backend.triggerControlEvent(row.control.id, "long_press");
}
: null,
cells: row.children
Expand All @@ -153,25 +152,25 @@ class _DataTableControlState extends State<DataTableControl>
onDoubleTap: cell.attrBool("onDoubleTap", false)!
? () {
widget.backend.triggerControlEvent(
cell.id, "double_tap", "");
cell.id, "double_tap");
}
: null,
onLongPress: cell.attrBool("onLongPress", false)!
? () {
widget.backend.triggerControlEvent(
cell.id, "long_press", "");
cell.id, "long_press");
}
: null,
onTap: cell.attrBool("onTap", false)!
? () {
widget.backend
.triggerControlEvent(cell.id, "tap", "");
.triggerControlEvent(cell.id, "tap");
}
: null,
onTapCancel: cell.attrBool("onTapCancel", false)!
? () {
widget.backend.triggerControlEvent(
cell.id, "tap_cancel", "");
cell.id, "tap_cancel");
}
: null,
onTapDown: cell.attrBool("onTapDown", false)!
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/dismissible.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _DismissibleControlState extends State<DismissibleControl> {
onResize: widget.control.attrBool("onResize", false)!
? () {
widget.backend
.triggerControlEvent(widget.control.id, "resize", "");
.triggerControlEvent(widget.control.id, "resize");
}
: null,
onUpdate: widget.control.attrBool("onUpdate", false)!
Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
_focused = _focusNode.hasFocus;
});
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down
7 changes: 3 additions & 4 deletions packages/flet/lib/src/controls/elevated_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class _ElevatedButtonControlState extends State<ElevatedButtonControl>

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down Expand Up @@ -102,16 +102,15 @@ class _ElevatedButtonControlState extends State<ElevatedButtonControl>
openWebBrowser(url,
webWindowName: widget.control.attrString("urlTarget"));
}
widget.backend
.triggerControlEvent(widget.control.id, "click", "");
widget.backend.triggerControlEvent(widget.control.id, "click");
}
: null;

Function()? onLongPressHandler = onLongPress && !disabled
? () {
debugPrint("Button ${widget.control.id} long pressed!");
widget.backend
.triggerControlEvent(widget.control.id, "long_press", "");
.triggerControlEvent(widget.control.id, "long_press");
}
: null;

Expand Down
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/floating_action_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FloatingActionButtonControl extends StatelessWidget {
if (url != "") {
openWebBrowser(url, webWindowName: urlTarget);
}
backend.triggerControlEvent(control.id, "click", "");
backend.triggerControlEvent(control.id, "click");
};

if (text == null && icon == null && contentCtrls.isEmpty) {
Expand Down
4 changes: 3 additions & 1 deletion packages/flet/lib/src/controls/icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class IconControl extends StatelessWidget {
debugPrint("Icon build: ${control.id}");

var name = control.attrString("name", "")!;
var size = control.attrDouble("size", null);
var size = control.attrDouble("size");
var semanticsLabel = control.attrString("semanticsLabel");
var color = HexColor.fromString(
Theme.of(context), control.attrString("color", "")!);

Expand All @@ -26,6 +27,7 @@ class IconControl extends StatelessWidget {
parseIcon(name),
size: size,
color: color,
semanticLabel: semanticsLabel,
),
parent,
control);
Expand Down
5 changes: 2 additions & 3 deletions packages/flet/lib/src/controls/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _IconButtonControlState extends State<IconButtonControl>

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down Expand Up @@ -101,8 +101,7 @@ class _IconButtonControlState extends State<IconButtonControl>
if (url != "") {
openWebBrowser(url, webWindowName: urlTarget);
}
widget.backend
.triggerControlEvent(widget.control.id, "click", "");
widget.backend.triggerControlEvent(widget.control.id, "click");
};

Widget? button;
Expand Down
4 changes: 2 additions & 2 deletions packages/flet/lib/src/controls/list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ class ListTileControl extends StatelessWidget with FletStoreMixin {
openWebBrowser(url, webWindowName: urlTarget);
}
if (onclick) {
backend.triggerControlEvent(control.id, "click", "");
backend.triggerControlEvent(control.id, "click");
}
}
: null;

Function()? onLongPress = onLongPressDefined && !disabled
? () {
debugPrint("Button ${control.id} clicked!");
backend.triggerControlEvent(control.id, "long_press", "");
backend.triggerControlEvent(control.id, "long_press");
}
: null;

Expand Down
5 changes: 2 additions & 3 deletions packages/flet/lib/src/controls/menu_item_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _MenuItemButtonControlState extends State<MenuItemButtonControl> {

void _onFocusChange() {
widget.backend.triggerControlEvent(
widget.control.id, _focusNode.hasFocus ? "focus" : "blur", "");
widget.control.id, _focusNode.hasFocus ? "focus" : "blur");
}

@override
Expand Down Expand Up @@ -98,8 +98,7 @@ class _MenuItemButtonControlState extends State<MenuItemButtonControl> {
: null,
onPressed: onClick && !disabled
? () {
widget.backend
.triggerControlEvent(widget.control.id, "click", "");
widget.backend.triggerControlEvent(widget.control.id, "click");
}
: null,
leadingIcon: leading.isNotEmpty
Expand Down
Loading