This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "date": "2025-08-29", | |
| "topic": "Draw a shoe" | |
| }, | |
| { | |
| "date": "2025-08-30", | |
| "topic": "Draw a desk lamp" | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "date": "2025-08-28", | |
| "question": "What is one small thing I did recently that made you feel appreciated?" | |
| }, | |
| { | |
| "date": "2025-08-29", | |
| "question": "What is one small thing I did recently that made you feel appreciated?" | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Sample Code | |
| @Composable | |
| fun MainContent(userDao: UserDao) { | |
| val userList = remember { mutableStateListOf<User>() } | |
| LaunchedEffect(Unit) { | |
| userList.value = userDao.getAllUsers() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Path: composeApp/src/desktopMain/kotlin/main.kt | |
| fun main() = application { | |
| Window( | |
| onCloseRequest = ::exitApplication, | |
| title = "projName", | |
| ) { | |
| val database = remember { getDatabaseBuilder() } | |
| App(database) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // composeApp/src/desktopMain/kotlin/database/Database.kt | |
| import androidx.room.Room | |
| import androidx.room.RoomDatabase | |
| import data.database.DictionaryDatabase | |
| import java.io.File | |
| fun getDatabaseBuilder(): RoomDatabase.Builder<DictionaryDatabase> { | |
| val dbFile = File(System.getProperty("java.io.tmpdir"), "user.db") | |
| return Room.databaseBuilder<DictionaryDatabase>( | |
| name = dbFile.absolutePath, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Path: composeApp/src/iosMain/kotlin/MainViewController.kt | |
| fun MainViewController() = ComposeUIViewController { | |
| val database = remember { getUserDatabase() } | |
| App(database) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Save at: composeApp/src/iosMain/kotlin/database/Database.kt | |
| import androidx.room.Room | |
| import androidx.room.RoomDatabase | |
| import data.database.UserDatabase | |
| import data.database.instantiateImpl // This shall show error, ignore it | |
| import platform.Foundation.NSHomeDirectory // This shall too in Windows. | |
| fun getUserDatabase(): RoomDatabase.Builder<UserDatabase> { | |
| val dbFile = NSHomeDirectory() + "/user.db" | |
| return Room.databaseBuilder<UserDatabase>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Path: composeApp/src/androidMain/kotlin/com/yourOrg/projName/MainActivity.kt | |
| class MainActivity : ComponentActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| val database = getUserDatabase(applicationContext) | |
| setContent { | |
| App(database) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Save at: composeApp/src/androidMain/kotlin/com/yourOrg/projName/database/Database.kt | |
| import android.content.Context | |
| import androidx.room.Room | |
| import androidx.room.RoomDatabase | |
| import data.database.UserDatabase | |
| fun getUserDatabase(context: Context): RoomDatabase.Builder<UserDatabase> { | |
| val dbFile = context.getDatabasePath("user.db") | |
| return Room.databaseBuilder<UserDatabase>( | |
| context = context.applicationContext, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is your entry point for your CMP App | |
| @Composable | |
| fun App( | |
| databaseBuilder: RoomDatabase.Builder<UserDatabase> | |
| ) { | |
| MaterialTheme { | |
| // Building the database | |
| val database = remember { databaseBuilder.build() } |
NewerOlder