We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I set the value of the text to null, the change is not reflected on the UI. It works for every other value.
`import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
// Adjust path as needed
class TaskState { String? text;
TaskState({required this.text});
TaskState copyWith({ String? text, }) { return TaskState( text: text ?? this.text, ); }
factory TaskState.initial() { return TaskState( text: null, ); } }
class TaskNotifier extends Notifier { @OverRide TaskState build() { return TaskState.initial(); }
void setText(String? text) { state = state.copyWith(text: text); } }
final taskProvider = NotifierProvider<TaskNotifier, TaskState>(() { return TaskNotifier(); }); `
TextField( controller: controller, ), ElevatedButton( onPressed: () { ref.read(taskProvider.notifier).setText( controller.text.isEmpty || controller.text == '' ? null : controller.text); }, child: Text("Set value")), Text(text ?? "the value is null"),
If the value is null, 'the value is null' is expected to be show in the text widget.
The text was updated successfully, but these errors were encountered:
I doubt Riverpod is the issue here.
Could you share a full example?
Sorry, something went wrong.
rrousselGit
No branches or pull requests
When I set the value of the text to null, the change is not reflected on the UI. It works for every other value.
`import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// Adjust path as needed
class TaskState {
String? text;
TaskState({required this.text});
TaskState copyWith({
String? text,
}) {
return TaskState(
text: text ?? this.text,
);
}
factory TaskState.initial() {
return TaskState(
text: null,
);
}
}
class TaskNotifier extends Notifier {
@OverRide
TaskState build() {
return TaskState.initial();
}
void setText(String? text) {
state = state.copyWith(text: text);
}
}
final taskProvider = NotifierProvider<TaskNotifier, TaskState>(() {
return TaskNotifier();
});
`
TextField( controller: controller, ), ElevatedButton( onPressed: () { ref.read(taskProvider.notifier).setText( controller.text.isEmpty || controller.text == '' ? null : controller.text); }, child: Text("Set value")), Text(text ?? "the value is null"),
If the value is null, 'the value is null' is expected to be show in the text widget.
The text was updated successfully, but these errors were encountered: