diegoveloper / flutter_percent_indicator

Flutter percent indicator library
BSD 2-Clause "Simplified" License
677 stars 206 forks source link

Cannot get size from a render object that has not been through layout. #213

Open kangtian opened 2 months ago

kangtian commented 2 months ago

════════ Exception caught by scheduler library ═════════════════════════════════ The following assertion was thrown during a scheduler callback: Cannot get size from a render object that has not been through layout. 2

The size of this render object has not yet been determined because this render object has not yet been through layout, which typically means that the size getter was called too early in the pipeline (e.g., during the build phase) before the framework has determined the size and position of the render objects during layout.

The size getter was called for the following element: CustomPaint-[GlobalKey#c3fdf] renderObject: RenderCustomPaint#fe468 NEEDS-LAYOUT NEEDS-PAINT The render object from which the size was to be obtained was: RenderCustomPaint#fe468 NEEDS-LAYOUT NEEDS-PAINT When the exception was thrown, this was the stack

    Container(
                              decoration: BoxDecoration(
                                  color: Colors.white10,
                                  borderRadius: BorderRadius.circular(3)),
                              width: screenAdapter.getscreenWidth() -
                                  screenAdapter.width(200),
                              height: screenAdapter.height(120),
                              child: Stack(
                                children: [
                                  Positioned(
                                      top: screenAdapter.height(20),
                                      child: LinearPercentIndicator(
                                        width:
                                            screenAdapter.getscreenWidth() -
                                                screenAdapter.width(220),
                                        lineHeight: screenAdapter.width(20),
                                        barRadius: const Radius.circular(4),
                                        percent: ranks.value!,
                                        linearGradient: GradientColor()
                                            .gradientColorsgrren,
                                        backgroundColor:
                                            const Color.fromARGB(
                                                99, 167, 181, 191),
                                      )),
                                  Positioned(
                                      left: (screenAdapter
                                                  .getscreenWidth() -
                                              screenAdapter.width(400)) *
                                          ranks.value,
                                      bottom: screenAdapter.height(15),
                                      child: Text(
                                        '${ranks.rate}',
                                        style: TextStyle(
                                            color: AppColors.subtitleColor,
                                            fontSize:
                                                screenAdapter.fontsize(42)),
                                        textScaleFactor: 1,
                                      ))
                                ],
                              ),
                            )
kangtian commented 2 months ago

I don't know why an error occurred