Search code examples
flutterflutter-dependencies

Flutter: Incorrect use of ParentDataWidget with animate_do package


This is the package: https://pub.dev/packages/animate_do

My widget works ok without the SlideInUp() widget, otherwise I get the error:

Stack( children:[SlideInUp(
      manualTrigger: true,
      from: -200,
      controller: (controller) => playersScoreController = controller,
      child: Positioned(
        bottom: 0,
        right: 0,
        left: 0,
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
          color: Helpers().colors['text'],
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text.rich(
                    TextSpan(
                      children: [
                        const TextSpan(
                            text: 'Score: ',
                            style: TextStyle(color: Colors.white)),
                        TextSpan(
                            text: '3',
                            style: TextStyle(color: playersColors[0])),
                        const TextSpan(
                            text: ' - ', style: TextStyle(color: Colors.white)),
                        TextSpan(
                            text: '5',
                            style: TextStyle(color: playersColors[1])),
                      ],
                    ),
                  ),
                  Row(
                    children: [
                      const Image(
                        image: AssetImage('assets/images/medal.png'),
                        height: 20,
                      ),
                      Text(
                        ' 5:566',
                        style: TextStyle(color: playersColors[1]),
                      ),
                    ],
                  ),
                ],
              ),
              playAgainButtonWidget(true),
            ],
          ),
        ),
          ),
],
        );

Solution

  • This is about incorrect usage of "Positioned" widget. Docs says "A Positioned widget must be a descendant of a Stack". So Problem is not about animate_do package.

    Simply, you CANNOT use positioned witget like this;

    Stack(
      children: [
        SlideInUp(
          manualTrigger: true,
          from: -200,
          controller: (controller) => playersScoreController = controller,
          child: Positioned( // this will produce error because it's under SlideInUp widget, not under Stack widget
            bottom: 0,
            right: 0,
            left: 0,
            .
            .
            .