Redirect class final
Sends the client somewhere else.
Return one from a handler; the verb builder writes it like any other value:
Future<Object?> oldPath(Request request) async =>
Redirect.permanent('/new/path');
Which constructor to reach for is a question about method and caching,
and getting it wrong is how a POST turns into a GET or a browser
remembers a move that was meant to be temporary:
| Constructor | Status | Method | Cached |
|---|---|---|---|
| Redirect.to | 303 | always becomes GET |
no |
| Redirect.temporary | 307 | preserved | no |
| Redirect.permanent | 308 | preserved | forever |
| Redirect.found | 302 | usually becomes GET |
no |
| Redirect.movedPermanently | 301 | usually becomes GET |
forever |
After a successful POST, Redirect.to is almost always the one you want:
303 tells the browser to follow up with a GET, which is what stops a
refresh from submitting the form twice.
301 and 302 are kept because real clients send them, but they are the two
whose method handling was never specified consistently — browsers turn a
POST into a GET and other clients do not. Prefer 303 or 307, which say
what they mean.
- Implemented types
Constructors
- Redirect.found(String location)
-
A 302, kept for clients that expect it. Prefer Redirect.to.
const
- Redirect.movedPermanently(String location)
-
A 301, kept for clients that expect it. Prefer Redirect.permanent.
const
- Redirect.permanent(String location)
-
A 308: same method, and remember this permanently.
const
- Redirect.temporary(String location)
-
A 307: same place, same method, do not cache.
const
- Redirect.to(String location)
-
A 303: follow up with a
GET, whatever this request was.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isPermanent → bool
-
Whether a client may cache this redirect indefinitely.
no setter
- location → String
-
Where the client is being sent.
final
- preservesMethod → bool
-
Whether the client keeps the method it used.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → int
-
The status code this redirect sends.
final
Methods
-
intoResponse(
) → Response -
Builds the response for this value.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited