Skip to main content

Posts

Showing posts with the label Compose Better

Jetpack compose: Room Add, Remove, Update

Jetpack Compose - Room Add, Remove, Update This code demonstrates a basic Android application built with Jetpack Compose that utilizes Room for data persistence. The app manages a list of "Students" with functionalities to add, remove, and update them. Key Components: Room Database: The RoomSingleton class defines a Room database with a single entity - Student . It provides methods to access the DAO (Data Access Object) for interacting with student data. Student Entity: The Student data class represents a student record with properties like ID (primary key), name (full name), and result (integer). StudentDao: This interface defines methods for CRUD (Create, Read, Update, Delete) operations on student data within the database. StudentViewModel: This ViewModel class acts as the single source of truth for student data. It holds a reference to the Room database instance and exposes functions to interact with students (insert, update, delete, clear all). Mai...

jetpack compose - Box gradient background color

Compose Box Gradient Background Color The Box is a layout widget of the android jetpack compose library. The Box is a single-child container. The Box layout is helpful to align the child element in a specific position. The following jetpack compose tutorial demonstrates to us how we can set a gradient background color to a Box layout. The Box constructor has no specific argument to set or change its background color. So how do we set a background color to it? As with other layout widgets, we can set a background color to a Box widget by using its ‘modifier’ argument’s ‘background’ element. The modifier’s ‘background()’ function element has several constructors to specify a background color or brush for the widget. The ’background()’ element has a constructor that accepts a ‘brush’ argument. The ‘brush’ argument data type is ‘Brush’. So we can pass a Brush instance to the Box widget to draw its background. We can create any type of gradient brush to draw a gradient background ...

jetpack compose - Column align bottom

Compose Column Align Bottom The Column is a jetpack compose layout widget. The Column layout places its elements in vertical sequences. By default, the Column lays out its elements from top to bottom. The Column layout aligns its element from the top start. The following jetpack compose tutorial will demonstrate how we can align Column children widgets at the bottom position. That means we lay out Column elements from the bottom position to the top position. We can set Column container size using its modifier argument. If we set the Column layout size to fill the maximum available size and we want to put a child element at the bottom of the Column container, then what should we do to achieve it? The Column widget constructor has an argument named ‘verticalArrangement’. The ‘verticalArrangement’ argument data type is ‘Arrangement.Vertical’ and it is used to specify the vertical arrangement of the layout’s children. The default value for this argument is ‘Arrangement.Top’. So t...