Created
August 30, 2021 13:33
-
-
Save md-weber/b5565b63064dd344107ecfce124f824b to your computer and use it in GitHub Desktop.
How to create a new List out of two Lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
List<DensityVolume> listDensity = [DensityVolume(2.3, 3.2), DensityVolume(4.2, 2.4)]; | |
List<HeightLengthWidth> listHeight = [HeightLengthWidth(1, 1, 1), HeightLengthWidth(2, 2, 2)]; | |
List<Cube> result = []; | |
for (var i = 0; i < listDensity.length; i++) { | |
final densityElement = listDensity[i]; | |
final heightElement = listHeight[i]; | |
result.add(Cube( | |
densityElement.density, | |
densityElement.volume, | |
heightElement.length, | |
heightElement.height, | |
heightElement.width, | |
)); | |
} | |
print(result); | |
} | |
class Cube { | |
final double density; | |
final double volume; | |
final int length; | |
final int height; | |
final int width; | |
Cube(this.density, this.volume, this.length, this.height, this.width); | |
} | |
class DensityVolume { | |
final double density; | |
final double volume; | |
DensityVolume(this.density, this.volume); | |
} | |
class HeightLengthWidth { | |
final int length; | |
final int height; | |
final int width; | |
HeightLengthWidth(this.length, this.height, this.width); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment