From fdc31d121acc6aa56831d8d3e4742f509d4fe7e9 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Mon, 6 Nov 2023 12:37:17 -0800 Subject: [PATCH 01/21] Create navigation_drawer.py --- .../src/flet_core/navigation_drawer.py | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py new file mode 100644 index 000000000..03ae1efc2 --- /dev/null +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -0,0 +1,288 @@ +from enum import Enum +from typing import Any, List, Optional, Union + +from flet_core.constrained_control import ConstrainedControl +from flet_core.control import Control, OptionalNumber +from flet_core.ref import Ref +from flet_core.types import ( + AnimationValue, + OffsetValue, + ResponsiveNumber, + RotateValue, + ScaleValue, +) + +# try: +# from typing import Literal +# except ImportError: +# from typing_extensions import Literal + +# NavigationBarLabelBehaviorString = Literal[ +# None, "alwaysShow", "alwaysHide", "onlyShowSelected" +# ] + + +# class NavigationBarLabelBehavior(Enum): +# """Defines how the destinations' labels will be laid out and when they'll be displayed.""" + +# ALWAYS_SHOW = "alwaysShow" +# ALWAYS_HIDE = "alwaysHide" +# ONLY_SHOW_SELECTED = "onlyShowSelected" + + +class NavigationDrawerDestination(Control): + """ + Displays an icon with a label, for use in NavigationDrawer destinations. + """ + + def __init__( + self, + ref: Optional[Ref] = None, + bgcolor: Optional[str] = None, + icon: Optional[str] = None, + icon_content: Optional[Control] = None, + label: Optional[str] = None, + selected_icon: Optional[str] = None, + selected_icon_content: Optional[Control] = None, + ): + Control.__init__(self, ref=ref) + self.label = label + self.bgcolor = bgcolor + self.icon = icon + self.__icon_content: Optional[Control] = None + self.icon_content = icon_content + self.selected_icon = selected_icon + self.__selected_icon_content: Optional[Control] = None + self.selected_icon_content = selected_icon_content + + def _get_control_name(self): + return "navigationdrawerdestination" + + def _get_children(self): + children = [] + if self.__icon_content: + self.__icon_content._set_attr_internal("n", "icon_content") + children.append(self.__icon_content) + if self.__selected_icon_content: + self.__selected_icon_content._set_attr_internal( + "n", "selected_icon_content" + ) + children.append(self.__selected_icon_content) + return children + + # bgcolor + @property + def bgcolor(self): + return self._get_attr("bgColor") + + @bgcolor.setter + def bgcolor(self, value): + self._set_attr("bgColor", value) + + # icon + @property + def icon(self): + return self._get_attr("icon") + + @icon.setter + def icon(self, value): + self._set_attr("icon", value) + + # icon_content + @property + def icon_content(self) -> Optional[Control]: + return self.__icon_content + + @icon_content.setter + def icon_content(self, value: Optional[Control]): + self.__icon_content = value + + # selected_icon + @property + def selected_icon(self): + return self._get_attr("selectedIcon") + + @selected_icon.setter + def selected_icon(self, value): + self._set_attr("selectedIcon", value) + + # selected_icon_content + @property + def selected_icon_content(self) -> Optional[Control]: + return self.__selected_icon_content + + @selected_icon_content.setter + def selected_icon_content(self, value: Optional[Control]): + self.__selected_icon_content = value + + # label + @property + def label(self): + return self._get_attr("label") + + @label.setter + def label(self, value): + self._set_attr("label", value) + + +class NavigationDrawer(Control): + """ + Material Design Navigation Drawer component. + + Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. + + Example: + + ``` + + ``` + + ----- + + Online docs: https://flet.dev/docs/controls/navigationdrawer + """ + + def __init__( + self, + ref: Optional[Ref] = None, + disabled: Optional[bool] = None, + visible: Optional[bool] = None, + data: Any = None, + # ref: Optional[Ref] = None, + # width: OptionalNumber = None, + # height: OptionalNumber = None, + # left: OptionalNumber = None, + # top: OptionalNumber = None, + # right: OptionalNumber = None, + # bottom: OptionalNumber = None, + # expand: Union[None, bool, int] = None, + # col: Optional[ResponsiveNumber] = None, + # opacity: OptionalNumber = None, + # rotate: RotateValue = None, + # scale: ScaleValue = None, + # offset: OffsetValue = None, + # aspect_ratio: OptionalNumber = None, + # animate_opacity: AnimationValue = None, + # animate_size: AnimationValue = None, + # animate_position: AnimationValue = None, + # animate_rotation: AnimationValue = None, + # animate_scale: AnimationValue = None, + # animate_offset: AnimationValue = None, + # on_animation_end=None, + # visible: Optional[bool] = None, + # disabled: Optional[bool] = None, + # data: Any = None, + # + # NavigationDrawer-specific + open: bool = False, + destinations: Optional[List[NavigationDrawerDestination]] = None, + selected_index: Optional[int] = None, + bgcolor: Optional[str] = None, + # label_behavior: Optional[NavigationBarLabelBehavior] = None, + elevation: OptionalNumber = None, + on_change=None, + ): + Control.__init__( + self, + ref=ref, + # width=width, + # height=height, + # left=left, + # top=top, + # right=right, + # bottom=bottom, + # expand=expand, + # col=col, + # opacity=opacity, + # rotate=rotate, + # scale=scale, + # offset=offset, + # aspect_ratio=aspect_ratio, + # animate_opacity=animate_opacity, + # animate_size=animate_size, + # animate_position=animate_position, + # animate_rotation=animate_rotation, + # animate_scale=animate_scale, + # animate_offset=animate_offset, + # on_animation_end=on_animation_end, + visible=visible, + disabled=disabled, + data=data, + ) + + self.open = open + self.destinations = destinations + self.selected_index = selected_index + # self.label_behavior = label_behavior + self.bgcolor = bgcolor + self.elevation = elevation + self.on_change = on_change + + def _get_control_name(self): + return "navigationdrawer" + + def _get_children(self): + children = [] + children.extend(self.__destinations) + return children + + # open + @property + def open(self) -> Optional[bool]: + return self._get_attr("open", data_type="bool", def_value=False) + + @open.setter + def open(self, value: Optional[bool]): + self._set_attr("open", value) + + # destinations + @property + def destinations(self) -> Optional[List[NavigationDrawerDestination]]: + return self.__destinations + + @destinations.setter + def destinations(self, value: Optional[List[NavigationDrawerDestination]]): + self.__destinations = value if value is not None else [] + + # on_change + @property + def on_change(self): + return self._get_event_handler("change") + + @on_change.setter + def on_change(self, handler): + self._add_event_handler("change", handler) + + # selected_index + @property + def selected_index(self) -> Optional[int]: + return self._get_attr("selectedIndex", data_type="int", def_value=0) + + @selected_index.setter + def selected_index(self, value: Optional[int]): + self._set_attr("selectedIndex", value) + + # # label_behavior + # @property + # def label_behavior(self) -> Optional[NavigationBarLabelBehavior]: + # return self.__label_behavior + + # @label_behavior.setter + # def label_behavior(self, value: Optional[NavigationBarLabelBehavior]): + # self.__label_behavior = value + # if isinstance(value, NavigationBarLabelBehavior): + # self._set_attr("labelType", value.value) + # else: + # self.__set_label_behavior(value) + + # def __set_label_behavior(self, value: NavigationBarLabelBehaviorString): + # self._set_attr("labelType", value) + + # bgcolor + @property + def bgcolor(self): + return self._get_attr("bgcolor") + + @bgcolor.setter + def bgcolor(self, value): + self._set_attr("bgcolor", value) From 156a6deba7f63a60d328cd6834fa698a8e8425b3 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Mon, 6 Nov 2023 12:51:05 -0800 Subject: [PATCH 02/21] added end_drawer to view and page --- .../packages/flet-core/src/flet_core/__init__.py | 1 + .../packages/flet-core/src/flet_core/page.py | 10 ++++++++++ .../packages/flet-core/src/flet_core/view.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/sdk/python/packages/flet-core/src/flet_core/__init__.py b/sdk/python/packages/flet-core/src/flet_core/__init__.py index 1fd981e8d..4168e075b 100644 --- a/sdk/python/packages/flet-core/src/flet_core/__init__.py +++ b/sdk/python/packages/flet-core/src/flet_core/__init__.py @@ -206,3 +206,4 @@ from flet_core.window_drag_area import WindowDragArea from flet_core.range_slider import RangeSlider from flet_core.badge import Badge +from flet_core.navigation_drawer import NavigationDrawer, NavigationDrawerDestination diff --git a/sdk/python/packages/flet-core/src/flet_core/page.py b/sdk/python/packages/flet-core/src/flet_core/page.py index 66d779688..826d558c4 100644 --- a/sdk/python/packages/flet-core/src/flet_core/page.py +++ b/sdk/python/packages/flet-core/src/flet_core/page.py @@ -25,6 +25,7 @@ from flet_core.floating_action_button import FloatingActionButton from flet_core.locks import AsyncNopeLock, NopeLock from flet_core.navigation_bar import NavigationBar +from flet_core.navigation_drawer import NavigationDrawer from flet_core.protocol import Command from flet_core.querystring import QueryString from flet_core.session_storage import SessionStorage @@ -1241,6 +1242,15 @@ def navigation_bar(self) -> Optional[NavigationBar]: def navigation_bar(self, value: Optional[NavigationBar]): self.__default_view.navigation_bar = value + # end_drawer + @property + def end_drawer(self) -> Optional[NavigationDrawer]: + return self.__default_view.end_drawer + + @end_drawer.setter + def end_drawer(self, value: Optional[NavigationDrawer]): + self.__default_view.end_drawer = value + # floating_action_button @property def floating_action_button(self) -> Optional[FloatingActionButton]: diff --git a/sdk/python/packages/flet-core/src/flet_core/view.py b/sdk/python/packages/flet-core/src/flet_core/view.py index 62bc6c3be..3624917e3 100644 --- a/sdk/python/packages/flet-core/src/flet_core/view.py +++ b/sdk/python/packages/flet-core/src/flet_core/view.py @@ -5,6 +5,7 @@ from flet_core.control import OptionalNumber from flet_core.floating_action_button import FloatingActionButton from flet_core.navigation_bar import NavigationBar +from flet_core.navigation_drawer import NavigationDrawer from flet_core.scrollable_control import ScrollableControl from flet_core.types import ( CrossAxisAlignment, @@ -35,6 +36,7 @@ def __init__( appbar: Optional[AppBar] = None, floating_action_button: Optional[FloatingActionButton] = None, navigation_bar: Optional[NavigationBar] = None, + end_drawer: Optional[NavigationDrawer] = None, vertical_alignment: MainAxisAlignment = MainAxisAlignment.NONE, horizontal_alignment: CrossAxisAlignment = CrossAxisAlignment.NONE, spacing: OptionalNumber = None, @@ -63,6 +65,7 @@ def __init__( self.route = route self.appbar = appbar self.navigation_bar = navigation_bar + self.end_drawer = end_drawer self.floating_action_button = floating_action_button self.vertical_alignment = vertical_alignment self.horizontal_alignment = horizontal_alignment @@ -88,6 +91,8 @@ def _get_children(self): children.append(self.__fab) if self.__navigation_bar: children.append(self.__navigation_bar) + if self.__end_drawer: + children.append(self.__end_drawer) children.extend(self.__controls) return children @@ -136,6 +141,15 @@ def navigation_bar(self) -> Optional[NavigationBar]: def navigation_bar(self, value: Optional[NavigationBar]): self.__navigation_bar = value + # end_drawer + @property + def end_drawer(self) -> Optional[NavigationDrawer]: + return self.__end_drawer + + @end_drawer.setter + def end_drawer(self, value: Optional[NavigationDrawer]): + self.__end_drawer = value + # horizontal_alignment @property def horizontal_alignment(self) -> CrossAxisAlignment: From e095f95909387889a25d2dd0317c66a4fc31ff80 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Tue, 7 Nov 2023 08:47:50 -0800 Subject: [PATCH 03/21] navigation_drawer.dart --- package/lib/src/controls/create_control.dart | 9 ++ .../lib/src/controls/navigation_drawer.dart | 124 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 package/lib/src/controls/navigation_drawer.dart diff --git a/package/lib/src/controls/create_control.dart b/package/lib/src/controls/create_control.dart index 084070edf..f29ab61e9 100644 --- a/package/lib/src/controls/create_control.dart +++ b/package/lib/src/controls/create_control.dart @@ -77,6 +77,7 @@ import 'vertical_divider.dart'; import 'window_drag_area.dart'; import 'range_slider.dart'; import 'badge.dart'; +import 'navigation_drawer.dart'; Widget createControl(Control? parent, String id, bool parentDisabled, {Widget? nextChild}) { @@ -498,6 +499,14 @@ Widget createWidget(Key? key, ControlViewModel controlView, Control? parent, children: controlView.children, parentDisabled: parentDisabled, nextChild: nextChild); + case "navigationdrawer": + return NavigationDrawerControl( + parent: parent, + control: controlView.control, + children: controlView.children, + parentDisabled: parentDisabled, + nextChild: nextChild, + dispatch: controlView.dispatch); case "bottomsheet": return BottomSheetControl( parent: parent, diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart new file mode 100644 index 000000000..7f4c9d155 --- /dev/null +++ b/package/lib/src/controls/navigation_drawer.dart @@ -0,0 +1,124 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_redux/flutter_redux.dart'; + +import '../actions.dart'; +import '../flet_app_services.dart'; +import '../models/app_state.dart'; +import '../models/control.dart'; +import '../models/controls_view_model.dart'; +import '../protocol/update_control_props_payload.dart'; +import '../utils/colors.dart'; +import '../utils/icons.dart'; +import 'create_control.dart'; + +class NavigationDrawerControl extends StatefulWidget { + final Control? parent; + final Control control; + final List children; + final bool parentDisabled; + final dynamic dispatch; + final Widget? nextChild; + + const NavigationDrawerControl( + {Key? key, + this.parent, + required this.control, + required this.children, + required this.parentDisabled, + required this.dispatch, + required this.nextChild}) + : super(key: key); + + @override + State createState() => + _NavigationDrawerControlState(); +} + +class _NavigationDrawerControlState extends State { + int _selectedIndex = 0; + + void _destinationChanged(int index) { + _selectedIndex = index; + debugPrint("Selected index: $_selectedIndex"); + List> props = [ + {"i": widget.control.id, "selectedindex": _selectedIndex.toString()} + ]; + widget.dispatch( + UpdateControlPropsAction(UpdateControlPropsPayload(props: props))); + final server = FletAppServices.of(context).server; + server.updateControlProps(props: props); + server.sendPageEvent( + eventTarget: widget.control.id, + eventName: "change", + eventData: _selectedIndex.toString()); + } + + @override + Widget build(BuildContext context) { + debugPrint("NavigationDrawerControl build: ${widget.control.id}"); + + bool disabled = widget.control.isDisabled || widget.parentDisabled; + var selectedIndex = widget.control.attrInt("selectedIndex", 0)!; + + if (_selectedIndex != selectedIndex) { + _selectedIndex = selectedIndex; + } + + // NavigationDestinationLabelBehavior? labelBehavior = + // NavigationDestinationLabelBehavior.values.firstWhereOrNull((a) => + // a.name.toLowerCase() == + // widget.control.attrString("labelBehavior", "")!.toLowerCase()); + + var navDrawer = StoreConnector( + distinct: true, + converter: (store) => ControlsViewModel.fromStore( + store, + widget.children + .where((c) => c.isVisible && c.name == null) + .map((c) => c.id)), + builder: (content, viewModel) { + return NavigationDrawer( + //labelBehavior: labelBehavior, + //height: widget.control.attrDouble("height"), + + elevation: widget.control.attrDouble("elevation"), + backgroundColor: HexColor.fromString( + Theme.of(context), widget.control.attrString("bgColor", "")!), + selectedIndex: _selectedIndex, + onDestinationSelected: _destinationChanged, + children: const [Icon(Icons.add)], + // destinations: viewModel.controlViews.map((destView) { + // var label = destView.control.attrString("label", "")!; + + // var icon = + // getMaterialIcon(destView.control.attrString("icon", "")!); + // var iconContentCtrls = + // destView.children.where((c) => c.name == "icon_content"); + + // var selectedIcon = getMaterialIcon( + // destView.control.attrString("selectedIcon", "")!); + // var selectedIconContentCtrls = destView.children + // .where((c) => c.name == "selected_icon_content"); + + // return NavigationDestination( + // icon: iconContentCtrls.isNotEmpty + // ? createControl(destView.control, + // iconContentCtrls.first.id, disabled) + // : Icon(icon), + // selectedIcon: selectedIconContentCtrls.isNotEmpty + // ? createControl(destView.control, + // selectedIconContentCtrls.first.id, disabled) + // : selectedIcon != null + // ? Icon(selectedIcon) + // : null, + // label: label); + //}).toList()); + ); + }); + + // return constrainedControl( + // context, navDrawer, widget.parent, widget.control); + return widget.nextChild ?? const SizedBox.shrink(); + } +} From 41d2368c76aead64f74528d3e972dd07cccef9d6 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Tue, 7 Nov 2023 14:05:22 -0800 Subject: [PATCH 04/21] NavigationDrawer prototype --- package/lib/src/controls/create_control.dart | 13 +- .../lib/src/controls/navigation_drawer.dart | 9 +- package/lib/src/controls/page.dart | 127 ++++++++++++++++-- .../src/flet_core/navigation_drawer.py | 37 +++++ .../packages/flet-core/src/flet_core/page.py | 9 ++ .../packages/flet-core/src/flet_core/view.py | 15 +++ 6 files changed, 184 insertions(+), 26 deletions(-) diff --git a/package/lib/src/controls/create_control.dart b/package/lib/src/controls/create_control.dart index f29ab61e9..2259166d2 100644 --- a/package/lib/src/controls/create_control.dart +++ b/package/lib/src/controls/create_control.dart @@ -15,6 +15,7 @@ import '../utils/transforms.dart'; import 'alert_dialog.dart'; import 'animated_switcher.dart'; import 'audio.dart'; +import 'badge.dart'; import 'banner.dart'; import 'barchart.dart'; import 'bottom_sheet.dart'; @@ -57,6 +58,7 @@ import 'progress_bar.dart'; import 'progress_ring.dart'; import 'radio.dart'; import 'radio_group.dart'; +import 'range_slider.dart'; import 'responsive_row.dart'; import 'row.dart'; import 'safe_area.dart'; @@ -75,9 +77,6 @@ import 'tooltip.dart'; import 'transparent_pointer.dart'; import 'vertical_divider.dart'; import 'window_drag_area.dart'; -import 'range_slider.dart'; -import 'badge.dart'; -import 'navigation_drawer.dart'; Widget createControl(Control? parent, String id, bool parentDisabled, {Widget? nextChild}) { @@ -499,14 +498,6 @@ Widget createWidget(Key? key, ControlViewModel controlView, Control? parent, children: controlView.children, parentDisabled: parentDisabled, nextChild: nextChild); - case "navigationdrawer": - return NavigationDrawerControl( - parent: parent, - control: controlView.control, - children: controlView.children, - parentDisabled: parentDisabled, - nextChild: nextChild, - dispatch: controlView.dispatch); case "bottomsheet": return BottomSheetControl( parent: parent, diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 7f4c9d155..1c8eb2e03 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -1,4 +1,3 @@ -import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; @@ -9,8 +8,6 @@ import '../models/control.dart'; import '../models/controls_view_model.dart'; import '../protocol/update_control_props_payload.dart'; import '../utils/colors.dart'; -import '../utils/icons.dart'; -import 'create_control.dart'; class NavigationDrawerControl extends StatefulWidget { final Control? parent; @@ -18,7 +15,6 @@ class NavigationDrawerControl extends StatefulWidget { final List children; final bool parentDisabled; final dynamic dispatch; - final Widget? nextChild; const NavigationDrawerControl( {Key? key, @@ -26,8 +22,7 @@ class NavigationDrawerControl extends StatefulWidget { required this.control, required this.children, required this.parentDisabled, - required this.dispatch, - required this.nextChild}) + required this.dispatch}) : super(key: key); @override @@ -119,6 +114,6 @@ class _NavigationDrawerControlState extends State { // return constrainedControl( // context, navDrawer, widget.parent, widget.control); - return widget.nextChild ?? const SizedBox.shrink(); + return navDrawer; } } diff --git a/package/lib/src/controls/page.dart b/package/lib/src/controls/page.dart index 959b63b40..97f9d3c0e 100644 --- a/package/lib/src/controls/page.dart +++ b/package/lib/src/controls/page.dart @@ -17,6 +17,7 @@ import '../models/page_args_model.dart'; import '../models/page_media_view_model.dart'; import '../models/routes_view_model.dart'; import '../protocol/keyboard_event.dart'; +import '../protocol/update_control_props_payload.dart'; import '../routing/route_parser.dart'; import '../routing/route_state.dart'; import '../routing/router_delegate.dart'; @@ -34,6 +35,7 @@ import '../widgets/page_media.dart'; import '../widgets/window_media.dart'; import 'app_bar.dart'; import 'create_control.dart'; +import 'navigation_drawer.dart'; import 'scroll_notification_control.dart'; import 'scrollable_control.dart'; @@ -90,6 +92,8 @@ class _PageControlState extends State { late final RouteParser _routeParser; String? _prevViewRoutes; bool _keyboardHandlerSubscribed = false; + bool? _drawerOpened; + bool? _endDrawerOpened; @override void initState() { @@ -593,6 +597,8 @@ class _PageControlState extends State { Control? appBar; Control? fab; Control? navBar; + Control? drawer; + Control? endDrawer; List controls = []; bool firstControl = true; @@ -606,6 +612,13 @@ class _PageControlState extends State { } else if (ctrl.type == "navigationbar") { navBar = ctrl; continue; + } else if (ctrl.type == "navigationdrawer" && + ctrl.name == "start") { + drawer = ctrl; + continue; + } else if (ctrl.type == "navigationdrawer" && ctrl.name == "end") { + endDrawer = ctrl; + continue; } // spacer between displayed controls else if (spacing > 0 && @@ -621,10 +634,8 @@ class _PageControlState extends State { controls.add(createControl(control, ctrl.id, control.isDisabled)); } - List childIds = []; - if (appBar != null) { - childIds.add(appBar.id); - } + List childIds = + [appBar?.id, drawer?.id, endDrawer?.id].whereNotNull().toList(); final textDirection = parent.attrBool("rtl", false)! ? TextDirection.rtl @@ -646,10 +657,12 @@ class _PageControlState extends State { builder: (context, childrenViews) { debugPrint("Route view StoreConnector build: $viewId"); - var appBarView = - appBar != null && childrenViews.controlViews.isNotEmpty - ? childrenViews.controlViews.last - : null; + var appBarView = childrenViews.controlViews.firstWhereOrNull( + (v) => v.control.id == (appBar?.id ?? "")); + var drawerView = childrenViews.controlViews.firstWhereOrNull( + (v) => v.control.id == (drawer?.id ?? "")); + var endDrawerView = childrenViews.controlViews.firstWhereOrNull( + (v) => v.control.id == (endDrawer?.id ?? "")); var column = Column( mainAxisAlignment: mainAlignment, @@ -668,7 +681,55 @@ class _PageControlState extends State { ScrollNotificationControl(control: control, child: child); } + GlobalKey? scaffoldKey = + FletAppServices.of(context).globalKeys["_scaffold"] + as GlobalKey?; + if (scaffoldKey == null) { + scaffoldKey = GlobalKey(); + FletAppServices.of(context).globalKeys["_scaffold"] = + scaffoldKey; + } + + WidgetsBinding.instance.addPostFrameCallback((_) { + if (drawerView != null) { + if (drawerView.control.attrBool("open", false)! && + _drawerOpened != true) { + if (scaffoldKey?.currentState?.isEndDrawerOpen == true) { + scaffoldKey?.currentState?.closeEndDrawer(); + } + Future.delayed(const Duration(milliseconds: 1)) + .then((value) { + scaffoldKey?.currentState?.openDrawer(); + _drawerOpened = true; + }); + } else if (!drawerView.control.attrBool("open", false)! && + _drawerOpened == true) { + scaffoldKey?.currentState?.closeDrawer(); + _drawerOpened = false; + } + } + if (endDrawerView != null) { + if (endDrawerView.control.attrBool("open", false)! && + _endDrawerOpened != true) { + if (scaffoldKey?.currentState?.isDrawerOpen == true) { + scaffoldKey?.currentState?.closeDrawer(); + } + Future.delayed(const Duration(milliseconds: 1)) + .then((value) { + scaffoldKey?.currentState?.openEndDrawer(); + _endDrawerOpened = true; + }); + } else if (!endDrawerView.control + .attrBool("open", false)! && + _endDrawerOpened == true) { + scaffoldKey?.currentState?.closeEndDrawer(); + _endDrawerOpened = false; + } + } + }); + var scaffold = Scaffold( + key: scaffoldKey, backgroundColor: HexColor.fromString( Theme.of(context), control.attrString("bgcolor", "")!), appBar: appBarView != null @@ -680,6 +741,56 @@ class _PageControlState extends State { height: appBarView.control .attrDouble("toolbarHeight", kToolbarHeight)!) : null, + drawer: drawerView != null + ? NavigationDrawerControl( + control: drawerView.control, + children: drawerView.children, + parentDisabled: control.isDisabled, + dispatch: widget.dispatch, + ) + : null, + onDrawerChanged: (opened) { + if (drawerView != null && !opened) { + _drawerOpened = false; + List> props = [ + {"i": drawerView.control.id, "open": "false"} + ]; + widget.dispatch(UpdateControlPropsAction( + UpdateControlPropsPayload(props: props))); + FletAppServices.of(context) + .server + .updateControlProps(props: props); + FletAppServices.of(context).server.sendPageEvent( + eventTarget: drawerView.control.id, + eventName: "dismiss", + eventData: ""); + } + }, + endDrawer: endDrawerView != null + ? NavigationDrawerControl( + control: endDrawerView.control, + children: endDrawerView.children, + parentDisabled: control.isDisabled, + dispatch: widget.dispatch, + ) + : null, + onEndDrawerChanged: (opened) { + if (endDrawerView != null && !opened) { + _endDrawerOpened = false; + List> props = [ + {"i": endDrawerView.control.id, "open": "false"} + ]; + widget.dispatch(UpdateControlPropsAction( + UpdateControlPropsPayload(props: props))); + FletAppServices.of(context) + .server + .updateControlProps(props: props); + FletAppServices.of(context).server.sendPageEvent( + eventTarget: endDrawerView.control.id, + eventName: "dismiss", + eventData: ""); + } + }, body: Stack(children: [ SizedBox.expand( child: Container( diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 03ae1efc2..0dc9a5beb 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -33,6 +33,43 @@ class NavigationDrawerDestination(Control): """ Displays an icon with a label, for use in NavigationDrawer destinations. + + import time + + import flet as ft + + + def main(page: ft.Page): + page.drawer = ft.NavigationDrawer( + destinations=[ft.NavigationDrawerDestination(icon=ft.icons.ABC, label="Item 1")] + ) + page.end_drawer = ft.NavigationDrawer( + destinations=[ + ft.NavigationDrawerDestination(icon=ft.icons.ABC, label="End drawer") + ] + ) + + def show_drawer(e): + page.drawer.open = True + page.drawer.update() + time.sleep(2) + page.drawer.open = False + page.drawer.update() + + def show_end_drawer(e): + page.end_drawer.open = True + page.end_drawer.update() + time.sleep(3) + page.drawer.open = True + page.drawer.update() + + page.add( + ft.ElevatedButton("Show drawer", on_click=show_drawer), + ft.ElevatedButton("Show end drawer", on_click=show_end_drawer), + ) + + + ft.app(main) """ def __init__( diff --git a/sdk/python/packages/flet-core/src/flet_core/page.py b/sdk/python/packages/flet-core/src/flet_core/page.py index 826d558c4..d398ff38f 100644 --- a/sdk/python/packages/flet-core/src/flet_core/page.py +++ b/sdk/python/packages/flet-core/src/flet_core/page.py @@ -1242,6 +1242,15 @@ def navigation_bar(self) -> Optional[NavigationBar]: def navigation_bar(self, value: Optional[NavigationBar]): self.__default_view.navigation_bar = value + # drawer + @property + def drawer(self) -> Optional[NavigationDrawer]: + return self.__default_view.drawer + + @drawer.setter + def drawer(self, value: Optional[NavigationDrawer]): + self.__default_view.drawer = value + # end_drawer @property def end_drawer(self) -> Optional[NavigationDrawer]: diff --git a/sdk/python/packages/flet-core/src/flet_core/view.py b/sdk/python/packages/flet-core/src/flet_core/view.py index 3624917e3..91c069763 100644 --- a/sdk/python/packages/flet-core/src/flet_core/view.py +++ b/sdk/python/packages/flet-core/src/flet_core/view.py @@ -36,6 +36,7 @@ def __init__( appbar: Optional[AppBar] = None, floating_action_button: Optional[FloatingActionButton] = None, navigation_bar: Optional[NavigationBar] = None, + drawer: Optional[NavigationDrawer] = None, end_drawer: Optional[NavigationDrawer] = None, vertical_alignment: MainAxisAlignment = MainAxisAlignment.NONE, horizontal_alignment: CrossAxisAlignment = CrossAxisAlignment.NONE, @@ -65,6 +66,7 @@ def __init__( self.route = route self.appbar = appbar self.navigation_bar = navigation_bar + self.drawer = drawer self.end_drawer = end_drawer self.floating_action_button = floating_action_button self.vertical_alignment = vertical_alignment @@ -91,7 +93,11 @@ def _get_children(self): children.append(self.__fab) if self.__navigation_bar: children.append(self.__navigation_bar) + if self.__drawer: + self.__drawer._set_attr_internal("n", "start") + children.append(self.__drawer) if self.__end_drawer: + self.__end_drawer._set_attr_internal("n", "end") children.append(self.__end_drawer) children.extend(self.__controls) return children @@ -141,6 +147,15 @@ def navigation_bar(self) -> Optional[NavigationBar]: def navigation_bar(self, value: Optional[NavigationBar]): self.__navigation_bar = value + # drawer + @property + def drawer(self) -> Optional[NavigationDrawer]: + return self.__drawer + + @drawer.setter + def drawer(self, value: Optional[NavigationDrawer]): + self.__drawer = value + # end_drawer @property def end_drawer(self) -> Optional[NavigationDrawer]: From d5bde6a9bd694337db79b0d932096a1962420513 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 10:12:59 -0800 Subject: [PATCH 05/21] NavigationDrawerDestination icon property --- package/lib/src/controls/navigation_drawer.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 1c8eb2e03..9e5a7f35f 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -8,6 +8,7 @@ import '../models/control.dart'; import '../models/controls_view_model.dart'; import '../protocol/update_control_props_payload.dart'; import '../utils/colors.dart'; +import '../utils/icons.dart'; class NavigationDrawerControl extends StatefulWidget { final Control? parent; @@ -73,6 +74,14 @@ class _NavigationDrawerControlState extends State { .where((c) => c.isVisible && c.name == null) .map((c) => c.id)), builder: (content, viewModel) { + List children = viewModel.controlViews.map((destView) { + var icon = + getMaterialIcon(destView.control.attrString("icon", "")!); + return NavigationDrawerDestination( + icon: Icon(icon), + label: Text('Text'), + ); + }).toList(); return NavigationDrawer( //labelBehavior: labelBehavior, //height: widget.control.attrDouble("height"), @@ -82,7 +91,7 @@ class _NavigationDrawerControlState extends State { Theme.of(context), widget.control.attrString("bgColor", "")!), selectedIndex: _selectedIndex, onDestinationSelected: _destinationChanged, - children: const [Icon(Icons.add)], + children: children, // destinations: viewModel.controlViews.map((destView) { // var label = destView.control.attrString("label", "")!; From 9c76fbbb8b899b165d2ef5db24893b863a04942a Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 10:16:21 -0800 Subject: [PATCH 06/21] icon_content for destination --- package/lib/src/controls/navigation_drawer.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 9e5a7f35f..3467b5423 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -9,6 +9,7 @@ import '../models/controls_view_model.dart'; import '../protocol/update_control_props_payload.dart'; import '../utils/colors.dart'; import '../utils/icons.dart'; +import 'create_control.dart'; class NavigationDrawerControl extends StatefulWidget { final Control? parent; @@ -77,8 +78,13 @@ class _NavigationDrawerControlState extends State { List children = viewModel.controlViews.map((destView) { var icon = getMaterialIcon(destView.control.attrString("icon", "")!); + var iconContentCtrls = + destView.children.where((c) => c.name == "icon_content"); return NavigationDrawerDestination( - icon: Icon(icon), + icon: iconContentCtrls.isNotEmpty + ? createControl( + destView.control, iconContentCtrls.first.id, disabled) + : Icon(icon), label: Text('Text'), ); }).toList(); From 977eb72157ef95bee89c1ee64544856cc7466868 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 10:50:55 -0800 Subject: [PATCH 07/21] destinations changed to controls --- .../lib/src/controls/navigation_drawer.dart | 27 +++++++++++-------- .../src/flet_core/navigation_drawer.py | 18 ++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 3467b5423..e965cd6c2 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -76,17 +76,22 @@ class _NavigationDrawerControlState extends State { .map((c) => c.id)), builder: (content, viewModel) { List children = viewModel.controlViews.map((destView) { - var icon = - getMaterialIcon(destView.control.attrString("icon", "")!); - var iconContentCtrls = - destView.children.where((c) => c.name == "icon_content"); - return NavigationDrawerDestination( - icon: iconContentCtrls.isNotEmpty - ? createControl( - destView.control, iconContentCtrls.first.id, disabled) - : Icon(icon), - label: Text('Text'), - ); + if (destView.control.type == "navigationdrawerdestination") { + var icon = + getMaterialIcon(destView.control.attrString("icon", "")!); + var iconContentCtrls = + destView.children.where((c) => c.name == "icon_content"); + return NavigationDrawerDestination( + icon: iconContentCtrls.isNotEmpty + ? createControl( + destView.control, iconContentCtrls.first.id, disabled) + : Icon(icon), + label: Text('Text'), + ); + } else { + return createControl( + widget.control, destView.control.id, disabled); + } }).toList(); return NavigationDrawer( //labelBehavior: labelBehavior, diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 0dc9a5beb..536630480 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -212,7 +212,7 @@ def __init__( # # NavigationDrawer-specific open: bool = False, - destinations: Optional[List[NavigationDrawerDestination]] = None, + controls: Optional[List[Control]] = None, selected_index: Optional[int] = None, bgcolor: Optional[str] = None, # label_behavior: Optional[NavigationBarLabelBehavior] = None, @@ -248,7 +248,7 @@ def __init__( ) self.open = open - self.destinations = destinations + self.controls = controls self.selected_index = selected_index # self.label_behavior = label_behavior self.bgcolor = bgcolor @@ -260,7 +260,7 @@ def _get_control_name(self): def _get_children(self): children = [] - children.extend(self.__destinations) + children.extend(self.__controls) return children # open @@ -272,14 +272,14 @@ def open(self) -> Optional[bool]: def open(self, value: Optional[bool]): self._set_attr("open", value) - # destinations + # controls @property - def destinations(self) -> Optional[List[NavigationDrawerDestination]]: - return self.__destinations + def controls(self) -> Optional[List[Control]]: + return self.__controls - @destinations.setter - def destinations(self, value: Optional[List[NavigationDrawerDestination]]): - self.__destinations = value if value is not None else [] + @controls.setter + def controls(self, value: Optional[List[Control]]): + self.__controls = value if value is not None else [] # on_change @property From 75c556a61540e8f1e7d7d857b071cf2e861ac355 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 11:40:02 -0800 Subject: [PATCH 08/21] removed bgColor property for NavigationDrawerDestination as it doesn't work in flutter https://github.com/flutter/flutter/issues/138105 --- .../lib/src/controls/navigation_drawer.dart | 5 ++++- .../src/flet_core/navigation_drawer.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index e965cd6c2..24c577fff 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -82,11 +82,14 @@ class _NavigationDrawerControlState extends State { var iconContentCtrls = destView.children.where((c) => c.name == "icon_content"); return NavigationDrawerDestination( + // backgroundColor: HexColor.fromString(Theme.of(context), + // destView.control.attrString("bgColor", "")!), + icon: iconContentCtrls.isNotEmpty ? createControl( destView.control, iconContentCtrls.first.id, disabled) : Icon(icon), - label: Text('Text'), + label: Text('Text2'), ); } else { return createControl( diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 536630480..f0a6a38bb 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -75,7 +75,7 @@ def show_end_drawer(e): def __init__( self, ref: Optional[Ref] = None, - bgcolor: Optional[str] = None, + # bgcolor: Optional[str] = None, icon: Optional[str] = None, icon_content: Optional[Control] = None, label: Optional[str] = None, @@ -84,7 +84,7 @@ def __init__( ): Control.__init__(self, ref=ref) self.label = label - self.bgcolor = bgcolor + # self.bgcolor = bgcolor self.icon = icon self.__icon_content: Optional[Control] = None self.icon_content = icon_content @@ -107,14 +107,14 @@ def _get_children(self): children.append(self.__selected_icon_content) return children - # bgcolor - @property - def bgcolor(self): - return self._get_attr("bgColor") + # # bgcolor + # @property + # def bgcolor(self): + # return self._get_attr("bgColor") - @bgcolor.setter - def bgcolor(self, value): - self._set_attr("bgColor", value) + # @bgcolor.setter + # def bgcolor(self, value): + # self._set_attr("bgColor", value) # icon @property From 452f86f12ddedd88f6c02527215a7a4081de1a65 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 11:48:44 -0800 Subject: [PATCH 09/21] Update navigation_drawer.dart --- package/lib/src/controls/navigation_drawer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 24c577fff..6cb4a6bb8 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -84,7 +84,7 @@ class _NavigationDrawerControlState extends State { return NavigationDrawerDestination( // backgroundColor: HexColor.fromString(Theme.of(context), // destView.control.attrString("bgColor", "")!), - + // flutter issue https://github.com/flutter/flutter/issues/138105 icon: iconContentCtrls.isNotEmpty ? createControl( destView.control, iconContentCtrls.first.id, disabled) From 2a57878012fd39eb3b6f6de17fe6ea746e658638 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Wed, 8 Nov 2023 12:55:16 -0800 Subject: [PATCH 10/21] selected_icon and selected_icon_content --- package/lib/src/controls/navigation_drawer.dart | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 6cb4a6bb8..d22454a4c 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -81,6 +81,10 @@ class _NavigationDrawerControlState extends State { getMaterialIcon(destView.control.attrString("icon", "")!); var iconContentCtrls = destView.children.where((c) => c.name == "icon_content"); + var selectedIcon = getMaterialIcon( + destView.control.attrString("selectedIcon", "")!); + var selectedIconContentCtrls = destView.children + .where((c) => c.name == "selected_icon_content"); return NavigationDrawerDestination( // backgroundColor: HexColor.fromString(Theme.of(context), // destView.control.attrString("bgColor", "")!), @@ -89,7 +93,13 @@ class _NavigationDrawerControlState extends State { ? createControl( destView.control, iconContentCtrls.first.id, disabled) : Icon(icon), - label: Text('Text2'), + label: Text(destView.control.attrString("label", "")!), + selectedIcon: selectedIconContentCtrls.isNotEmpty + ? createControl(destView.control, + selectedIconContentCtrls.first.id, disabled) + : selectedIcon != null + ? Icon(selectedIcon) + : null, ); } else { return createControl( From d022ed961852b37e376462617f8b1c8f2c37df56 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 09:51:49 -0800 Subject: [PATCH 11/21] elevation property --- .../lib/src/controls/navigation_drawer.dart | 4 + .../src/flet_core/navigation_drawer.py | 89 +++---------------- 2 files changed, 14 insertions(+), 79 deletions(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index d22454a4c..029175421 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -111,8 +111,12 @@ class _NavigationDrawerControlState extends State { //height: widget.control.attrDouble("height"), elevation: widget.control.attrDouble("elevation"), + //elevation: 40, + + shadowColor: Colors.red, backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), + surfaceTintColor: Colors.blue, selectedIndex: _selectedIndex, onDestinationSelected: _destinationChanged, children: children, diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index f0a6a38bb..c4a7e6f18 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -12,23 +12,6 @@ ScaleValue, ) -# try: -# from typing import Literal -# except ImportError: -# from typing_extensions import Literal - -# NavigationBarLabelBehaviorString = Literal[ -# None, "alwaysShow", "alwaysHide", "onlyShowSelected" -# ] - - -# class NavigationBarLabelBehavior(Enum): -# """Defines how the destinations' labels will be laid out and when they'll be displayed.""" - -# ALWAYS_SHOW = "alwaysShow" -# ALWAYS_HIDE = "alwaysHide" -# ONLY_SHOW_SELECTED = "onlyShowSelected" - class NavigationDrawerDestination(Control): """ @@ -185,63 +168,19 @@ def __init__( disabled: Optional[bool] = None, visible: Optional[bool] = None, data: Any = None, - # ref: Optional[Ref] = None, - # width: OptionalNumber = None, - # height: OptionalNumber = None, - # left: OptionalNumber = None, - # top: OptionalNumber = None, - # right: OptionalNumber = None, - # bottom: OptionalNumber = None, - # expand: Union[None, bool, int] = None, - # col: Optional[ResponsiveNumber] = None, - # opacity: OptionalNumber = None, - # rotate: RotateValue = None, - # scale: ScaleValue = None, - # offset: OffsetValue = None, - # aspect_ratio: OptionalNumber = None, - # animate_opacity: AnimationValue = None, - # animate_size: AnimationValue = None, - # animate_position: AnimationValue = None, - # animate_rotation: AnimationValue = None, - # animate_scale: AnimationValue = None, - # animate_offset: AnimationValue = None, - # on_animation_end=None, - # visible: Optional[bool] = None, - # disabled: Optional[bool] = None, - # data: Any = None, # # NavigationDrawer-specific + # open: bool = False, controls: Optional[List[Control]] = None, selected_index: Optional[int] = None, bgcolor: Optional[str] = None, - # label_behavior: Optional[NavigationBarLabelBehavior] = None, elevation: OptionalNumber = None, on_change=None, ): Control.__init__( self, ref=ref, - # width=width, - # height=height, - # left=left, - # top=top, - # right=right, - # bottom=bottom, - # expand=expand, - # col=col, - # opacity=opacity, - # rotate=rotate, - # scale=scale, - # offset=offset, - # aspect_ratio=aspect_ratio, - # animate_opacity=animate_opacity, - # animate_size=animate_size, - # animate_position=animate_position, - # animate_rotation=animate_rotation, - # animate_scale=animate_scale, - # animate_offset=animate_offset, - # on_animation_end=on_animation_end, visible=visible, disabled=disabled, data=data, @@ -250,7 +189,6 @@ def __init__( self.open = open self.controls = controls self.selected_index = selected_index - # self.label_behavior = label_behavior self.bgcolor = bgcolor self.elevation = elevation self.on_change = on_change @@ -299,22 +237,6 @@ def selected_index(self) -> Optional[int]: def selected_index(self, value: Optional[int]): self._set_attr("selectedIndex", value) - # # label_behavior - # @property - # def label_behavior(self) -> Optional[NavigationBarLabelBehavior]: - # return self.__label_behavior - - # @label_behavior.setter - # def label_behavior(self, value: Optional[NavigationBarLabelBehavior]): - # self.__label_behavior = value - # if isinstance(value, NavigationBarLabelBehavior): - # self._set_attr("labelType", value.value) - # else: - # self.__set_label_behavior(value) - - # def __set_label_behavior(self, value: NavigationBarLabelBehaviorString): - # self._set_attr("labelType", value) - # bgcolor @property def bgcolor(self): @@ -323,3 +245,12 @@ def bgcolor(self): @bgcolor.setter def bgcolor(self, value): self._set_attr("bgcolor", value) + + # elevation + @property + def elevation(self) -> OptionalNumber: + return self._get_attr("elevation") + + @elevation.setter + def elevation(self, value: OptionalNumber): + self._set_attr("elevation", value) From 4c85e5a46b75faffc0ffb45a5665aebb683d7d69 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 09:59:47 -0800 Subject: [PATCH 12/21] indicator_color property --- package/lib/src/controls/navigation_drawer.dart | 6 ++---- .../flet-core/src/flet_core/navigation_drawer.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 029175421..d231386cd 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -107,11 +107,9 @@ class _NavigationDrawerControlState extends State { } }).toList(); return NavigationDrawer( - //labelBehavior: labelBehavior, - //height: widget.control.attrDouble("height"), - elevation: widget.control.attrDouble("elevation"), - //elevation: 40, + indicatorColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("indicatorColor", "")!), shadowColor: Colors.red, backgroundColor: HexColor.fromString( diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index c4a7e6f18..adf3aa22d 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -176,6 +176,7 @@ def __init__( selected_index: Optional[int] = None, bgcolor: Optional[str] = None, elevation: OptionalNumber = None, + indicator_color: Optional[str] = None, on_change=None, ): Control.__init__( @@ -191,6 +192,7 @@ def __init__( self.selected_index = selected_index self.bgcolor = bgcolor self.elevation = elevation + self.indicator_color = indicator_color self.on_change = on_change def _get_control_name(self): @@ -254,3 +256,12 @@ def elevation(self) -> OptionalNumber: @elevation.setter def elevation(self, value: OptionalNumber): self._set_attr("elevation", value) + + # indicator_color + @property + def indicator_color(self): + return self._get_attr("indicatorColor") + + @indicator_color.setter + def indicator_color(self, value): + self._set_attr("indicatorColor", value) From 67a0529178a645fd77be4d56c4ed863f803b2d80 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 10:28:21 -0800 Subject: [PATCH 13/21] indicator_shape property --- .../lib/src/controls/navigation_drawer.dart | 3 +++ .../src/flet_core/navigation_drawer.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index d231386cd..150d4ea4c 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -10,6 +10,7 @@ import '../protocol/update_control_props_payload.dart'; import '../utils/colors.dart'; import '../utils/icons.dart'; import 'create_control.dart'; +import '../utils/borders.dart'; class NavigationDrawerControl extends StatefulWidget { final Control? parent; @@ -110,6 +111,8 @@ class _NavigationDrawerControlState extends State { elevation: widget.control.attrDouble("elevation"), indicatorColor: HexColor.fromString(Theme.of(context), widget.control.attrString("indicatorColor", "")!), + indicatorShape: + parseOutlinedBorder(widget.control, "indicatorShape"), shadowColor: Colors.red, backgroundColor: HexColor.fromString( diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index adf3aa22d..798e9a856 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -12,6 +12,8 @@ ScaleValue, ) +from flet_core.buttons import OutlinedBorder + class NavigationDrawerDestination(Control): """ @@ -177,6 +179,7 @@ def __init__( bgcolor: Optional[str] = None, elevation: OptionalNumber = None, indicator_color: Optional[str] = None, + indicator_shape: Optional[OutlinedBorder] = None, on_change=None, ): Control.__init__( @@ -193,11 +196,17 @@ def __init__( self.bgcolor = bgcolor self.elevation = elevation self.indicator_color = indicator_color + self.indicator_shape = indicator_shape + self.on_change = on_change def _get_control_name(self): return "navigationdrawer" + def _before_build_command(self): + super()._before_build_command() + self._set_attr_json("indicatorShape", self.__indicator_shape) + def _get_children(self): children = [] children.extend(self.__controls) @@ -265,3 +274,12 @@ def indicator_color(self): @indicator_color.setter def indicator_color(self, value): self._set_attr("indicatorColor", value) + + # indicator_shape + @property + def indicator_shape(self) -> Optional[OutlinedBorder]: + return self.__indicator_shape + + @indicator_shape.setter + def indicator_shape(self, value: Optional[OutlinedBorder]): + self.__indicator_shape = value From cb0a218fbb49d5e4336608542da29671c9a77b19 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 10:41:28 -0800 Subject: [PATCH 14/21] shadow_color property --- package/lib/src/controls/navigation_drawer.dart | 3 ++- .../flet-core/src/flet_core/navigation_drawer.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 150d4ea4c..59792e741 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -114,11 +114,12 @@ class _NavigationDrawerControlState extends State { indicatorShape: parseOutlinedBorder(widget.control, "indicatorShape"), - shadowColor: Colors.red, backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), surfaceTintColor: Colors.blue, selectedIndex: _selectedIndex, + shadowColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("shadowColor", "")!), onDestinationSelected: _destinationChanged, children: children, // destinations: viewModel.controlViews.map((destView) { diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 798e9a856..67d98bba0 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -180,6 +180,7 @@ def __init__( elevation: OptionalNumber = None, indicator_color: Optional[str] = None, indicator_shape: Optional[OutlinedBorder] = None, + shadow_color: Optional[str] = None, on_change=None, ): Control.__init__( @@ -197,6 +198,7 @@ def __init__( self.elevation = elevation self.indicator_color = indicator_color self.indicator_shape = indicator_shape + self.shadow_color = shadow_color self.on_change = on_change @@ -283,3 +285,12 @@ def indicator_shape(self) -> Optional[OutlinedBorder]: @indicator_shape.setter def indicator_shape(self, value: Optional[OutlinedBorder]): self.__indicator_shape = value + + # shadow_color + @property + def shadow_color(self): + return self._get_attr("shadowColor") + + @shadow_color.setter + def shadow_color(self, value): + self._set_attr("shadowColor", value) From 8a69bfd4254797da1bd69e3ca1f02d9c6aa5b4c6 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 10:47:03 -0800 Subject: [PATCH 15/21] surface_tint_color property --- package/lib/src/controls/navigation_drawer.dart | 4 +++- .../flet-core/src/flet_core/navigation_drawer.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index 59792e741..cefad1a57 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -116,10 +116,12 @@ class _NavigationDrawerControlState extends State { backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), - surfaceTintColor: Colors.blue, + selectedIndex: _selectedIndex, shadowColor: HexColor.fromString(Theme.of(context), widget.control.attrString("shadowColor", "")!), + surfaceTintColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("surfaceTintColor", "")!), onDestinationSelected: _destinationChanged, children: children, // destinations: viewModel.controlViews.map((destView) { diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 67d98bba0..383c6dd30 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -181,6 +181,7 @@ def __init__( indicator_color: Optional[str] = None, indicator_shape: Optional[OutlinedBorder] = None, shadow_color: Optional[str] = None, + surface_tint_color: Optional[str] = None, on_change=None, ): Control.__init__( @@ -199,6 +200,7 @@ def __init__( self.indicator_color = indicator_color self.indicator_shape = indicator_shape self.shadow_color = shadow_color + self.surface_tint_color = surface_tint_color self.on_change = on_change @@ -294,3 +296,12 @@ def shadow_color(self): @shadow_color.setter def shadow_color(self, value): self._set_attr("shadowColor", value) + + # surface_tint_color + @property + def surface_tint_color(self): + return self._get_attr("surfaceTintColor") + + @surface_tint_color.setter + def surface_tint_color(self, value): + self._set_attr("surfaceTintColor", value) From b6ba9c743e71c21f7b76a7f36371cdce99aa1d5e Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 12:27:18 -0800 Subject: [PATCH 16/21] refactor --- .../lib/src/controls/navigation_drawer.dart | 38 +---- .../src/flet_core/navigation_drawer.py | 150 +++++++++++------- 2 files changed, 96 insertions(+), 92 deletions(-) diff --git a/package/lib/src/controls/navigation_drawer.dart b/package/lib/src/controls/navigation_drawer.dart index cefad1a57..ecae4e811 100644 --- a/package/lib/src/controls/navigation_drawer.dart +++ b/package/lib/src/controls/navigation_drawer.dart @@ -11,6 +11,7 @@ import '../utils/colors.dart'; import '../utils/icons.dart'; import 'create_control.dart'; import '../utils/borders.dart'; +import '../utils/edge_insets.dart'; class NavigationDrawerControl extends StatefulWidget { final Control? parent; @@ -63,11 +64,6 @@ class _NavigationDrawerControlState extends State { _selectedIndex = selectedIndex; } - // NavigationDestinationLabelBehavior? labelBehavior = - // NavigationDestinationLabelBehavior.values.firstWhereOrNull((a) => - // a.name.toLowerCase() == - // widget.control.attrString("labelBehavior", "")!.toLowerCase()); - var navDrawer = StoreConnector( distinct: true, converter: (store) => ControlsViewModel.fromStore( @@ -113,48 +109,20 @@ class _NavigationDrawerControlState extends State { widget.control.attrString("indicatorColor", "")!), indicatorShape: parseOutlinedBorder(widget.control, "indicatorShape"), - backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), - selectedIndex: _selectedIndex, shadowColor: HexColor.fromString(Theme.of(context), widget.control.attrString("shadowColor", "")!), surfaceTintColor: HexColor.fromString(Theme.of(context), widget.control.attrString("surfaceTintColor", "")!), + tilePadding: parseEdgeInsets(widget.control, "tilePadding") ?? + const EdgeInsets.symmetric(horizontal: 12.0), onDestinationSelected: _destinationChanged, children: children, - // destinations: viewModel.controlViews.map((destView) { - // var label = destView.control.attrString("label", "")!; - - // var icon = - // getMaterialIcon(destView.control.attrString("icon", "")!); - // var iconContentCtrls = - // destView.children.where((c) => c.name == "icon_content"); - - // var selectedIcon = getMaterialIcon( - // destView.control.attrString("selectedIcon", "")!); - // var selectedIconContentCtrls = destView.children - // .where((c) => c.name == "selected_icon_content"); - - // return NavigationDestination( - // icon: iconContentCtrls.isNotEmpty - // ? createControl(destView.control, - // iconContentCtrls.first.id, disabled) - // : Icon(icon), - // selectedIcon: selectedIconContentCtrls.isNotEmpty - // ? createControl(destView.control, - // selectedIconContentCtrls.first.id, disabled) - // : selectedIcon != null - // ? Icon(selectedIcon) - // : null, - // label: label); - //}).toList()); ); }); - // return constrainedControl( - // context, navDrawer, widget.parent, widget.control); return navDrawer; } } diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 383c6dd30..4bd340f24 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -5,11 +5,7 @@ from flet_core.control import Control, OptionalNumber from flet_core.ref import Ref from flet_core.types import ( - AnimationValue, - OffsetValue, - ResponsiveNumber, - RotateValue, - ScaleValue, + PaddingValue, ) from flet_core.buttons import OutlinedBorder @@ -19,42 +15,6 @@ class NavigationDrawerDestination(Control): """ Displays an icon with a label, for use in NavigationDrawer destinations. - import time - - import flet as ft - - - def main(page: ft.Page): - page.drawer = ft.NavigationDrawer( - destinations=[ft.NavigationDrawerDestination(icon=ft.icons.ABC, label="Item 1")] - ) - page.end_drawer = ft.NavigationDrawer( - destinations=[ - ft.NavigationDrawerDestination(icon=ft.icons.ABC, label="End drawer") - ] - ) - - def show_drawer(e): - page.drawer.open = True - page.drawer.update() - time.sleep(2) - page.drawer.open = False - page.drawer.update() - - def show_end_drawer(e): - page.end_drawer.open = True - page.end_drawer.update() - time.sleep(3) - page.drawer.open = True - page.drawer.update() - - page.add( - ft.ElevatedButton("Show drawer", on_click=show_drawer), - ft.ElevatedButton("Show end drawer", on_click=show_end_drawer), - ) - - - ft.app(main) """ def __init__( @@ -149,19 +109,83 @@ def label(self, value): class NavigationDrawer(Control): """ - Material Design Navigation Drawer component. + Material Design Navigation Drawer component. + + Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. - Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. + Example: - Example: + ``` + import flet as ft - ``` - ``` + def main(page: ft.Page): + def item_selected_left(e): + print(e.control.selected_index) - ----- + page.drawer = ft.NavigationDrawer( + elevation=40, + indicator_color=ft.colors.GREEN_200, + indicator_shape=ft.StadiumBorder(), + shadow_color=ft.colors.GREEN_900, + surface_tint_color=ft.colors.GREEN, + selected_index=-1, + on_change=item_selected_left, + controls=[ + ft.Container(height=12), + ft.NavigationDrawerDestination( + label="Item 1", + icon=ft.icons.ABC, + selected_icon_content=ft.Icon(ft.icons.ACCESS_ALARM), + ), + ft.Divider(thickness=2), + ft.NavigationDrawerDestination( + icon_content=ft.Icon(ft.icons.MAIL), + label="Item 2", + selected_icon=ft.icons.PHISHING, + ), + ft.NavigationDrawerDestination( + icon_content=ft.Icon(ft.icons.PHONE), + label="Item 3", + selected_icon=ft.icons.PHISHING, + ), + ], + ) + page.end_drawer = ft.NavigationDrawer( + controls=[ + ft.NavigationDrawerDestination( + icon=ft.icons.ADD_TO_HOME_SCREEN_SHARP, label="Item 1" + ), + ft.NavigationDrawerDestination(icon=ft.icons.ADD_COMMENT, label="Item 2"), + ], + ) - Online docs: https://flet.dev/docs/controls/navigationdrawer + def show_drawer(e): + page.drawer.open = True + page.drawer.update() + + def show_end_drawer(e): + page.end_drawer.open = True + page.end_drawer.update() + + page.add( + ft.Row( + alignment=ft.MainAxisAlignment.SPACE_BETWEEN, + controls=[ + ft.ElevatedButton("Show drawer", on_click=show_drawer), + ft.ElevatedButton("Show end drawer", on_click=show_end_drawer), + ], + ) + ) + + + ft.app(main) + + ``` + + ----- + + Online docs: https://flet.dev/docs/controls/navigationdrawer """ def __init__( @@ -182,6 +206,7 @@ def __init__( indicator_shape: Optional[OutlinedBorder] = None, shadow_color: Optional[str] = None, surface_tint_color: Optional[str] = None, + tile_padding: PaddingValue = None, on_change=None, ): Control.__init__( @@ -201,6 +226,7 @@ def __init__( self.indicator_shape = indicator_shape self.shadow_color = shadow_color self.surface_tint_color = surface_tint_color + self.tile_padding = tile_padding self.on_change = on_change @@ -210,6 +236,7 @@ def _get_control_name(self): def _before_build_command(self): super()._before_build_command() self._set_attr_json("indicatorShape", self.__indicator_shape) + self._set_attr_json("tilePadding", self.__tile_padding) def _get_children(self): children = [] @@ -234,15 +261,6 @@ def controls(self) -> Optional[List[Control]]: def controls(self, value: Optional[List[Control]]): self.__controls = value if value is not None else [] - # on_change - @property - def on_change(self): - return self._get_event_handler("change") - - @on_change.setter - def on_change(self, handler): - self._add_event_handler("change", handler) - # selected_index @property def selected_index(self) -> Optional[int]: @@ -305,3 +323,21 @@ def surface_tint_color(self): @surface_tint_color.setter def surface_tint_color(self, value): self._set_attr("surfaceTintColor", value) + + # tile_padding + @property + def tile_padding(self) -> PaddingValue: + return self.__tile_padding + + @tile_padding.setter + def tile_padding(self, value: PaddingValue): + self.__tile_padding = value + + # on_change + @property + def on_change(self): + return self._get_event_handler("change") + + @on_change.setter + def on_change(self, handler): + self._add_event_handler("change", handler) From 6eb06e97d85f0ce2dd2899410671d3e7c9ce4039 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 12:46:03 -0800 Subject: [PATCH 17/21] added elevation and shadow_color to NavigationBar --- package/lib/src/controls/navigation_bar.dart | 2 + .../flet-core/src/flet_core/navigation_bar.py | 38 ++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/package/lib/src/controls/navigation_bar.dart b/package/lib/src/controls/navigation_bar.dart index df88a1d2d..64a94787a 100644 --- a/package/lib/src/controls/navigation_bar.dart +++ b/package/lib/src/controls/navigation_bar.dart @@ -79,6 +79,8 @@ class _NavigationBarControlState extends State { labelBehavior: labelBehavior, height: widget.control.attrDouble("height"), elevation: widget.control.attrDouble("elevation"), + shadowColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("shadowColor", "")!), backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), selectedIndex: _selectedIndex, diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py index 51a5f1119..01b502233 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py @@ -182,6 +182,7 @@ def __init__( bgcolor: Optional[str] = None, label_behavior: Optional[NavigationBarLabelBehavior] = None, elevation: OptionalNumber = None, + shadow_color: Optional[str] = None, on_change=None, ): ConstrainedControl.__init__( @@ -217,6 +218,7 @@ def __init__( self.label_behavior = label_behavior self.bgcolor = bgcolor self.elevation = elevation + self.shadow_color = shadow_color self.on_change = on_change def _get_control_name(self): @@ -236,15 +238,6 @@ def destinations(self) -> Optional[List[NavigationDestination]]: def destinations(self, value: Optional[List[NavigationDestination]]): self.__destinations = value if value is not None else [] - # on_change - @property - def on_change(self): - return self._get_event_handler("change") - - @on_change.setter - def on_change(self, handler): - self._add_event_handler("change", handler) - # selected_index @property def selected_index(self) -> Optional[int]: @@ -278,3 +271,30 @@ def bgcolor(self): @bgcolor.setter def bgcolor(self, value): self._set_attr("bgcolor", value) + + # elevation + @property + def elevation(self) -> OptionalNumber: + return self._get_attr("elevation") + + @elevation.setter + def elevation(self, value: OptionalNumber): + self._set_attr("elevation", value) + + # shadow_color + @property + def shadow_color(self): + return self._get_attr("shadowColor") + + @shadow_color.setter + def shadow_color(self, value): + self._set_attr("shadowColor", value) + + # on_change + @property + def on_change(self): + return self._get_event_handler("change") + + @on_change.setter + def on_change(self, handler): + self._add_event_handler("change", handler) From 836e3ca267ce607bd6cd4022ed4f9dbd366d1ff6 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 13:12:04 -0800 Subject: [PATCH 18/21] indicator_color, indicator_shape, surface_tint_color, shadow_color, elevation for NavigationBar --- package/lib/src/controls/navigation_bar.dart | 7 ++++ .../flet-core/src/flet_core/navigation_bar.py | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/package/lib/src/controls/navigation_bar.dart b/package/lib/src/controls/navigation_bar.dart index 64a94787a..48172c86e 100644 --- a/package/lib/src/controls/navigation_bar.dart +++ b/package/lib/src/controls/navigation_bar.dart @@ -11,6 +11,7 @@ import '../protocol/update_control_props_payload.dart'; import '../utils/colors.dart'; import '../utils/icons.dart'; import 'create_control.dart'; +import '../utils/borders.dart'; class NavigationBarControl extends StatefulWidget { final Control? parent; @@ -81,6 +82,12 @@ class _NavigationBarControlState extends State { elevation: widget.control.attrDouble("elevation"), shadowColor: HexColor.fromString(Theme.of(context), widget.control.attrString("shadowColor", "")!), + surfaceTintColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("surfaceTintColor", "")!), + indicatorColor: HexColor.fromString(Theme.of(context), + widget.control.attrString("indicatorColor", "")!), + indicatorShape: + parseOutlinedBorder(widget.control, "indicatorShape"), backgroundColor: HexColor.fromString( Theme.of(context), widget.control.attrString("bgColor", "")!), selectedIndex: _selectedIndex, diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py index 01b502233..6eafa86d7 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_bar.py @@ -12,6 +12,8 @@ ScaleValue, ) +from flet_core.buttons import OutlinedBorder + try: from typing import Literal except ImportError: @@ -183,6 +185,9 @@ def __init__( label_behavior: Optional[NavigationBarLabelBehavior] = None, elevation: OptionalNumber = None, shadow_color: Optional[str] = None, + indicator_color: Optional[str] = None, + indicator_shape: Optional[OutlinedBorder] = None, + surface_tint_color: Optional[str] = None, on_change=None, ): ConstrainedControl.__init__( @@ -219,11 +224,18 @@ def __init__( self.bgcolor = bgcolor self.elevation = elevation self.shadow_color = shadow_color + self.indicator_color = indicator_color + self.indicator_shape = indicator_shape + self.surface_tint_color = surface_tint_color self.on_change = on_change def _get_control_name(self): return "navigationbar" + def _before_build_command(self): + super()._before_build_command() + self._set_attr_json("indicatorShape", self.__indicator_shape) + def _get_children(self): children = [] children.extend(self.__destinations) @@ -290,6 +302,33 @@ def shadow_color(self): def shadow_color(self, value): self._set_attr("shadowColor", value) + # indicator_color + @property + def indicator_color(self): + return self._get_attr("indicatorColor") + + @indicator_color.setter + def indicator_color(self, value): + self._set_attr("indicatorColor", value) + + # indicator_shape + @property + def indicator_shape(self) -> Optional[OutlinedBorder]: + return self.__indicator_shape + + @indicator_shape.setter + def indicator_shape(self, value: Optional[OutlinedBorder]): + self.__indicator_shape = value + + # surface_tint_color + @property + def surface_tint_color(self): + return self._get_attr("surfaceTintColor") + + @surface_tint_color.setter + def surface_tint_color(self, value): + self._set_attr("surfaceTintColor", value) + # on_change @property def on_change(self): From 562ee5d64e4addccd38de66792c1e5ad75f4a28d Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Thu, 9 Nov 2023 13:25:49 -0800 Subject: [PATCH 19/21] show_drawer, show_end_drawer, close_drawer, close_end_drawer for page --- .../src/flet_core/navigation_drawer.py | 20 ++++----- .../packages/flet-core/src/flet_core/page.py | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 4bd340f24..41cff65e1 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -109,13 +109,13 @@ def label(self, value): class NavigationDrawer(Control): """ - Material Design Navigation Drawer component. + Material Design Navigation Drawer component. - Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. + Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. - Example: + Example: - ``` + ``` import flet as ft @@ -151,7 +151,8 @@ def item_selected_left(e): ), ], ) - page.end_drawer = ft.NavigationDrawer( + + end_drawer = ft.NavigationDrawer( controls=[ ft.NavigationDrawerDestination( icon=ft.icons.ADD_TO_HOME_SCREEN_SHARP, label="Item 1" @@ -165,8 +166,7 @@ def show_drawer(e): page.drawer.update() def show_end_drawer(e): - page.end_drawer.open = True - page.end_drawer.update() + page.show_end_drawer(end_drawer) page.add( ft.Row( @@ -181,11 +181,11 @@ def show_end_drawer(e): ft.app(main) - ``` + ``` - ----- + ----- - Online docs: https://flet.dev/docs/controls/navigationdrawer + Online docs: https://flet.dev/docs/controls/navigationdrawer """ def __init__( diff --git a/sdk/python/packages/flet-core/src/flet_core/page.py b/sdk/python/packages/flet-core/src/flet_core/page.py index d398ff38f..7ab12e66f 100644 --- a/sdk/python/packages/flet-core/src/flet_core/page.py +++ b/sdk/python/packages/flet-core/src/flet_core/page.py @@ -1051,6 +1051,50 @@ async def close_bottom_sheet_async(self): self.__offstage.bottom_sheet.open = False await self.__offstage.update_async() + # Drawer + # + def show_drawer(self, drawer: NavigationDrawer): + self.drawer = drawer + self.drawer.open = True + self.update() + + async def show_drawer_async(self, drawer: NavigationDrawer): + self.drawer = drawer + self.drawer.open = True + await self.update_async() + + def close_drawer(self): + if self.drawer is not None: + self.drawer.open = False + self.update() + + async def close_drawer_async(self): + if self.drawer is not None: + self.drawer.open = False + await self.drawer.update_async() + + # End_drawer + # + def show_end_drawer(self, end_drawer: NavigationDrawer): + self.end_drawer = end_drawer + self.end_drawer.open = True + self.update() + + async def show_end_drawer_async(self, end_drawer: NavigationDrawer): + self.end_drawer = end_drawer + self.end_drawer.open = True + await self.update_async() + + def close_end_drawer(self): + if self.end_drawer is not None: + self.end_drawer.open = False + self.update() + + async def close_end_drawer_async(self): + if self.end_drawer is not None: + self.end_drawer.open = False + await self.end_drawer.update_async() + def window_destroy(self): self._set_attr("windowDestroy", "true") self.update() From b65fb57a4326514bb061ac79c848861f52b507c0 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Fri, 10 Nov 2023 09:36:44 -0800 Subject: [PATCH 20/21] on_dismiss for NavigationDrawer --- .../flet-core/src/flet_core/navigation_drawer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 41cff65e1..72046adcd 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -208,6 +208,7 @@ def __init__( surface_tint_color: Optional[str] = None, tile_padding: PaddingValue = None, on_change=None, + on_dismiss=None, ): Control.__init__( self, @@ -229,6 +230,7 @@ def __init__( self.tile_padding = tile_padding self.on_change = on_change + self.on_dismiss = on_dismiss def _get_control_name(self): return "navigationdrawer" @@ -341,3 +343,12 @@ def on_change(self): @on_change.setter def on_change(self, handler): self._add_event_handler("change", handler) + + # on_dismiss + @property + def on_dismiss(self): + return self._get_event_handler("dismiss") + + @on_dismiss.setter + def on_dismiss(self, handler): + self._add_event_handler("dismiss", handler) From f47cda3b06779128ff5a298cd1618fcebdad0a43 Mon Sep 17 00:00:00 2001 From: InesaFitsner Date: Fri, 10 Nov 2023 09:48:34 -0800 Subject: [PATCH 21/21] updated comments --- .../flet-core/src/flet_core/navigation_drawer.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py index 72046adcd..3e1c1563b 100644 --- a/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py +++ b/sdk/python/packages/flet-core/src/flet_core/navigation_drawer.py @@ -109,13 +109,13 @@ def label(self, value): class NavigationDrawer(Control): """ - Material Design Navigation Drawer component. + Material Design Navigation Drawer component. - Navigation drawers offer a persistent and convenient way to switch between primary destinations in an app. + Navigation Drawer is a panel slides in horizontally from the left or right edge of a page to show primary destinations in an app. - Example: + Example: - ``` + ``` import flet as ft @@ -181,11 +181,11 @@ def show_end_drawer(e): ft.app(main) - ``` + ``` - ----- + ----- - Online docs: https://flet.dev/docs/controls/navigationdrawer + Online docs: https://flet.dev/docs/controls/navigationdrawer """ def __init__(