How do you use a Custom Transition when using the Navigator's PushNamed function in Flutter? - flutter-animation

I have created named routes and now a custom route transition class which extends PageRouteBuilder. I would like to use the custom transition when I change routes using the pushNamed function of the Navigator object but I am unsure of how to do this as all examples I see use the push function which takes the route object instead of the route name.
What do I need to do to use custom transitions with the pushNamed routes function?

Related

rails admin, create a button that runs custom code

in my rails app I need to generate a bunch of buttons/links linked to several models to enable users to run some maintenance tasks (coded in the Backend).
I found the concept of actions in rails admin here: https://github.com/sferik/rails_admin/wiki/Actions, but I'm not quite clear how to use it, any ideas?
I thought I could add the buttons to the edit action for a model, but no ideas how to.
Sooo, rails uses an MVC paradigm. It sounds like you have the View and Model components under control, but you are missing your Controller logic. The Controller, is a place that handles any View logic using Model methods... ideally.
So, if you already have an existing controller that you are trying to add "Controller Actions" to... you need to define your custom method actions you want to create in your config/routes.rb file.
This will look like the following:
Create a route for your new controller action.
Add new controller action definition to your Controller.
Call controller action in your view's button link_to tag helper
Handle your custom logic in your new controller action using model methods
This is the cyclical MVC nature of Rails. M (Model), V (View), C (Controller).

Grails Custom Scaffolding get access to controller name

I am trying to write a custom src/templates/scaffolding/Controller.groovy and was wondering if there was any way to get access to the controller name? Right now it seems like you can only get the "model" class. The reason I need it is I am customizing the render to prefix the templates directory based on the controller.
For instance I have a controller named AuthorAdminController and I need to customize the list to use the /admin/user/** directory.
Let me know if you have any questions. I am getting ready to look into how to customize DefaultGrailsTemplateGenerator but I am not sure if that is the correct route to go.
Example:
class UserAdminController {
static scaffold = User
}
Currently in my Controller.groovy I get className='user' so I have no access to the controller.
I don't think you can, as the way scaffolding works your template will always be generating a class named DomainClassNameController (i.e. UserController in your example), which gets loaded into a new classloader and then the metaclass of the real controller (UserAdminController) gets new actions added to it which delegate to an instance of the generated UserController.
Now every controller has access to the controllerName property during execution of actions, so this may provide you with a workaround. I haven't tried it, but you could try putting a log.info("controller: \${controllerName}") into the template and see which name it gives you (the backslash to make it resolve at runtime rather than generation time).

adding Route name in routes.insert function MVC

Hi I am creating a RouteBase object and try to insert in routes collection using route.insert
routes.Insert(0, objRoute);method. How can i assign a name to the route in this scenrio??
like routes.add("myfavroute", localizedRoute); method
Info: I have to use the routes.Insert method as i have to ad the route at the top of the collection
I am afraid that you cannot provide a name if you use the Insert method to add the route. You will have to call the Add method before any other route registrations if you want this named route to be the first one.

Get route name from inside view?

Using Attribute Routing you can define a route name. Is there a way I can get the name of the used route from inside my view?
According to this answer, you can use:
#{ var x = ViewContext.RouteData.Values["Action"]; }
to get route data. Then according to the right answer of this post: "How to get a custom attribute from object instance in C#", you can pull out the attributes.
This doesn't sound like a real good idea. You should probably add the route name to view data or the view model instead.
MapMvcAttributeRoutes has multiple overloads which expects a parameter for IDirectRouteProvider implementation. This interface is responsible for generating routes. The default implementation for this interface is DefaultDirectRouteProvider. Create a custom class that inherits from DefaultDirectRouteProvider and override required methods like GetActionDirectRoutes or GetControllerDirectRoutes. In this method you will get RouteEntry which contains the route name. You can add this name to datatokens.

Create a Route Constraint that only applies a route when the action has a particular action filter

I have a list of actions on various controllers that are 'Admin' functions (create, update, delete) but other actions on those same controllers that aren't admin actions.
What I want to do is create a route that will prefix /Admin/ before all urls that call an action that have the Authorize filter attribute.
Is this even possible to do?
Yes everything is possible, but I think what you mean to say is it easy to do? And the answer is no. What you have to do is create your own route, and then add this customized route to the route mapping. This isn't hard to do, but the problem arises in that the routes are initialized before the controller, so you will have to handle the lookup and reflection yourself to check for your criteria.
There is an alternative option, you can try to use the ActionMethodSelectorAttribute which allows you to create custom selectors for your Action Methods and ignore ones that don't contain the Authorize attribute. An example of this attribute being used is the ActionVerbAttribute.
The easiest way by far is to just create a custom extension for the Html.ActionLink that does its own checks and keep it as a display only thing, and then create dual routes for the same controller in your Global.asax.

Resources