How to make Fluro defined route parameters OPTIONAL in flutter?
mhbdev opened this issue · comments
I have defined this route using Fluro. exchange/:pair
There is a problem! I want :pair
to be optional. If client types https://host:port/exchange/BNB_BTC
everything goes fine. but assume the user is looking for https://host:port/exchange
and he confronts with 404 error cause there is no such route/path
.
I mean something like exchange/{:pair}
.
@mhbdev, what happens if you just assign an empty map to the params parameter as a default (optional named parameter) in the Handler. If I'm thinking correctly, you could add that and then render the appropriate content by testing for an empty Map:
final myPageHandler = Handler(handlerFunc: (BuildContext context, {Map<String, List<String>> params = Map()}) {
return params.isEmpty?
? MyNoParamsContent()
: MyContentThatExpectsParams(params);
})
I think that may not work because of inconsistency with Hander's constructor. I'll be working on this question myself soon as I need the same functionality.