define user based value to the firebase instance collection

Viewed 35

I have two pages FirstPage and SecondPage. I am passing the argument or value from FirstPage to SecondPage. Is it possible in the SecondPage to get the value adjusted in the ("${widget.col}") ? I tried this way but could not get that value.

FirstPage

onTap : {

  Navigator.push(context,MaterialPageRoute(builder: (context) => SecondPage(gen: 'collection')));}

SecondPage



    class SongProvider extends ChangeNotifier { 
    late final String col;
 SongProvider({required this.col}); 
final _worshipColleciton = FirebaseFirestore.instance.collection("$col");
1 Answers

To pass data you can do

Navigator.push(context,MaterialPageRoute(builder: (context) => SecondPage(collectionName:'collection')));}

Then in screen 2

class SecondScreen extends StatelessWidget {

  final String collectionName;

  SecondScreen({Key key, required this.collectionName}) : super(key: key);
}

If you notice collection name is the string required by screen 2 and that's being passed from screen 1

Related