flutter_settings_ui
flutter_settings_ui copied to clipboard
SettingsTile.switchTile | Error "Null check operator used on a null value"
════════ 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'),
),
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'),
));