diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..27a080a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Shafwan Junindra + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/advanced/async_await.dart b/advanced/async_await.dart new file mode 100644 index 0000000..bbd90c6 --- /dev/null +++ b/advanced/async_await.dart @@ -0,0 +1,11 @@ +Future fetchData() async { + print("⏳ Mengambil data..."); + await Future.delayed(Duration(seconds: 2)); + print("✅ Data berhasil diambil!"); +} + +void main() { + print("🚀 Start"); + fetchData(); + print("🏁 Program selesai (menunggu data...)"); +} diff --git a/advanced/exception_handling.dart b/advanced/exception_handling.dart new file mode 100644 index 0000000..05bda8e --- /dev/null +++ b/advanced/exception_handling.dart @@ -0,0 +1,10 @@ +void main() { + try { + int hasil = 10 ~/ 0; // Error: pembagian nol + print("Hasil: $hasil"); + } catch (e) { + print("❌ Terjadi error: $e"); + } finally { + print("🔚 Program tetap jalan meskipun error."); + } +} diff --git a/advanced/future_example.dart b/advanced/future_example.dart new file mode 100644 index 0000000..5ebc47c --- /dev/null +++ b/advanced/future_example.dart @@ -0,0 +1,13 @@ +Future getUser() { + return Future.delayed(Duration(seconds: 1), () => "Shafwan"); +} + +void main() { + print("🔍 Mengambil user..."); + + getUser().then((user) { + print("👤 User: $user"); + }); + + print("🏁 Selesai"); +} diff --git a/advanced/json_handling.dart b/advanced/json_handling.dart new file mode 100644 index 0000000..62f9e6f --- /dev/null +++ b/advanced/json_handling.dart @@ -0,0 +1,16 @@ +import 'dart:convert'; + +void main() { + // Dari String ke Map + String jsonString = '{"nama": "Shafwan", "umur": 16}'; + Map data = jsonDecode(jsonString); + print("👤 Nama: ${data['nama']}, Umur: ${data['umur']}"); + + // Dari Map ke String + Map user = { + 'username': 'suffjasteb', + 'level': 'advanced' + }; + String encoded = jsonEncode(user); + print("📦 JSON: $encoded"); +}