首页 > 解决方案 > How do i get a loading screen while i fetch images from api?

问题描述

I want a loading screen when i shake screen and 10 more images loads from api.

 void initState() {
    super.initState();
    _shakePlugin = FlutterShakePlugin(
      onPhoneShaken: (){
        //do stuff on phone shake
        setState(() {
          
          count=count+10;
           
           
        });
      },
    )..startListening();
  }

Future<String> getjsondata() async {
    try {
      
      var response = await http.get(
          'https://api.unsplash.com/search/photos?per_page=${count}&client_id=TcAQEO3JoMG90U7Rl-YUiDo1x9XbZukzMOMQhxUVCV4&query=${_search}');
      setState(() {
        var converted = json.decode(response.body);
        data = converted['results'];
      });
      
    } catch (e) {}
    return 'success';
  }

Whenever i increment the count by 10,i need a loading widget to show until it fetches the images from api.

标签: flutterdartloading

解决方案


Use FutureBuilder to handle the different snapshot conditions and connection states to show different widgets


推荐阅读