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

Add rtl prop to more controls #3641

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 19 additions & 34 deletions packages/flet/lib/src/controls/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,65 +49,50 @@ class AppBarControl extends StatelessWidget
var titleCtrls = children.where((c) => c.name == "title" && c.isVisible);
var actionCtrls =
children.where((c) => c.name == "action" && c.isVisible);

var leadingWidth = control.attrDouble("leadingWidth");
var elevation = control.attrDouble("elevation");
var toolbarOpacity = control.attrDouble("toolbarOpacity", 1)!;
var centerTitle = control.attrBool("centerTitle", false)!;
var automaticallyImplyLeading =
control.attrBool("automaticallyImplyLeading", true)!;
var color = control.attrColor("color", context);
var bgcolor = control.attrColor("bgcolor", context);
var shadowColor = control.attrColor("shadowColor", context);
var surfaceTintColor = control.attrColor("surfaceTintColor", context);
var elevationOnScroll = control.attrDouble("elevationOnScroll");
var forceMaterialTransparency =
control.attrBool("forceMaterialTransparency", false)!;
var isSecondary = control.attrBool("isSecondary", false)!;
var excludeHeaderSemantics =
control.attrBool("excludeHeaderSemantics", false)!;
var titleSpacing = control.attrDouble("titleSpacing");

var clipBehavior = parseClip(control.attrString("clipBehavior"));

return AppBar(
var appBar = AppBar(
leading: leadingCtrls.isNotEmpty
? createControl(control, leadingCtrls.first.id, control.isDisabled,
parentAdaptive: adaptive)
: null,
leadingWidth: leadingWidth,
automaticallyImplyLeading: automaticallyImplyLeading,
leadingWidth: control.attrDouble("leadingWidth"),
automaticallyImplyLeading:
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
control.attrBool("automaticallyImplyLeading", true)!,
title: titleCtrls.isNotEmpty
? createControl(control, titleCtrls.first.id, control.isDisabled,
parentAdaptive: adaptive)
: null,
centerTitle: centerTitle,
centerTitle: control.attrBool("centerTitle", false)!,
toolbarHeight: preferredSize.height,
foregroundColor: color,
backgroundColor: bgcolor,
elevation: elevation,
foregroundColor: control.attrColor("color", context),
backgroundColor: control.attrColor("bgcolor", context),
elevation: control.attrDouble("elevation"),
actions: actionCtrls
.map((c) => createControl(control, c.id, control.isDisabled,
parentAdaptive: adaptive))
.toList(),
systemOverlayStyle: Theme.of(context)
.extension<SystemUiOverlayStyleTheme>()
?.systemUiOverlayStyle,
shadowColor: shadowColor,
surfaceTintColor: surfaceTintColor,
scrolledUnderElevation: elevationOnScroll,
forceMaterialTransparency: forceMaterialTransparency,
shadowColor: control.attrColor("shadowColor", context),
surfaceTintColor: control.attrColor("surfaceTintColor", context),
scrolledUnderElevation: control.attrDouble("elevationOnScroll"),
forceMaterialTransparency:
control.attrBool("forceMaterialTransparency", false)!,
primary: !isSecondary,
titleSpacing: titleSpacing,
excludeHeaderSemantics: excludeHeaderSemantics,
clipBehavior: clipBehavior,
titleSpacing: control.attrDouble("titleSpacing"),
excludeHeaderSemantics:
control.attrBool("excludeHeaderSemantics", false)!,
clipBehavior: parseClip(control.attrString("clipBehavior")),
titleTextStyle:
parseTextStyle(Theme.of(context), control, "titleTextStyle"),
shape: parseOutlinedBorder(control, "shape"),
toolbarOpacity: toolbarOpacity,
toolbarOpacity: control.attrDouble("toolbarOpacity", 1)!,
toolbarTextStyle:
parseTextStyle(Theme.of(context), control, "toolbarTextStyle"),
);
return baseControl(context, appBar, parent, control);
});
}

Expand Down
22 changes: 9 additions & 13 deletions packages/flet/lib/src/controls/cupertino_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,21 @@ class CupertinoAppBarControl extends StatelessWidget
var trailingCtrls = children.where(
(c) => (c.name == "trailing" || c.name == "action") && c.isVisible);

var automaticallyImplyLeading =
control.attrBool("automaticallyImplyLeading", true)!;
var automaticallyImplyMiddle =
control.attrBool("automaticallyImplyMiddle", true)!;
var transitionBetweenRoutes =
control.attrBool("transitionBetweenRoutes", true)!;
var bgcolor = control.attrColor("bgcolor", context);

return CupertinoNavigationBar(
var bar = CupertinoNavigationBar(
leading: leadingCtrls.isNotEmpty
? createControl(control, leadingCtrls.first.id, control.isDisabled,
parentAdaptive: parentAdaptive)
: null,
automaticallyImplyLeading: automaticallyImplyLeading,
automaticallyImplyMiddle: automaticallyImplyMiddle,
transitionBetweenRoutes: transitionBetweenRoutes,
automaticallyImplyLeading:
control.attrBool("automaticallyImplyLeading", true)!,
automaticallyImplyMiddle:
control.attrBool("automaticallyImplyMiddle", true)!,
transitionBetweenRoutes:
control.attrBool("transitionBetweenRoutes", true)!,
border: parseBorder(Theme.of(context), control, "border"),
previousPageTitle: control.attrString("previousPageTitle"),
padding: parseEdgeInsetsDirectional(control, "padding"),
backgroundColor: control.attrColor("bgcolor", context),
middle: middleCtrls.isNotEmpty
? createControl(control, middleCtrls.first.id, control.isDisabled,
parentAdaptive: parentAdaptive)
Expand All @@ -73,8 +69,8 @@ class CupertinoAppBarControl extends StatelessWidget
.toList(),
)
: null,
backgroundColor: bgcolor,
);
return baseControl(context, bar, parent, control);
}

@override
Expand Down
8 changes: 3 additions & 5 deletions packages/flet/lib/src/controls/cupertino_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class _CupertinoBottomSheetControlState
: const SizedBox.shrink();

if (contentCtrls.isNotEmpty &&
(contentCtrls.first.type == "cupertinopicker" ||
contentCtrls.first.type == "cupertinotimerpicker" ||
contentCtrls.first.type == "cupertinodatepicker")) {
["cupertinopicker", "cupertinotimerpicker", "cupertinodatepicker"]
.contains(contentCtrls.first.type)) {
content = Container(
height: height,
padding: padding,
Expand Down Expand Up @@ -112,8 +111,7 @@ class _CupertinoBottomSheetControlState
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
11 changes: 6 additions & 5 deletions packages/flet/lib/src/controls/navigation_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl>
_selectedIndex = selectedIndex;
}

var navDrawer = withControls(
return withControls(
widget.children
.where((c) => c.isVisible && c.name == null)
.map((c) => c.id), (content, viewModel) {
List<Widget> children = viewModel.controlViews.map((destView) {
if (destView.control.type == "navigationdrawerdestination") {
var icon = parseIcon(destView.control.attrString("icon"));
var iconContentCtrls = destView.children
.where((c) => c.name == "icon_content" && c.isVisible);
var selectedIcon =
Expand All @@ -73,7 +72,7 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl>
? createControl(
destView.control, iconContentCtrls.first.id, disabled,
parentAdaptive: widget.parentAdaptive)
: Icon(icon),
: Icon(parseIcon(destView.control.attrString("icon"))),
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
label: Text(destView.control.attrString("label", "")!),
selectedIcon: selectedIconContentCtrls.isNotEmpty
? createControl(destView.control,
Expand All @@ -88,7 +87,8 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl>
parentAdaptive: widget.parentAdaptive);
}
}).toList();
return NavigationDrawer(

var drawer = NavigationDrawer(
elevation: widget.control.attrDouble("elevation"),
indicatorColor: widget.control.attrColor("indicatorColor", context),
indicatorShape: parseOutlinedBorder(widget.control, "indicatorShape"),
Expand All @@ -101,8 +101,9 @@ class _NavigationDrawerControlState extends State<NavigationDrawerControl>
onDestinationSelected: _destinationChanged,
children: children,
);

return baseControl(context, drawer, widget.parent, widget.control);
});

return navDrawer;
}
}
6 changes: 3 additions & 3 deletions packages/flet/lib/src/controls/navigation_rail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _NavigationRailControlState extends State<NavigationRailControl>

void _destinationChanged(int index) {
_selectedIndex = index;
debugPrint("Selected index: $_selectedIndex");
debugPrint("NavigationRail selectedIndex: $_selectedIndex");
widget.backend.updateControlState(
widget.control.id, {"selectedindex": _selectedIndex.toString()});
widget.backend.triggerControlEvent(
Expand Down Expand Up @@ -81,7 +81,7 @@ class _NavigationRailControlState extends State<NavigationRailControl>
"NavigationRail constraints.maxHeight: ${constraints.maxHeight}");

if (constraints.maxHeight == double.infinity &&
widget.control.attrs["height"] == null) {
widget.control.attrDouble("height") == null) {
FeodorFitsner marked this conversation as resolved.
Show resolved Hide resolved
return const ErrorControl("Error displaying NavigationRail",
description:
"Control's height is unbounded. Either set \"expand\" property, set a fixed \"height\" or nest NavigationRail inside another control with a fixed height.");
Expand All @@ -90,7 +90,7 @@ class _NavigationRailControlState extends State<NavigationRailControl>
return NavigationRail(
labelType: extended ? NavigationRailLabelType.none : labelType,
extended: extended,
elevation: widget.control.attrDouble("elevation", 0),
elevation: widget.control.attrDouble("elevation"),
selectedLabelTextStyle: parseTextStyle(
Theme.of(context), widget.control, "selectedLabelTextStyle"),
unselectedLabelTextStyle: parseTextStyle(Theme.of(context),
Expand Down
5 changes: 4 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/app_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ def __init__(
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
rtl: Optional[bool] = None,
adaptive: Optional[bool] = None,
):
Control.__init__(self, ref=ref, visible=visible, disabled=disabled, data=data)
Control.__init__(
self, ref=ref, visible=visible, disabled=disabled, data=data, rtl=rtl
)

AdaptiveControl.__init__(self, adaptive=adaptive)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ def __init__(
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
rtl: Optional[bool] = None,
):
Control.__init__(self, ref=ref, visible=visible, disabled=disabled, data=data)
Control.__init__(
self, ref=ref, visible=visible, disabled=disabled, data=data, rtl=rtl
)

self.leading = leading
self.middle = middle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ def __init__(
disabled: Optional[bool] = None,
visible: Optional[bool] = None,
data: Any = None,
rtl: Optional[bool] = None,
):
Control.__init__(
self,
ref=ref,
visible=visible,
disabled=disabled,
data=data,
rtl=rtl,
)

self.open = open
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def __init__(
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
rtl: Optional[bool] = False,
):
ConstrainedControl.__init__(
self,
Expand Down Expand Up @@ -291,6 +292,7 @@ def __init__(
visible=visible,
disabled=disabled,
data=data,
rtl=rtl,
)

self.destinations = destinations
Expand Down Expand Up @@ -409,7 +411,7 @@ def elevation(self) -> OptionalNumber:

@elevation.setter
def elevation(self, value: OptionalNumber):
assert value is None or value >= 0, "elevation cannot be negative"
assert value is None or value > 0, "elevation must be greater than 0"
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
self._set_attr("elevation", value)

# extended
Expand Down
2 changes: 0 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,9 @@ async def __on_authorize_async(self, e) -> None:
if not self.web:
if self.platform in ["ios", "android"]:
# close web view on mobile

self.close_in_app_web_view()
else:
# activate desktop window

self.window_to_front()
login_evt = LoginEvent(
error=d.get("error"),
Expand Down
3 changes: 1 addition & 2 deletions sdk/python/packages/flet-core/tests/test_navigation_rail.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import flet_core as ft
import pytest
from flet_core.protocol import Command


Expand All @@ -11,7 +10,7 @@ def test_instance_no_attrs_set():
indent=0,
name=None,
values=["navigationrail"],
attrs={},
attrs={"rtl": "false"},
commands=[],
)
], "Test failed"
Expand Down