'How to rebuild widget or recall query from another class in flutter?

i have a class in which i build the main screen of the app. In there i just put titles and classes. But now i want to create a refresh button. So if the user changes a filter i want to rebuild all classes and get the updated queries with the filter. How can this be done? It would be nice to trigger the refresh with the typically "drag down" refresh indicator.

class home_screen extends StatefulWidget {
  @override
  home_screenState createState() => home_screenState();
}

class home_screenState extends State<home_screen> {

  @override
  Widget build(BuildContext context) { 
    return Scaffold(
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [

            //Alle ansehen
            Padding(
              padding: const EdgeInsets.fromLTRB(15,15,15,0),
              child: Row(
                children: [
                  const Text("Alle ansehen", style: TextStyle(fontSize: 22,fontWeight: FontWeight.bold),),
                  TextButton(onPressed: (){
                    Navigator.push(context, MaterialPageRoute(builder: (context) => const CategoryPage(title: "Alle Unternehmen", categorie: "all")));
                  }, child: const Icon(Icons.chevron_right_outlined, color: Colors.black26,)),
                ],
              ),
            ),
            const CompanyCard(categorie: "all", title: "Alle ansehen"),
 
          ],
        ),
      ),
    );
  } 
}

My query class looks like this:

  Stream<List<DocumentSnapshot<Object?>>> stream = Geoflutterfire().collection(collectionRef: FirebaseFirestore.instance.collection('companies')).within(center: userloc, radius: posradius, field: 'geoPosition', strictMode: true);


class CompanyCard extends StatefulWidget {
  final categorie;
  final title;

  const CompanyCard({ Key? key, required this.categorie, required this.title,}) : super(key: key);
  @override
  _CompanyCardState createState() => _CompanyCardState();
}

class _CompanyCardState extends State<CompanyCard> {

  @override
  Widget build(BuildContext context) {
 return Column(
   children: [
     StreamBuilder(
       stream: stream, 
          builder: (BuildContext context, AsyncSnapshot<List<DocumentSnapshot>> snapshot) {
            if(!snapshot.hasData){
              return const SizedBox(
                height: 220,
                child: Center(
                  child: CircularProgressIndicator()));
            }
            else {
              return SizedBox(
                height: 220,
                child: ListView(
                  scrollDirection: Axis.horizontal,
                  children: [
                    ...snapshot.data!
                        .map((DocumentSnapshot<Object?> data){

                          final String name = data.get("name");
                          final String phone = data.get("phone");
                          final GeoPoint coord = data.get("geoPosition")["geopoint"];
                          double distance = userloc.distance(lat: coord.latitude, lng: coord.longitude);

//Here i build the Cards

                        }
                        ),
                        GestureDetector(
                          onTap: (){ Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryPage(title: widget.title, categorie: widget.categorie)));},
                          child: Container(
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                            color: Colors.black.withOpacity(0.03),
                            borderRadius: BorderRadius.circular(15.0),
                            ),
                            margin: const EdgeInsets.fromLTRB(10, 10, 20, 10),
                            height: 120,
                            width: 100,
                            child: const Text("Alle\n anzeigen", textAlign: TextAlign.center, style: TextStyle(color: Colors.black26, fontWeight: FontWeight.bold),)),
                        ),                        
                  ],
                ),
              );
            }
          }
        ),
      ],
    );
  }
}
´´´


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source