I want to parse arguments with Navigator.push() to my other dart file .
Because I want to send the path of the selected song in songlist,
to the music player main UI (For Playing)
child:ListView.builder(
itemCount: getSongList()[0].length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(getSongList()[1][index].split('/').last,style:
const TextStyle(
fontSize: 21
),),
leading: IconButton(onPressed: (){
Navigator.push(context,MaterialPageRoute(builder: (context) => music_player()));
},
icon: Icon(Icons.my_library_music)),
);
}
)
),
[ musicplayer.dart ]
class music_player extends StatefulWidget {
const music_player({Key? key}) : super(key: key);
@override
State<music_player> createState() => _music_playerState();
}
class _music_playerState extends State<music_player> {
// codes
}
Just wanna know how to parse arguments from my first file to second file.
If I pass arguments there will be an error :
too many positional arguments: 0 expected, but 1 found.
Thanks in advance.
2
Answers
you need to add parameter(selectedSongs) in widget like this:
this way you can use in Navigator.push:
If your want to pass arguments with Navigator the correct way is:
-Register the widget in the routes:
-Navigate to the widget:
And inside your next page widget:
All information here: https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments