title: How to call api on change of dropdown value in flutter?
body: <p>In my flutter app i have two Dropdown buttons first is select subjet and second one is select lecture no.If i select subject and lecture no then call api studentList and show student list in list view.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    class SubjectWiseAttendance extends StatefulWidget {
      final imei_no,school_code,employee_id;
        SubjectWiseAttendance({Key key, this.imei_no, this.school_code, this.employee_id})
            : super(key: key);
        @override
        _SubjectWiseAttendanceState createState() =&gt; _SubjectWiseAttendanceState();
      }
      class _SubjectWiseAttendanceState extends State&lt;SubjectWiseAttendance&gt; {
        String date =DateFormat("dd-MM-yyyy").format(DateTime.now());
        String holder='9';
        String get imei_no =&gt; '0';
        String get school_code =&gt; 'STAGING';
        String get employee_id =&gt; 'EMP450';
        String get class_id=&gt;holder;
        String get subject_id=&gt;'0';
        String get attendance_date=&gt;date;
        String get standard_id=&gt;'0';
        String get attendance_type=&gt;'S';
        String get hr_id=&gt;'0';
        String get batch_id=&gt;'0';
        String get sort_by_lect_no=&gt;'0';
        String get Absent_Enroll_No =&gt;new_str;
        String get proxy_flag =&gt;'N';
        String get proxy_reason =&gt;" ";
        String get late_flag=&gt;'N';
        String get homeroom_id=&gt;'0';
        String get lecture_id =&gt;'0';
        List&lt;dynamic&gt; filteredItems;
        List&lt;dynamic&gt; filteredItemsType;
        String _selectedLocation;
        Future api1;
        var result ;
        var msg;
        var validate;
        var validate1;
        var api2;
        var array;
        @override
        void initState() {
          print('initState');
          _selectedLocation;
         _lectures;
         api1=_fetchClassdivision(imei_no, school_code, employee_id);
         api2=_fetchStudentlist(imei_no, school_code, employee_id, class_id, subject_id, attendance_date, standard_id, attendance_type, hr_id, batch_id, sort_by_lect_no);
          super.initState();
        }
        @override
        void dispose() {
          super.dispose();
        }
        _fetchClassdivision(
            String imei_no, String school_code, String employee_id) async {
          var apiUrl ='https://staging.ethdigitalcampus.com/T-View/service/DC/getClassDivisionSubjectwise' ;
          List&lt;ClassDivisionSubject&gt; list;
          Map&lt;String, String&gt; headers = {
  
            'content-type': 'application/x-www-form-urlencoded'
          };
          print('api1');
          Map&lt;String, String&gt; body = {
            'imei_no': imei_no,
            'school_code': school_code,
            'employee_id': employee_id,
          };
          http.Response response =
          await http.post(apiUrl, body: body, headers: headers);
          var data = json.decode(response.body);
          return data ;
         } 
  
        **List _buildFilteredList(List&lt;dynamic&gt; data) {
          List filteredItems = [];
          for(int j=0;j&lt;data.length;j++)
          {
          String subject = data[j]['class_desc']+"--"+ data[j]['subject_desc'];
          filteredItems.add(subject.toString());
          }
          return filteredItems;
        }**
       _fetchStudentlist(...)
        Widget listViewWidget(data) {...
         }
      final GlobalKey&lt;FormState&gt; _formKey = new GlobalKey&lt;FormState&gt;();
       @override
        Widget build(BuildContext context) {
         body: new SafeArea(
                top: false,
                bottom: false,
                child: new Form(
                    key: _formKey,
                    autovalidate: true,
                    child: new ListView(
                     children: &lt;Widget&gt;[
                     Container(
                          child:FutureBuilder(
                              future:api1,
                              builder: (BuildContext context,snapshot) {
                                print('class division');
                                if (snapshot.data == null) {
                                  return Column(children: &lt;Widget&gt;[
                                    Container(
                                        child: Center(
                                          child:  CircularProgressIndicator()
                                        ))
                                  ]);
                                } else {
                                  if(result =='0') {
                                    filteredItems = _buildFilteredList(array);
                                    if (filteredItems.length &gt; 0) {
                                      if(_flag == true){
                                        _selectedLocation = filteredItems[0];
                                      }
                                       return Column(children: &lt;Widget&gt;[
                                        Divider(),
                                        DropdownButton(
                                         isExpanded: true,
                                          isDense: true,
                                          value: _selectedLocation,
                                          onChanged: (newValue) {
                                            setState(() {
                                              _flag = false;
                                              _selectedLocation = newValue
                                           });
                                          },
                                          items: filteredItems.map((subject) {
                                            return DropdownMenuItem(
                                              child: new Text(subject),
                                              value: subject,
                                            );
                                          }).toList(),
                                        ),
                                      ]
                                      );
                                    }
                                  } }}),
                        ),
                         child: FutureBuilder(
                              future: api2,
                              builder: (context, snapshot) {
                                print('check student list');
                                if (snapshot.hasError) print(snapshot.error);
                                return snapshot.data != null
                                    ? listViewWidget(snapshot.data)
                                    : Center(child: CircularProgressIndicator());
                              }),
                        ),
  
                      ],
                    )
                )
            ),
   }
  </code></pre>
  
  <p>Output:</p>
  
  <p><img src="https://i.stack.imgur.com/hL9UK.png" alt="Output"></p>
  
  <p>If change dropdown value then how to change studentList according dropdown value.</p>