Ali
Ali

Reputation: 186

How to attach a "determinate" progress indicator to a network call in flutter

I want to show a determinate progress indicator to my api network call.

I have seen other solutions where they hardcode the time like 2 seconds. But, i need the progress indicator to start when the call is made and finish at 100% when we have got the response. As you may know that time can vary.

  @override
  void initState() {
    super.initState();
    bloc.fetchAllBusiness();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
        stream: bloc.allBusinesses,
        builder: (context, AsyncSnapshot<List<BusinessModel>> snapshot) 
        {
          if (snapshot.hasData) {
            return buildList(snapshot);
          } else if (snapshot.hasError) {
            //error handling
          }
          //This is where i need show a determinate indicator
          return Center(child: LinearProgressIndicator(value:"???"));
        }

I need to know, how to set the double here "???" which increases overtime and reaches 1.0 when the network call get its response.

Upvotes: 1

Views: 258

Answers (0)

Related Questions