Skip to content

Commit

Permalink
AppBar, NavigationRail - Python
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed May 14, 2022
1 parent 8110110 commit 4751be9
Show file tree
Hide file tree
Showing 5 changed files with 469 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/lib/controls/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class PageControl extends StatelessWidget {
darkTheme: darkTheme,
themeMode: themeMode,
home: Scaffold(
appBar: null,
body: Stack(children: [
SizedBox.expand(
child: Container(
Expand Down
13 changes: 10 additions & 3 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* [x] Tabs
* [ ] AppBar
* [ ] NavigationRail
* [ ] NavigationBar
* Basic controls
* [x] Text
* [x] Icon
Expand Down Expand Up @@ -56,12 +55,19 @@
* Flet Daemon
* [x] "assets" directory with static content

* Samples apps
* [x] Counter
* [x] To-Do
* [x] Icon browser
* [ ] Chat

* Website
* [ ] Controls S1 reference
* [x] Introduction
* [ ] Home page
* [ ] Blog post
* [ ] Python Guide
* [ ] Deployment (+how to change favicon.ico)
* Deployment (+how to change favicon.ico)
* [x] Deployment to Replit
* [x] Deployment to Fly.io

Expand All @@ -70,7 +76,8 @@
* Authentication
* Controls
* Navigation
* NavigationDrawer
* NavigationDrawer
* NavigationBar
* Layout
* Row (responsive)
* Column (responsive)
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/flet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flet.alert_dialog import AlertDialog
from flet.app_bar import AppBar
from flet.banner import Banner
from flet.checkbox import Checkbox
from flet.circle_avatar import CircleAvatar
Expand All @@ -17,6 +18,7 @@
from flet.icon_button import IconButton
from flet.image import Image
from flet.list_view import ListView
from flet.navigation_rail import NavigationRail, NavigationRailDestination
from flet.outlined_button import OutlinedButton
from flet.page import Page
from flet.popup_menu_button import PopupMenuButton, PopupMenuItem
Expand Down
133 changes: 133 additions & 0 deletions sdk/python/flet/app_bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import json
from typing import Literal, Optional, Union

from beartype import beartype
from beartype.typing import List

from flet import padding
from flet.constrained_control import ConstrainedControl
from flet.control import Control, OptionalNumber, PaddingValue
from flet.embed_json_encoder import EmbedJsonEncoder
from flet.ref import Ref


class AppBar(Control):
def __init__(
self,
ref: Ref = None,
leading: Control = None,
leading_width: OptionalNumber = None,
title: Control = None,
center_title: bool = None,
toolbar_height: OptionalNumber = None,
color: str = None,
bgcolor: str = None,
actions: List[Control] = None,
):
Control.__init__(self, ref=ref)

self.__leading: Control = None
self.__title: Control = None
self.__actions: List[Control] = []

self.leading = leading
self.leading_width = leading_width
self.title = title
self.center_title = center_title
self.toolbar_height = toolbar_height
self.color = color
self.bgcolor = bgcolor
self.actions = actions

def _get_control_name(self):
return "appbar"

def _get_children(self):
children = []
if self.__leading:
self.__leading._set_attr_internal("n", "leading")
children.append(self.__leading)
if self.__title:
self.__title._set_attr_internal("n", "title")
children.append(self.__title)
for action in self.__actions:
action._set_attr_internal("n", "action")
children.append(action)
return children

# leading
@property
def leading(self):
return self.__leading

@leading.setter
@beartype
def leading(self, value: Optional[Control]):
self.__leading = value

# leading_width
@property
def leading_width(self):
return self._get_attr("leadingWidth")

@leading_width.setter
@beartype
def leading_width(self, value: OptionalNumber):
self._set_attr("leadingWidth", value)

# title
@property
def title(self):
return self.__title

@title.setter
@beartype
def title(self, value: Optional[Control]):
self.__title = value

# center_title
@property
def center_title(self):
return self._get_attr("centerTitle", data_type="bool", def_value=False)

@center_title.setter
@beartype
def center_title(self, value: Optional[bool]):
self._set_attr("centerTitle", value)

# toolbar_height
@property
def toolbar_height(self):
return self._get_attr("toolbarHeight")

@toolbar_height.setter
@beartype
def toolbar_height(self, value: OptionalNumber):
self._set_attr("toolbarHeight", value)

# color
@property
def color(self):
return self._get_attr("color")

@color.setter
def color(self, value):
self._set_attr("color", value)

# bgcolor
@property
def bgcolor(self):
return self._get_attr("bgcolor")

@bgcolor.setter
def bgcolor(self, value):
self._set_attr("bgcolor", value)

# actions
@property
def actions(self):
return self.__actions

@actions.setter
def actions(self, value):
self.__actions = value or []
Loading

0 comments on commit 4751be9

Please sign in to comment.