Null Safety Switch Dartpad

Beranda › Forums › Belajar Flutter Mobile Apps Tingkat Pemula › Null Safety Switch Dartpad

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #48364
    Sicario
    Participant

      Mohon info cara memunculkan switch null safety di dartpad.
      Sudah dicoba menggunakan beberapa browser berbeda, tetap sama. Terima kasih

      #48372
      Anonymous
        #48436
        Sicario
        Participant

          Coach, pakai https://dartpad.dev/?null_safety=false masih belum berhasil.

          Syntax:
          class Manusia{
          String nama;
          int umur;
          Manusia({this.nama, this.umur});
          }

          void main(){
          var m1 = Manusia(nama: ‘Andi’,umur: 17);
          print(m1.nama);
          print(m1.umur);
          }

          Pesan Error:
          Error compiling to JavaScript:
          Info: Compiling with sound null safety
          Warning: Interpreting this as package URI, ‘package:dartpad_sample/main.dart’.
          lib/main.dart:4:17:
          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:4:28:
          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.

          #48462
          Anonymous

            Bisa dicoba menggunakan ini
            class Manusia{
            String? nama;
            int? umur;
            Manusia({this.nama, this.umur});
            }

            void main(){
            var m1 = Manusia(nama: ‘Andi’,umur: 17);
            print(m1.nama);
            print(m1.umur);
            }

            Diberikan tanda tanya, yang artinya, kemungkinan isi dari nama/umur bisa null

          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