spreadRadius value as parameter in flutter

I am making a global boxShadow list that I want to use in the whole app.
I am trying to pass spreadRadius value(i.e. 5 in the code below) as a parameter to make it dynamic in my custom list of BoxShadow.

Here is the code:

List<BoxShadow> outerShadow = [
  BoxShadow(
    color: Colors.grey.withOpacity(0.4),
    spreadRadius: 5,
    blurRadius: 7,
    offset: const Offset(0, 3),
  )
];

>Solution :

You need to create a method if you wish to pass some data as a parameter.

List<BoxShadow> outerShadow(double spreadRadiusVal){
return [
  BoxShadow(
    color: Colors.grey.withOpacity(0.4),
    spreadRadius: spreadRadiusVal,
    blurRadius: 7,
    offset: const Offset(0, 3),
  )
];
}

And use it like

boxShadow : outerShadow(5.0),

Leave a Reply