Flutter_svg: Problem when using for BottomNavigationBar icon

Created on 16 Jul 2019  路  3Comments  路  Source: dnfield/flutter_svg

Hello there!

I'm having a problem when trying to use an instance of SvgPicture.asset as the Icon parameter of the BottomNavigationBarItem widget.

Here is the code:

  Widget dumbbellIcon =
      SvgPicture.asset('assets/icons/Dumbbell.svg');

Widget build(BuildContext context) {
    return Scaffold(
      ...,
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: dumbbellIcon,
          ),
        ],
      ),
    );
  }

The errors are:

Invalid constant value.dart(invalid_constant)
The values in a const list literal must be constants.
Try removing the keyword 'const' from the list literal.dart(non_constant_list_element)

I just can't get it to work!

Thank you very much for your work (:

Most helpful comment

Ahh in that case you have to take const off the list of bottomnavigwtionbaritems

All 3 comments

Try const Widget dumbbellIcon =

Thank you for such a quick answer Dan!

I tried it already :/

It throws this:

The constructor being called isn't a const constructor.
Try using 'new' to call the constructor.dart(const_with_non_const)
Const variables must be initialized with a constant value.
Try changing the initializer to be a constant expression.

Ahh in that case you have to take const off the list of bottomnavigwtionbaritems

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChristianKleineidam picture ChristianKleineidam  路  5Comments

zjiekai picture zjiekai  路  6Comments

coupestartup picture coupestartup  路  6Comments

joaorpalma picture joaorpalma  路  4Comments

Eddydpyl picture Eddydpyl  路  6Comments