Home > Software design >  Flutter- Wrap widget takes a long time to display children contained in a for loop
Flutter- Wrap widget takes a long time to display children contained in a for loop

Time:04-21

Wrap widget takes a long time to display these children contained in a for loop, Is there a solution to reduce this waiting time?

SingleChildScrollView(
  padding: EdgeInsets.only(left: 10, right: 10),
  child: Wrap(
      direction: Axis.horizontal,
      children: [
          for (int i = 0; i < state.items.length; i  )
            Expanded(
              child: InkWell(
                onTap: () {},
                child: Container(
                  width: (MediaQuery.of(context).size.width - 40) / 3,
                  decoration: BoxDecoration(
                    color: Colors.white,
                  ),
                  child: Column(
                      children: [
                        FadeInImage.assetNetwork(
                                fit: BoxFit.fill,
                                placeholder: 'assets/loading.gif',
                                image: state.items[i].image)),
                        .....
                      

CodePudding user response:

try to display shimmer or circular loading than show assetNetwork. after image/data loaded, show the the real widget.

CodePudding user response:

use List.generate instead of for loop.

  • Related