Beranda › Forums › Belajar Flutter Mobile Apps Tingkat Menengah › tidak bisa jalankan di emulator (error)
Tagged: Praktik SQLite part II
- This topic has 4 replies, 2 voices, and was last updated 4 years, 4 months ago by Anonymous.
-
AuthorPosts
-
July 13, 2022 at 8:55 PM #51616
Dear Coach,
saat jalankan di emulator terjadi error dan muncul pada debug console tulisan berikut ini:
Running “flutter pub get” in notes…
Because every version of flutter_test from sdk depends on path 1.8.1 and notes depends on path ^1.8.2, flutter_test from sdk is forbidden.
So, because notes depends on flutter_test from sdk, version solving failed.
pub get failed (1; So, because notes depends on flutter_test from sdk, version solving failed.)
Exited (1)mohon masukkanya coach..terimakasih sebelumnya..
July 13, 2022 at 8:56 PM #51617Code database_helper.dart
import ‘package:notes/models/note.dart’;
import ‘package:path/path.dart’;
import ‘package:sqflite/sqflite.dart’;class DatabaseHelper {
// tambahkan variable static const untuk menghindari typo dan memudahkan merubah nama table
static const TABLE_NOTES = ‘notes’;
static const TABLE_NOTES_ID = ‘id’;
static const TABLE_NOTES_NOTE = ‘note’;
static const TABLE_NOTES_TITLE = ‘title’;
static const TABLE_NOTES_ISPINNED = ‘isPinned’;
static const TABLE_NOTES_UPDATEDAT = ‘updated_at’;
static const TABLE_NOTES_CREATEDAT = ‘created_at’;// buat fungsi untuk open database
static Future<Database> init() async {
final dbPath = await getDatabasesPath();
return openDatabase(join(dbPath, ‘notes.db’), version: 1,
onCreate: (newDb, version) {
newDb.execute(”’
CREATE TABLE $TABLE_NOTES (
$TABLE_NOTES_ID TEXT PRIMARY KEY,
$TABLE_NOTES_TITLE TEXT,
$TABLE_NOTES_NOTE TEXT,
$TABLE_NOTES_ISPINNED INTEGER,
$TABLE_NOTES_UPDATEDAT TEXT,
$TABLE_NOTES_CREATEDAT TEXT
)
”’);
});
}// buat fungsi untuk mendapatkan atau select note nya
Future<List<Note>> getAllNote() async {
final db = await DatabaseHelper.init();
final result = await db.query(‘notes’);List<Note> listNote = [];
result.forEach((data) {
listNote.add(Note.fromDb(data));
});return listNote;
}// buat fungsi untuk insert semua note
Future<void> insertAllNote(List<Note> listNote) async {
final db = await DatabaseHelper.init();
// fungsi Batch untuk insert banyak data
Batch batch = db.batch();listNote.forEach((note) {
batch.insert(
‘notes’,
note.toDb(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
});await batch.commit();
}// fungsi untuk update data pada database helper
Future<void> updateNote(Note note) async {
final db = await DatabaseHelper.init();
await db.update(TABLE_NOTES, note.toDb(),
where: ‘$TABLE_NOTES_ID = ?’, whereArgs: [note.id]);
}// fungsi untuk update toogleIspinned pada database helper
Future<void> toogleIspinned(
String id, bool isPinned, DateTime updatedAt) async {
final db = await DatabaseHelper.init();
await db.update(
TABLE_NOTES,
{
TABLE_NOTES_ISPINNED: isPinned ? 1 : 0,
TABLE_NOTES_UPDATEDAT: updatedAt.toIso8601String(),
},
where: ‘$TABLE_NOTES_ID = ?’,
whereArgs: [id],
);
}// fungsi untuk update deleteNote pada database helper
Future<void> deleteNote(String id) async {
final db = await DatabaseHelper.init();
await db.delete(TABLE_NOTES, where: ‘$TABLE_NOTES_ID = ?’, whereArgs: [id]);
}
}July 15, 2022 at 11:00 AM #51692AnonymousHi,
bisa coba buka cmd dan run flutter doctor?
trus coba kirimin hasil dari flutter doctornya.Terima kasih.
July 15, 2022 at 11:07 AM #51694Sudah bisa jalan cocah.. Saya coba ganti di pubspec.yaml path nya dari 1.8.2 ke 1.8.1..tetimakasih sebelum nya coach
July 15, 2022 at 3:06 PM #51703AnonymousSip mantap, semangat terus.
-
AuthorPosts
- You must be logged in to reply to this topic.