0

Edit:

class Transactions {
  final String id;

  final double amount;
  final String date;
  

  const Transactions({
    @required this.id,
    @required this.amount,
    @required this.date,
   
  });}

I am trying to ad a transaction to the current month . When the user adds a transaction based on the current moth is I would like to add that transaction to the array,e

so I want to make a list of list of Transactions

this is what i have tried :

  List<List> _userTransactions = [
            List<Transactions> jan= [];
            List<Transactions> feb= [];
            List<Transactions> mar= [];
            List<Transactions> apr= [];
            List<Transactions> may= [];
            .....
            ];
1
  • the currect title is language Dart no Flutter... Commented Sep 3, 2020 at 12:41

3 Answers 3

1

Edit:

already answered

you might want try this one:

final grid = List<List<int>>.generate(
      size, (i) => List<int>.generate(size, (j) => i * size + j));
Sign up to request clarification or add additional context in comments.

Comments

0

If all you want is to initialize a list of hard-coded integers, you can do:

var list = [
    [1, 2, 3],
    [4, 5, 6]
  ];

You can specify the type instead of var if you want, it is List<List<int>>.

Or, if you want to generate a grid, you can either use a for loop with the add function, or use generate as per mra9776's answer.

2 Comments

how would add to the the variable list if it is a dynamic list and there is no hard coded values
@Chad For this mra9776's answer can help. Or use for loops. So initially, declare an empty list: List<List<int>> list = [];, and then inside your loop you can use list.add(....).
0

Here we have a class with name as Transactions So to make the list of Transactions objects we have to create list which is of type Transactions In the below code part we created a List of type Transactions and added objects to them by creating them with the help of new variable

List<Transactions> _userTransactions = [
        new Transactions(100, 5000, "4-10-2020"),
        new Transactions(101, 5000, "4-11-2020")
        
        ];

for more information about creation of objects and adding them to the List

please click the link https://kodeazy.com/flutter-array-userdefined-class-objects/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.