Skip to content
New issue

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

setting the value to null doesn't update the UI. #3921

Open
qasim-xo opened this issue Jan 12, 2025 · 1 comment
Open

setting the value to null doesn't update the UI. #3921

qasim-xo opened this issue Jan 12, 2025 · 1 comment
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@qasim-xo
Copy link

qasim-xo commented Jan 12, 2025

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.

@qasim-xo qasim-xo added bug Something isn't working needs triage labels Jan 12, 2025
@rrousselGit
Copy link
Owner

I doubt Riverpod is the issue here.

Could you share a full example?

@rrousselGit rrousselGit added question Further information is requested and removed needs triage labels Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants