rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

how to change color of shape object

Open rdcoder33 opened this issue 3 years ago • 0 comments

Hey, I am trying to change the color of a component called "body" in a rive asset but it's not reflecting.

// code to change color:
           
ElevatedButton(
                onPressed: () {
                  _riveArtboard!.forEachComponent((child) {
                    if (child.name == 'body') {
                      debugPrint("Body found");
                      if (child is Shape) {
                        debugPrint("it's a shape");
                        final Shape shape = child;
                        setState(() {
                          shape.fills.first.paint.color = Colors.yellow;
                        });
                        
                       
                      }
                    }
                  });
                },
                child: const Text('Change Color')),
// rive widget:
Container(
                  width: 400,
                  height: 400,
                  color: Colors.green,
                  child:
                       const RiveAnimation.asset(
                    'assets/casual_character.riv',
                     animations: ['hi'],
                    fit: BoxFit.contain,

                    antialiasing: true,
                  ),
                ),

I do get print outputs: "body found", "it's a shape" but the color didn't change

casual_character.riv.zip

rdcoder33 avatar Mar 05 '22 16:03 rdcoder33