data doesn't load instantly in drawer even though it's in same widget

Viewed 90

So in my view I am fetching data whenever it inits.

  @override
  void initState()  {
    super.initState();
    context.read<UseAuth>().fetchUserInfo();
  }

After I display data in my app like context.watch<UseAuth>().getNick then it's all fine, however I have a drawer here as well and in that drawer I display context.watch<UseAuth>().getAvatar. The drawer is in same widget.

But when I open the drawer, I don't see the avatar for like a 1-2 seconds. I am not sure why this is happening?

Both are getters in my provider file, nick load instantly.

 String? get getNick => _userData?.nick;
 String? get getAvatar => _userData?.avatar_url;

I am using this in the drawer child: Image.network('${context.watch<UseAuth>().getAvatar}'),. Should the image not be loaded already because drawer is in same Widget? Can this be happening because the Image.network?

Can I force this Image.network to load whenever the widget is loaded b efore opening the drawer?

1 Answers

I am not sure you can load you image before accessing drawer, but you can use a package like https://pub.dev/packages/cached_network_image and have a placeholder for until the image is loaded. And also after first time loading, while the program will be running, the image will be cached.

Related