How to use http query paramter at flutter router
// // use http query paramter at flutter rpouter // import 'package:flutter/material.dart'; main() { runApp(MaterialApp( onGenerateRoute: (RouteSettings settings) { var _uri = Uri.parse(settings.name); String path = _uri.path; Map<String,String> params = _uri.queryParameters; if(path.startsWith("/image")) { return MaterialPageRoute( settings: RouteSettings( name:"/image?uuid=${params['uuid']}" ), builder: (context) { return ImagePage(params["uuid"]); }, ); } else { return null; } }, routes: { "/home" :(context)=> HomePage() } , initialRoute: "/home", )); } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Center(child: RaisedButton( child: Text("move to /image?uuid=xxxx"), onPressed: () { Navigator.pushNamed(context, "/image?uuid=xxxx"); },), )); } } class ImagePage extends StatelessWidget{ String imageName; ImagePage(this.imageName){} @override Widget build(BuildContext context) { return Scaffold( body: Center(child: Text("${imageName}"),), ); } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How to use http query paramter at flutter router