Dart Collections: Arrays or LIST as Fixed-length List. Dart for Flutter #11.1

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • Access 7000+ courses for 15 days FREE: pluralsight.pxf.io/c/1291657/...
    Dart beginners guide. Explore Arrays or Fixed length List in Ordered Dart Collections. Dart supports various Collection types such as Set, Map, HashSet, HashMap, Queue, LinkedList. Let us explore each one of them in this section.
    Next Video : • Dart Collections: Arra...
    Previous Video : • Dart Lexical Closures ...
    Code Files: bit.ly/2Xzd4mG .
    .
    Please donate and support my work
    (If you think my free tutorials are better than paid ones :)
    - Patreon: bit.ly/patreon-donate
    - Paypal/Payoneer: sriyank123@gmail.com
    - UPI (only for India): smartherd@okaxis
    :: If you want to develop a website or a mobile app, email me your requirement at sriyank.siddhartha@gmail.com :: Free demos provided beforehand ::
    - Access my premium courses: bit.ly/sriyank-courses
    Free Programming courses:
    - Ruby Programming: bit.ly/smyt-r
    - Dart Programming: bit.ly/smyt-d
    - Kotlin Programming: bit.ly/smyt-k
    - Java Programming: bit.ly/smyt-j
    - Kotlin Coroutines: bit.ly/smyt-coru
    Free Flutter course:
    - Flutter App Development: bit.ly/2Rg7EFR
    Free Android courses:
    - Android using Kotlin: bit.ly/smyt-ka
    - Android using Java: bit.ly/smyt-ja
    - Android Material Design: bit.ly/2SMJqU6
    - Android Jetpack Architecture: bit.ly/yt-j
    - Android Multiple Screen Support: bit.ly/smyt-mss
    - Android Retrofit: bit.ly/2Ee6GHn
    More free programming courses:
    - bit.ly/smy-list
    Check out my website:
    - bit.ly/smartherd
    Let's get in touch! [Sriyank Siddhartha]
    LinkedIn: bit.ly/sriyank-linkedin
    Facebook: bit.ly/smartherd-facebook
    Instagram: bit.ly/sriyank-instagram
    Twitter: bit.ly/sriyank-twitter
    Github: bit.ly/smartherd-github
    --- Thank you for your love and support ---

ความคิดเห็น • 43

  • @harshrishiwal6255
    @harshrishiwal6255 4 หลายเดือนก่อน +1

    To people facing the same issue :
    Reason:
    In modern Dart, when we write List Dart considers this as a List of integers but we know that in Dart, variables without any value are null!
    so that's where the problem arises List of integers with a null value in it,
    Solution:
    Use this instead, i.e. pre-populate the array: -
    List numberList = List.filled(5, -1); // -1 can be any integer number

    • @raptorrogue4227
      @raptorrogue4227 3 หลายเดือนก่อน

      Thankyou 🔥

    • @userl-mo4sl
      @userl-mo4sl หลายเดือนก่อน

      How about strings?

  • @annapurnasid
    @annapurnasid 2 ปีที่แล้ว +8

    Dart List constructor is not supported any more. You can use the following to create a fixed length list now:
    List numbersList = List.filled(5, null);
    int? implies the list items can be null.
    If you want the default value to be 0 and that the list shouldn't have null value, use this instead:
    List numbersList = List.filled(5, 0);

    • @knight5970
      @knight5970 ปีที่แล้ว

      thanks bro you solved my problem, i have been searching for this accurate explanation for 2 days.

    • @jamshaidali3193
      @jamshaidali3193 ปีที่แล้ว

      OR you can simply initialized List with having some length e.g ( List numberofvalues = [10 ];

  • @AnilPawar-lp1zd
    @AnilPawar-lp1zd 2 ปีที่แล้ว +1

    Sir please my one error in list
    The default list constructor is not available
    When null safety is enabled

  • @JK92007
    @JK92007 5 ปีที่แล้ว +1

    Gr8...Nice...👍👍👍👍😊...Thanks bro.....

  • @Gurpreet-Chandi
    @Gurpreet-Chandi 2 ปีที่แล้ว

    the delete operation is not working as the error shows that can't remove from fixed length

  • @shivatiwari1127
    @shivatiwari1127 4 ปีที่แล้ว

    In numberslist(0),1 numberlist 2 is missing

  • @krishnakumarramachandran5888
    @krishnakumarramachandran5888 5 ปีที่แล้ว

    Super sir👍

  • @Wongmc644
    @Wongmc644 ปีที่แล้ว +4

    Great tutorial but this section on fixed length list and the growable list section is deprecated and not applicable anymore? I'm very new to dart so any errors & omission excepted :-). just sharing info...full source codes below:-
    new fixed length list:-
    // is to allow null values assignment
    List numbersList = List.filled(5, 0, growable: false);
    numbersList[0] = 73;
    numbersList[1] = 21;
    numbersList[2] = 64;
    numbersList[3] = 73;
    numbersList[4] = 12;
    numbersList[1] = null;
    print(numbersList); //console: [73, null, 64, 73, 12]
    // above list not iterable!!
    // to iterate then use below:-
    List numbersList2 = [1, 2, 3, 4, 5];

    for (int e in numbersList2) {
    print(e);
    }
    //using forEach
    numbersList.forEach((element)=> print('forEach : $element'));
    ======== full source========
    void main() {
    // fixed length
    //List numbersList = List(5); deprecated, use below for fixed length
    List numbersList = List.filled(5, 0, growable: false);
    numbersList[0] = 73;
    numbersList[1] = 21;
    numbersList[2] = 64;
    numbersList[3] = 73;
    numbersList[4] = 12;
    numbersList[1] = null;
    //myList.add('bbb'); can't use add because not growable
    print(numbersList);
    for (int i = 0; i < numbersList.length; i++) {
    print(numbersList[i]);
    }
    //for (int element in numbersList) {
    // print(element);
    //}
    List numbersList2 = [1, 2, 3, 4, 5];
    //growable
    for (int e in numbersList2) {
    print(e);
    }
    numbersList.forEach((element)=> print('forEach : $element'));
    }

  • @whitehawk4671
    @whitehawk4671 2 ปีที่แล้ว +1

    @Smartheard, sir i am getting error through your code which i copied from github and it is saying that:- The default 'List' constructor isn't available when null safety is enabled.
    I am using intellij idea, also i copy pasted the same code in dart pad too..... but still facing the same error again and again

    • @zeusking4468
      @zeusking4468 ปีที่แล้ว

      use this
      var nums = List.filled(5,0);

  • @muhammadyusoffjamaluddin
    @muhammadyusoffjamaluddin 4 ปีที่แล้ว +2

    The 'For Loop' give errors.
    cant print out the elements but giving errors.
    I am using VSCode with 'Runner' as my code runner, and it is giving error.
    already installed any Dart extensions and Flutter but why?

    • @_haptic_shorts
      @_haptic_shorts 4 ปีที่แล้ว

      Check it once on Online Dart compiler.

    • @whitehawk4671
      @whitehawk4671 2 ปีที่แล้ว

      @@_haptic_shorts still facing error , it saying that at line 4 The default 'List' constructor isn't available when null safety is enabled.

  • @amansarma417
    @amansarma417 5 ปีที่แล้ว +4

    Like any other language how to take input from the user in Dart

    • @nikhilchigali
      @nikhilchigali 5 ปีที่แล้ว +7

      You gotta import "dart:io" package for that,
      Then use
      stdin.readLineSync();

    • @jnralexander7913
      @jnralexander7913 ปีที่แล้ว

      @@nikhilchigali I did it but i still get nothin in the output console

  • @muhammadyusoffjamaluddin
    @muhammadyusoffjamaluddin 4 ปีที่แล้ว

    I got all of the print out errors!
    code error =254?
    but you get output?
    how can?

    • @_haptic_shorts
      @_haptic_shorts 4 ปีที่แล้ว

      R u using IntelliJ IDEA or online Dev compiler ??
      Are you used IntelliJ then reinstall the sdk and chocolate pack .
      If you are using online dart compiler, Then copy the code from GITHUB, the Check it once ..👏

    • @muhammadyusoffjamaluddin
      @muhammadyusoffjamaluddin 4 ปีที่แล้ว

      @@_haptic_shorts I use VSCode with 'Complete Flutter Extension Pack',
      at that time even using latest Dart packages.

    • @_haptic_shorts
      @_haptic_shorts 4 ปีที่แล้ว

      @@muhammadyusoffjamaluddin Bro once use Online Dart pad ,
      Or you can copy and paste the code from Github , Then try it once ..
      If the error is not fixed, Then try to reinstall.

    • @muhammadyusoffjamaluddin
      @muhammadyusoffjamaluddin 4 ปีที่แล้ว

      @@_haptic_shorts okay thank you, maybe I need to make some changes too on my local.

    • @_haptic_shorts
      @_haptic_shorts 4 ปีที่แล้ว +1

      @@muhammadyusoffjamaluddinit's my pleasure .

  • @nikhilcuiet
    @nikhilcuiet 2 ปีที่แล้ว

    it error in vs code ide

  • @yohanmallula3132
    @yohanmallula3132 3 ปีที่แล้ว +1

    Listnumber = List(5); errors plz any one help

    • @tirupathitex3422
      @tirupathitex3422 2 ปีที่แล้ว +1

      Same

    • @MuhammadAfzal-kt7zn
      @MuhammadAfzal-kt7zn 2 ปีที่แล้ว

      no more support to fixed length list, we can't create fixed length list through this approach

  • @MuhammadAfzal-kt7zn
    @MuhammadAfzal-kt7zn 2 ปีที่แล้ว

    No more support to the fixed-length list, we can't create fixed-length list like List list = List(5) it's deprecated now

  • @tech2ka1
    @tech2ka1 3 ปีที่แล้ว

    After = list(5);
    It's showing list keyword with cross

  • @reycoseguma2184
    @reycoseguma2184 2 ปีที่แล้ว

    ## FIXED LENGTH LIST
    List numberList = List.filled(3, 0);
    numberList[0] = 73;
    numberList[1] = 73;
    numberList[2] = 73;
    print(numberList);

    • @jnralexander7913
      @jnralexander7913 ปีที่แล้ว

      How about, accepting input from user in a console stage

  • @shamilyazeen4062
    @shamilyazeen4062 3 ปีที่แล้ว

    did anyone get an error while declaring fixed list ?

    • @AlamKhan-tg4mr
      @AlamKhan-tg4mr 3 ปีที่แล้ว +3

      Due to null safety its deprecated now, new way to define fixed length list
      var names = List.filled(10,0);
      // names.length == 10

  • @lordeloalvaro
    @lordeloalvaro 5 ปีที่แล้ว +1

    Bhai, where's your Flutter tutorial ?

    • @smartherd
      @smartherd  5 ปีที่แล้ว +2

      Go to my channel page. There you will find a Playlist on. Flutter

    • @jjss6717
      @jjss6717 9 หลายเดือนก่อน

      th-cam.com/play/PLlxmoA0rQ-Lw6tAs2fGFuXGP13-dWdKsB.html&si=VR3tZ8IF6pQImDi5