Reagan
Reagan

Reputation: 131

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

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,
            ),
          ),
        ],
      ),
    );
  }
}

Upvotes: 6

Views: 18006

Answers (2)

Navid Shokoufeh
Navid Shokoufeh

Reputation: 569

the right way is :

icon: Icon(Icons.person_outline)

Upvotes: 1

Nirmal Code
Nirmal Code

Reputation: 4058

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),

Upvotes: 18

Related Questions