Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
namespace = "com.example.medicines"
compileSdk = flutter.compileSdkVersion
ndkVersion = "27.0.12077973"

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
coreLibraryDesugaringEnabled true
}

lintOptions {
disable 'InvalidPackage'
kotlinOptions {
jvmTarget = '11'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.medicines"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
applicationId = "com.example.medicines"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
signingConfig = signingConfigs.debug
}
}
}

flutter {
source '../..'
source = "../.."
}

dependencies {
implementation 'androidx.window:window:1.3.0'
implementation 'androidx.window:window-java:1.3.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
}
3 changes: 1 addition & 2 deletions android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.medicines">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
Expand Down
48 changes: 18 additions & 30 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.medicines">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="medicines"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -19,44 +16,35 @@
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:showWhenLocked="true"
android:turnScreenOn="true">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
android:turnScreenOn="true"
android:exported="true">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<receiver
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver
android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
</application>

</manifest>
21 changes: 5 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

rootProject.buildDir = '../build'
rootProject.buildDir = "../build"
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
project.evaluationDependsOn(":app")
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
}
6 changes: 3 additions & 3 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Tue Apr 16 15:28:58 WIB 2024
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
zipStoreBase=GRADLE_USER_HOME
30 changes: 22 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.7.3" apply false
id "org.jetbrains.kotlin.android" version "1.9.24" apply false
}

include ":app"
26 changes: 17 additions & 9 deletions lib/database/pills_database.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@


import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

class PillsDatabase{
class PillsDatabase {

setDatabase() async{
Future<Database> setDatabase() async {
String databasePath = await getDatabasesPath();
String path = join(databasePath,"pills_db");
Database database = await openDatabase(path,version: 1,onCreate: (Database db,int version)async{
await db.execute("CREATE TABLE Pills (id INTEGER PRIMARY KEY, name TEXT, amount TEXT, type TEXT, howManyWeeks INTEGER, medicineForm TEXT, time INTEGER, notifyId INTEGER)");
String path = join(databasePath, "pills_db");
Database database = await openDatabase(path, version: 1, onCreate: (Database db, int version) async {
await db.execute('''
CREATE TABLE Pills (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
amount TEXT,
type TEXT,
howManyWeeks INTEGER,
medicineForm TEXT,
time INTEGER,
notifyId INTEGER
)
''');
});
return database;
}

}
}
58 changes: 30 additions & 28 deletions lib/database/repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,49 @@
import 'package:medicine/database/pills_database.dart';
import 'package:sqflite/sqflite.dart';

class Repository{
class Repository {
final PillsDatabase _pillsDatabase = PillsDatabase();
static Database? _database;

PillsDatabase _pillsDatabase = PillsDatabase();
static Database _database;

//init database
Future<Database> get database async{
if(_database != null) return _database;
_database = await _pillsDatabase.setDatabase();
return _database;
Future<Database> get database async {
if (_database == null || !_database!.isOpen) {
_database = await _pillsDatabase.setDatabase();
}
return _database!;
}

//insert something to database
Future<int> insertData(String table,Map<String,dynamic> data) async{
Database db = await database;
try{
Future<int?> insertData(String table, Map<String, dynamic> data) async {
try {
final db = await database;

if (!data.containsKey('name') || !data.containsKey('amount') || !data.containsKey('type')) {
throw Exception('Data tidak lengkap, pastikan semua kolom yang diperlukan ada.');
}

return await db.insert(table, data);
}catch(e){
} catch (e) {
print('Error inserting data into $table: $e');
return null;
}
}

//get all data from database
Future<List<Map<String,dynamic>>> getAllData(table) async{
Database db = await database;
try{
return db.query(table);
}catch(e){
Future<List<Map<String, dynamic>>?> getAllData(String table) async {
try {
final db = await database;
return await db.query(table);
} catch (e) {
print('Error fetching data: $e');
return null;
}
}

//delete data
Future<int> deleteData(String table,int id) async{
Database db = await database;
try{
return await db.delete(table,where: "id = ?", whereArgs: [id]);
}catch(e){
Future<int?> deleteData(String table, int id) async {
try {
final db = await database;
return await db.delete(table, where: "id = ?", whereArgs: [id]);
} catch (e) {
print('Error deleting data: $e');
return null;
}
}


}
Loading