how to run function inside the classdart code example

Example 1: how to run function inside the classdart

class ShowingAnimalList extends StatelessWidget {
     final Animals ani= new Animals();
     @override
     Widget build(BuildContext context) {
       return GestureDetector(
         onTap: ani.animalListPrinter(),
       );
  }
}

Example 2: how to run function inside the classdart

class Animals
{
  var animalList = ['dog','cat','cow'];

  // function for printing the list of animals

  void animalListPrinter(){
    for(var animal in animalList){
        print(animal);

     }
  }
}

Tags:

Misc Example