
# @Controller

`@Controller()` marks a class as a bean of the presentation layer.

## Why

In this package it does exactly what [@Component](component.md) does. It suits objects that drive a user interface, such as the logic behind a Flutter screen or a view model. The web starter (`spring_boot_starter_web`) gives it its request-handling meaning.

Use it so that a reader sees at once which classes belong to the UI side, and so that [scan filters](component-scan.md) and pointcuts can select them.

## Example

```dart
import 'package:spring_core_dart/spring_core_dart.dart';

@Service()
class AuthService {
  bool login(String user, String password) => password.isNotEmpty;
}

// The login screen's logic, with the auth service injected.
// The widget only calls submit() and reads error.
@Controller()
class LoginController {
  LoginController(this.auth);

  final AuthService auth;
  String? error;

  bool submit(String user, String password) {
    final ok = auth.login(user, password);
    error = ok ? null : 'Wrong user name or password';
    return ok;
  }
}
```

## Parameters

| Name | Type | Default | Meaning |
|---|---|---|---|
| `name` (positional) | `String?` | `null` | The bean name. `null` gives the class name in lowerCamelCase. |

## In Spring (Java)

```java
@Controller
class LoginController {
  LoginController(AuthService auth) { ... }
}
```

In Spring MVC a `@Controller` handles web requests. In `spring_core_dart` alone it is only a stereotype. Request handling comes from the web starter.

## See also

- [@Component](component.md)
- [@Service](service.md)
- [@Configurable](configurable.md): inject beans into a Flutter `State`
