> For the complete documentation index, see [llms.txt](https://flutter-boilerplate.gitbook.io/flutter-boilerplate-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://flutter-boilerplate.gitbook.io/flutter-boilerplate-docs/features/provider.md).

# Provider

There are two providers used in the app. The `UserDataProvider()` and the `ThemeProvider().`

They are setup globally in the `main.dart` file with a `MultiProvider()`

```dart
MultiProvider(
  providers: [
    ChangeNotifierProvider(
      create: (context) {
        return UserDataProvider();
      },
    ),
    ChangeNotifierProvider(
      create: (context) {
        return ThemeProvider();
      },
    ),
  ],
  ...
```

## UserDataProvider()

The `UserDataProvider()` is updated whenever the database listener registers an update in the userdata. This logic is implemented in the `UserDataWrapper()`.\
Whenever the is a part of the UI that must update when the user data changes in the database, the user data can be read from the provider:

```dart
context.listen<UserDataProvider>().userData
```

## ThemeProvider()

The `ThemeProvider()` contains no data but is only used as notification whenever something in the Theme or UI updates and the whole up needs to rebuild. E.g. in the `SwithLightDarkTheme1()`

```dart
context.read<ThemeProvider>().notify();
```

To rebuild the app the top level `MaterialApp()` widget in main.dart is wrapped with a `ChangeNotifierProvider()` that has the `ThemeProvider` as a consumer.

```dart
ChangeNotifierProvider(
    create: (context) => ThemeProvider(),
    child: Consumer<ThemeProvider>(
        builder: (context, themeProvider, child) {
        ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://flutter-boilerplate.gitbook.io/flutter-boilerplate-docs/features/provider.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
