setAttribute abstract method
Sets or replaces a request attribute with the given name and value.
Attributes can be used to store context or share data between components during request processing. Attributes are request-scoped and will be available to all components that process the same request.
Parameters
name: The name of the attribute to setvalue: The value to associate with the attribute
Example
// Store authentication context
request.setAttribute('authenticatedUser', user);
// Store request timing
request.setAttribute('requestStartTime', DateTime.now());
// Store computed data for reuse
request.setAttribute('parsedBody', parsedJson);
Best Practices
- Use descriptive names to avoid conflicts
- Consider using namespaced names (e.g., 'package:example/example.dart.user')
- Be mindful of memory usage for large objects
Implementation
void setAttribute(String name, Object value);