> 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) {
        ...
```
