Flutter '{1} positional argument(s) expected, but {0} found

138 Views Asked by At

I tried to make circleImage Widget and use it. but when it's used, it makes error that needs argument. What argument needs in that position?




 @override
 Widget build(BuildContext context) {
   return MaterialApp(
       home: Scaffold(
     appBar: AppBar(
       leading: Text('eyes'),
       actions: <Widget>[
           **CircleImage();**
       ],
     ),  
       ],

     ),
   )
   );
 }
}

// making CircleImage

class CircleImage extends StatelessWidget {
 CircleImage(
     this.imageProvider,  {
       this.radius = 10,
     }
     );

 final double radius;
 final ImageProvider imageProvider;


 @override
 Widget build(BuildContext context) {
   return Column(
     mainAxisAlignment: MainAxisAlignment.center,
     children: <Widget>[
       CircleAvatar(
         radius: radius,
         backgroundImage: imageProvider,
       )
     ],
   );
 }
}

It appers in AppBar's widget. That makes error. Could I workaround that?

1

There are 1 best solutions below

0
Gowtham K K On

You need to pass image provider to CircleImage widget.

For example if you have image in assets,

actions: <Widget>[
    CircleImage(AssetImage('assets/image_name.png')),
]

Else if you have image url,you can do something like this.

actions: <Widget>[
    CircleImage(NetworkImage("https:/somedomain.com/a.png")) //Your image url
]