Forum Replies Created
-
AuthorPosts
-
August 2, 2022 at 8:33 AM in reply to: Note yang terakhir saat di pin membuat note yang lain ikut ter pin #103470
sudah bisa berjalan coach kode nya…terimakasih banyak coach atas penjelasan nya..
Sudah bisa berjalan coach..terimakasih banyak coach arahan dan petunjuknya..
Sudah saya hapus dan saya buat ulang di firebase coach..
namun di emulator tetap error : Exception : Error terjadi kesalahan..
di firebase:
N01
created_at:”2022-07-17T19:42:47.490535″
isPinned:false
note:”Test isi note”
title:”Test title”
updated_at:”2022-07-17T19:42:47.490535″ini full code saya coach di github: https://github.com/Vram-AH/aplikasi-notes-flutter
dear coach jadi terhapus semua coach saat
“note”: “123”,
“title”: “123”,
“updated_at”: “2022-07-17T13:08:53.668538″ di hapus..atau saya boleh minta source code untuk app note nya coach, biar saya samain code nya…terimakasih sebelumnya coach..
sudah sesuai coach di VS code tidak ada ’, sepertinya berubah di forum itbox saat copy coach..
maaf coach yang ini $#8217; dikode yang mana ya coach?
sudah saya ubah coach di Firebase..namun masih belum bisa berjalan di emulator..
// fungsi untuk delete dan ubah atau kirim data tersebut ke server
Future<void> deleteNote(String? id) async {
final uri = Uri.parse(
‘https://notes-9f78d-default-rtdb.asia-southeast1.firebasedatabase.app/notes/$id.json’);
try {
final response = await http.delete(uri);
if (response.statusCode != 200) {
throw Exception();
}
} on SocketException {
throw SocketException(‘Tidak dapat tersambung ke internet’);
} catch (e) {
throw Exception(‘Error, terjadi kesalahan’);
}
}
}// tambahkan fungsi toggleIspined agar saat note di PIN maka terupdate pada server
Future<void> toggleIsPinned(
String? id, bool? isPinned, DateTime updatedAt) async {
final uri = Uri.parse(
‘https://notes-9f78d-default-rtdb.asia-southeast1.firebasedatabase.app/notes/$id.json’);
Map<String, dynamic> map = {
‘isPinned’: isPinned,
‘updated_at’: updatedAt.toIso8601String(),
};
try {
final body = json.encode(map);
final response = await http.patch(uri, body: body);
if (response.statusCode != 200) throw Exception();
} on SocketException {
throw SocketException(‘Tidak dapat tersambung ke internet’);
} catch (e) {
throw Exception(‘Error, terjadi kesalahan’);
}
}// tambahkan fungsi agar saat note diubah maka akan terupdate juga pada server
Future<void> updateNote(Note note) async {
final uri = Uri.parse(
‘https://notes-9f78d-default-rtdb.asia-southeast1.firebasedatabase.app/notes/${note.id}.json’);
Map<String, dynamic> map = {
‘title’: note.title,
‘note’: note.note,
‘updated_at’: note.updatedAt!.toIso8601String(),
};try {
final body = json.encode(map);
final response = await http.patch(uri, body: body);
if (response.statusCode != 200) throw Exception();
} on SocketException {
throw SocketException(‘Tidak dapat tersambung ke internet’);
} catch (e) {
throw Exception(‘Error, terjadi kesalahan’);
}
}// Buat fungsi note API untuk post note baru
// tambahkan Future pada string dan async agar fungsi await bisa digunakan
Future<String?> postNote(Note note) async {
final uri = Uri.parse(
‘https://notes-9f78d-default-rtdb.asia-southeast1.firebasedatabase.app/notes.json’);
// buat map untuk isi/body yang akan dikirim ke server
Map<String, dynamic> map = {
‘title’: note.title,
‘note’: note.note,
‘isPinned’: note.isPinned,
//1. karena encode akan mengubah data menjadi string json maka note.updatedAt dan note.createdAt di ubah menjadi string dengan toIso8601String
//2. tambahkan validasi karena migrasi ke null agar tidak error
‘updated_at’:
note.updatedAt == null ? null : note.updatedAt!.toIso8601String(),
‘created_at’:
note.createdAt == null ? null : note.createdAt!.toIso8601String()
};try {
// ubah map jadi string json
final body = json.encode(map);
// 1. melakukan post
// 2. tambahkan await agar kode dibawah menunggu proses get data selesai
final response = await http.post(uri, body: body);
if (response.statusCode == 200) {
return json.decode(response.body)[‘name’];
} else {
throw Exception();
}
} on SocketException {
throw SocketException(‘Tidak dapat tersambung ke internet’);
} catch (e) {
throw Exception(‘Error, terjadi kesalahan’);
}
}note.api
import ‘dart:convert’;
import ‘dart:io’;import ‘package:notes/models/note.dart’;
import ‘package:http/http.dart’ as http;// buat class yang berisi semua fungsi untuk koneksi ke server firebase
class NoteApi {
// buat fungsi untuk mendapatkan seluruh note (list)
// tambahkan Future dan async agar fungsi await bisa digunakan
Future<List<Note>> getAllNote() async {
// print(‘pertama dijalankan’);
final uri = Uri.parse(
‘https://notes-9f78d-default-rtdb.asia-southeast1.firebasedatabase.app/notes.json’);
// tambahakan try & catch untuk mengatasi error no internet/SocketException dan merubah tulisannya
List<Note> notes = [];
try {
// tambahkan await agar kode dibawah menunggu proses get data selesai
final response = await http.get(uri);print(response.statusCode);
if (response.statusCode == 200) {
// ubah data json menjadi map
final results = json.decode(response.body) as Map<String, dynamic>;
// looping map result ke List<Note>
results.forEach((key, value) {
notes.add(Note(
id: key,
title: value[‘title’],
note: value[‘note’],
isPinned: value[‘isPinned’],
updatedAt: DateTime.parse(value[‘updated_at’]),
createdAt: DateTime.parse(value[‘created_at’])));
});
} else {
throw Exception();
}
} on SocketException {
throw SocketException(‘Tidak dapat tersambung ke internet’);
} catch (e) {
throw Exception(‘Error terjadi kesalahan’);
}return notes;
}namun saya ada dapat email dari fire base isinya:
notes
[Firebase] Akses klien ke ‘notes-9f78d-default-rtdb’ Realtime Database Anda akan berakhir dalam 4 hariAnda memilih untuk mulai mengembangkan aplikasi dalam Mode Uji, yang membuat instance Realtime Database Anda sepenuhnya terbuka ke internet. Karena pilihan ini membuat aplikasi Anda rentan terhadap penyerang, aturan keamanan database Anda dikonfigurasi untuk berhenti mengizinkan permintaan setelah 30 hari pertama.
Dalam 4 hari, semua permintaan klien ke instance Realtime Database Anda akan ditolak. Sebelum waktu tersebut, harap perbarui aturan keamanan agar aplikasi Anda dapat berfungsi sekaligus melindungi data Anda dengan tepat. Analisis dijalankan setiap hari; jika Anda telah mengubah aturan dalam 24 jam terakhir, perubahan tersebut mungkin tidak diperhitungkan.
ATURAN YANG SEGERA BERAKHIR
notes
Database
notes-9f78d-default-rtdbapa pengaruh ya coach ke API code nya?
g bisa di paste disini coach..saya coba buat post pertanyaan baru coach..
ini yang notes_grid.dart coach
import ‘package:flutter/material.dart’;
import ‘package:notes/models/note.dart’;
import ‘package:notes/providers/notes.dart’;
import ‘package:notes/widgets/note_item.dart’;
import ‘package:provider/provider.dart’;class NotesGrid extends StatefulWidget {
@override
State<NotesGrid> createState() => _NotesGridState();
}class _NotesGridState extends State<NotesGrid> {
@override
Widget build(BuildContext context) {
// gunakan data provider
final notesProvider = Provider.of<Notes>(context);
List<Note> listNote = notesProvider.notes;
return Padding(
padding: EdgeInsets.all(12),
child: GridView.builder(
itemCount: listNote.length,
itemBuilder: (ctx, index) => NoteItem(
id: listNote[index].id,
ctx: context,
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
),
),
);
}
} -
AuthorPosts