Home > Mobile >  Error: The argument type 'IconData' can't be assigned to the parameter type 'Wid
Error: The argument type 'IconData' can't be assigned to the parameter type 'Wid

Time:01-02

I was learning from another project and when I tried to implement it I have the following errors:

Error: The argument type 'IconData' can't be assigned to the parameter type 'Widget'.

Any help?

My code is the following:

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: kBackground,
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            expandedHeight: 150,
            elevation: 0,
            pinned: true,
            stretch: true,
            toolbarHeight: 80,
            backgroundColor: Colors.white,
            leading: IconButton(
              onPressed: (){
                Navigator.pushNamed(context, '/signUp');

              },
              icon: Icons.person_outline,
            ),
          ),
        ],
      ),
    );
  }
}

CodePudding user response:

icon: Icons.person_outline,

Here Icons.person_outline is Type IconData

You need to use that in the Icon Widget.

icon: const Icon(Icons.person_outline),

CodePudding user response:

the right way is :

icon: Icon(Icons.person_outline)
  • Related