fluro icon indicating copy to clipboard operation
fluro copied to clipboard

How to make Fluro defined route parameters OPTIONAL in flutter?

Open mhbdev opened this issue 4 years ago • 1 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 avatar Apr 08 '21 12:04 mhbdev

@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.

willhaslett avatar Apr 13 '21 15:04 willhaslett