Upgrade Skill Di ITBOX Jadi Lebih Hemat
Special Diskon 50%
Sampai 16 November 2026!
Hari
Jam
Menit
Detik
GARUDABOX

Class and Object

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #190612
    albert.s
    Participant

      hello coach , aku nulis code seperti ini

      class Manusia{
      String nama;
      int umur ;
      //constructor = > NamaClass(isiAtribut)
      Manusia({this.nama, this.umur});
      }
      void main (){

      var m1 = Manusia(nama :’andi’, umur :17);
      print (m1.nama);
      print (m1.umur);
      }

      namun ketika di run :

      Error compiling to JavaScript:
      Info: Compiling with sound null safety
      lib/main.dart:6:16:
      Error: The parameter ‘nama’ can’t have a value of ‘null’ because of its type ‘String’, but the implicit default value is ‘null’.
      Manusia({this.nama, this.umur});
      ^^^^
      lib/main.dart:6:27:
      Error: The parameter ‘umur’ can’t have a value of ‘null’ because of its type ‘int’, but the implicit default value is ‘null’.
      Manusia({this.nama, this.umur});
      ^^^^
      Error: Compilation failed.

      padahal di video coach ga ada error. 😐

      #191020
      Anonymous

        ini saat di dart ya? tambahkan (?) setelah int

        class Manusia{
        String? nama;
        int? umur ;
        //constructor = > NamaClass(isiAtribut)
        Manusia({this.nama, this.umur});
        }
        #191647
        albert.s
        Participant

          done, thnakyou coach

          #191818
          Anonymous

            siap sama sama

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.
          Shopping cart0
          There are no products in the cart!
          Continue shopping