Reputation: 503
Getting error when using the slider in flutter.
Code where the error is :
Slider(
value: (_currentStrength ?? userData.strength).toDouble(),
activeColor:
Colors.brown[_currentStrength ?? userData.strength],
inactiveColor:
Colors.brown[_currentStrength ?? userData.strength],
min: 100.0,
max: 900.0,
divisions: 8,
onChanged: (val) =>
setState(() => _currentStrength = val.round()),
),
User data class :
class UserData {
final String uid;
final String name;
final String sugars;
final int strength;
UserData({ required this.uid, required this.sugars, required this.strength, required this.name });
}
Upvotes: 0
Views: 113
Reputation: 2099
You are using Flutter with sound null safety enabled. The error message means that you are trying to assign a value which might be null to a parameter which may not be null.
You can probably fix your issue, by adding an exclamation mark to the value you are passing in like: _currentStrength ?? userData.strength!
But please read this: https://dart.dev/null-safety
Upvotes: 1