Home > Blockchain >  Flutter : Youtube search autoComplete Json
Flutter : Youtube search autoComplete Json

Time:05-01

Hi everyone i work to You-tube app with flutter everything is good . but how can i get json data from auto Complete from this url http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&q=QUERY and save data to list to display in app

anyone have idea ?

CodePudding user response:

I solved the problem and work for me :)

Function :

  List<dynamic> ? autoComplete ;
  bool isntNull= false;

  Future<void> autoCompleteSuggestions(String text) async {
    var getSuggestions = await http.get(Uri.parse('http://suggestqueries.google.com/complete/search?client=youtube&ds=yt&client=firefox&q=$text'));
    final extractedData = json.decode(getSuggestions.body) as List<dynamic>;
    setState(() {
      autoComplete = extractedData;
      if(autoComplete!=null)
        isntNull= true;
    });
  }

ListView builder :

isntNull ? Expanded(
 child: ListView.builder(
  itemCount: autoComplete![1].length,
  itemBuilder: (context , index){
   return Text(autoComplete![1][index].toString());
  },
 ),
) : Text('Null')
  • Related