0

Example i have three dart class. main.dart, firstdata.dart, and seconddata.dart.

then in firstdata.dart and seconddata.dart i have list/array data

firstdata.dart:

class firstdata{
 static logo = [ assets/pic1.png, assets/pic2.png];
 static name = [ 'dani', 'lict'];}

seconddata.dart:

class seconddata{
 static logo = [ 'assets/image1.png', 'assets/image2.png'];
 static name = [ 'rose', 'fanny'];}

Question: How can i call/access array/list value from firstdata.dart and seconddata.dart to main.dart?

2 Answers 2

2
//Custom class in project directory
class FirstData {
 FirstData._();
 static logo = [ assets/pic1.png, assets/pic2.png];
 static name = [ 'dani', 'lict'];
}

class SecondData {
 SecondData._();
 static logo = [ assets/image1.png, assets/image2.png];
 static name = [ 'rose', 'fanny'];
}

And Now Call Like this any class like:

class MainClass {
 // From Class Second
 FirstData.logo;
 FirstData.name;

 // From Class Second
 SecondData.logo;
 SecondData.name;
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can directly access all the static variable using class name only.

void main() {
    print(Firstdata.logo);
}

class Firstdata{
 static var logo = ['logo'];
 static var name = [ 'dani', 'lict'];}

class Seconddata{
 static var logo = [ 'assets/image1.png, assets/image2.png'];
 static var name = [ 'rose', 'fanny'];}

2 Comments

Accept the answer if you found useful @SDi
what if Firstdata class is Stateful?

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.