juliansteenbakker / flutter_settings_ui

Fork of settings_ui. Create native settings for Flutter app in a minutes.
Apache License 2.0
42 stars 16 forks source link

SettingsTile.switchTile | Error "Null check operator used on a null value" #22

Open haizadvnet opened 6 months ago

haizadvnet commented 6 months ago
════════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building SettingsTile(dirty):
Null check operator used on a null value

When the exception was thrown, this was the stack:
#0      SettingsTheme.of (package:flutter_settings_ui/src/utils/settings_theme.dart:21:18)
settings_theme.dart:21
#1      SettingsTile.build (package:flutter_settings_ui/src/tiles/settings_tile.dart:94:33)
settings_tile.dart

I ran into issue above after migration to new version (3.0.0). Even the snippet below that I got from the example, gives me the error.

SettingsTile.switchTile(
                initialValue: false,
                onToggle: (_) {},
                title: Text('Allow notification snoozing'),
              ),
ericbomgardner commented 2 months ago

Seems like flutter_settings_ui expects SettingsTile to always be used within a SettingsList (which creates a SettingsTheme and adds it to the widget tree above its sections); if you're using the tile without a SettingsList, then there's no SettingsTheme automatically available.

A workaround that's working for me is to include a SettingsTheme as a parent widget of the settings tile, like:

    SettingsTheme(
        themeData: const SettingsThemeData(),
        platform: detectPlatform(context),
        child: SettingsTile.switchTile(
          initialValue: false,
          onToggle: (_) {},
          title: const Text('Allow notification snoozing'),
        ));