Skip to main content

Posts

Showing posts with the label Formatted

Jetpack compose: ViewModel Room delete clear data

Introduction This code demonstrates a Jetpack Compose application that utilizes Room database to manage employee data. The application allows adding new employees, deleting existing ones, and clearing all data. It leverages ViewModel to manage the data state and provide a single source of truth for the UI. Breakdown The code is organized into several classes: MainActivity.kt : This is the main activity that sets the content of the app using a Composable function called MainContent . MainContent.kt : This composable function builds the UI for the app. It retrieves data from the ViewModel, displays the number of employees, and presents a list of employees. It also provides buttons for adding new employees and clearing all data. RoomSingleton.kt : This class defines a Room database named "roomdb" with a single entity - Employee . It provides a singleton instance using the getInstance method. Employee.kt : This data class represents an employee with an ID (Long) and a ...

flutter - How to change PopupMenuButton icon

Flutter - PopupMenuButton Change Icon The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to set or change the PopupMenuButton widget’s icon. Here we used the PopupMenuButton class’s icon property to change the default icon of the PupupMenuButton widget. Here we also change the default color of the PopupMenuButton widget’s replaced icon. The PopupMenuButton class’s icon property value is a widget that is the icon used for this button and the button will behave like an Ic...

flutter - How to use PopupMenuItem onTap

Flutter - PopupMenuItem onTap The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to use the PopupMenuItem widget’s tap callback. Here we used the PopupMenuItem class’s onTap property to set the PupupMenuButton widget’s item tap callback. The flutter PopupMenuItem class represents an item in a material design popup menu. Normally the child of a PopupMenuItem is a Text widget. But the flutter developers can build more complex items such as they can show both an icon and ...

flutter - How to use PopupMenuButton onSelected

Flutter - PopupMenuButton onSelected The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to use the PopupMenuButton widget’s onSelected callback. Here we used the PopupMenuButton class’s onSelected property to set the PupupMenuButton widget’s item selection callback. The PopupMenuButton class’s onSelected property value is a PopupMenuItemSelected instance that is called when the user selects a value from the popup menu created by this button. But if the popup menu is dis...

flutter - How to show icon and text on PopupMenuButton items

Flutter - PopupMenuButton Icon & Text The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to display both a text and an icon on each item in a PopupMenuButton widget. Here we used the PopupMenuButton class’s itemBuilder property to add items to the PupupMenuButton widgets. And also configure the menu items to show text and an icon inside each item of the PopupMenuButton widget. The PopupMenuButton class’s itemBuilder property value is a PopupMenuItemBuilder instanc...

flutter - How to change PopupMenuButton items icon color

Flutter - PopupMenuButton Items Icon Color The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to display both a text and an icon on each item in a PopupMenuButton widget. And how to change the icon color of menu items in a PopupMenuButton widget by a single setting. Here we used the PopupMenuButton class’s itemBuilder property to add items to the PupupMenuButton widgets. And we wrapped the PopupMenuButton widget with a Theme widget to set or change a common color for the menu...

flutter - How to add divider to PopupMenuButton

Flutter - PopupMenuButton Divider The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to add a divider between PopupMenuButton items. Here we used the PopupMenuButton class’s itemBuilder property to add items to the PupupMenuButton widgets. And also add a divider line between each item by placing the PopupMenuDivider instance between items. The PopupMenuButton class’s itemBuilder property value is a PopupMenuItemBuilder instance. The PopupMenuItemBuilder is called when...

flutter - How to change PopupMenuButton offset

Flutter - PopupMenuButton Offset The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to set or change the offset value of a PopupMenuButton widget. Here we used the PopupMenuButton class’s offset property to set or change the PupupMenuButton widget’s default offset value. The PopupMenuButton class’s offset property value is an Offset instance that is the offset is applied relative to the initial position set by the position. If the flutter developers do not set the Popup...

flutter - How to change PopupMenuButton width

Flutter - PopupMenuButton Width The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to set or change the PopupMenuButton widget width. But there is no direct property or method to set or change the width of a PopupMenuButton widget. So we have to take help from another property of PopupMenuButton class. Here we used the PopupMenuButton class’s itemBuilder property to specify the width of PopupMenuButton items, this will finally change the width of the PopupMenuButton widge...

flutter - How to change PopupMenuButton shape

Flutter - PopupMenuButton Shape The PopupMenuButton class allows us to display a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item. The flutter developers can provide one of a child or an icon but not both. If developers provide an icon then PopupMenuButton behaves like an IconButton. If both child and icon are null, then a standard overflow icon is created depending on the platform. The following flutter app development tutorial will demonstrate how to set or change the PopupMenuButton widget shape. Here we used the PopupMenuButton class’s shape property to specify the shape of a PopupMenuButton widget. We rendered a rounded corners PopupMenuButton in this flutter example. The PopupMenuButton class’s shape property value is a ShapeBorder instance that defines the shape of the menu. When flutter developers leave the shape property...

flutter - How to use IconButton onPressed

Flutter - IconButton onPressed The IconButton class represents a material design icon button. IconButton is a picture printed on a material widget that reacts to touches by filling with color. The flutter developers commonly used the Icon buttons in the AppBar actions field, but IconButtons can also be used in many other places. The flutter app developers can leave the onPressed callback null to disable an IconButton, it will not react to touch. The following flutter app development tutorial will demonstrate how to use IconButton onPressed property. The IconButton onPressed property makes the button clickable when the developers set a value to it. If they pass a null value to this onPressed property value the button act as disable/nonclickable. Actually, the onPressed property is used to trigger an action when someone clicks the IconButton widget. The IconButton class’s onPressed property value is a callback that is called when the button is tapp...

flutter - How to disable an IconButton

Flutter - IconButton Disable The IconButton class represents a material design icon button. IconButton is a picture printed on a material widget that reacts to touches by filling with color. The flutter developers commonly used the Icon buttons in the AppBar actions field, but IconButtons can also be used in many other places. The flutter app developers can leave the onPressed callback null to disable an IconButton, it will not react to touch. The following flutter app development tutorial will demonstrate how to disable an IconButton widget. Here we will also set a color for the IconButton widget’s disabled state. The IconButton class’s onPressed property value is a callback that is called when the button is tapped or otherwise activated. When the flutter developers set this property value to null, the button will be disabled. So in this flutter example code, we passed a null value for the IconButton onPressed property to disable the IconButton ...

flutter - IconButton remove splash

Flutter - IconButton Remove Splash The IconButton class represents a material design icon button. IconButton is a picture printed on a material widget that reacts to touches by filling with color. The flutter developers commonly used the Icon buttons in the AppBar actions field, but IconButtons can also be used in many other places. The flutter app developers can leave the onPressed callback null to disable an IconButton, it will not react to touch. The following flutter app development tutorial will demonstrate how to remove the splash from an IconButton widget. In this example code, we used the IconButon class’s splashColor property to remove the splash effect of an InconButton widget. Here we also change the icon button’s highlight color by using the IconButton class’s highlightColor property. The IconButton class’s splashColor property value is a Color that defines the primary color of the button when the button is in the down/pressed state. Th...

flutter - How to remove IconButton padding

Flutter - IconButton Remove Padding The IconButton class represents a material design icon button. IconButton is a picture printed on a material widget that reacts to touches by filling with color. The flutter developers commonly used the Icon buttons in the AppBar actions field, but IconButtons can be used in many other places as well. The flutter app developers can leave the onPressed callback null to disable an IconButton, then it will not react to touch. The following flutter app development tutorial will demonstrate how to remove the padding from an IconButton widget. In this example code, we used the IconButon class’s padding property to remove the padding of an InconButton widget. Here we also change the icon button’s splash radius by using the IconButton class’s splashRadius property. The IconButton class’s padding property defines the padding around the button's icon. The entire padded icon will react to input gestures. The padding p...