Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to call a function when launching an application

I need to call a function when the application starts. I call it from the Main file, the function itself is in another file. I tried to do this, but there are no expected changes and the function in another file is highlighted with the warning

Null numberColumnFunction() The declaration ‘numberColumnFunction’
isn’t referenced. Try removing the declaration of
‘numberColumnFunction’.

What ‘s wrong with my call ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My Main:

void main() async{
 await ColumnView.numberColumnFunction();
  runApp(const MyApp());
}

My fuction in class ColumnView:

 @override
  Widget build(BuildContext context) {

    int numberColumn = 3;
    int columnsPositioned = 5;
    var visibilityColumn = false;

    numberColumnFunction(){
      if (numberColumn == 3) {
        columnsPositioned = 8;
        visibilityColumn = true;
      }
      else {
        () {
          null;
      };
      }
    }
}

>Solution :

Make a regular class like this and not use StatelessWidget or StatefulWidget class for calling only functions.

class ColumnView {
 int numberColumn = 3;
  int columnsPositioned = 5;
  var visibilityColumn = false;

  numberColumnFunction(){
  if (numberColumn == 3) {
    columnsPositioned = 8;
    visibilityColumn = true;
  }
  else {
    () {
      null;
    };
   }
  }
}

then call like that…

void main() async{
await ColumnView().numberColumnFunction();
runApp(const MyApp());
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading