So, I'm trying to display a stream using a list view from a stream function, that takes an input from the text field.
Stream<List<UserModel>> queryByName(search) {
return FirebaseFirestore.instance
.collection("users")
.orderBy("firstName")
.startAt([search]).endAt([search + '\uf8ff'])
.limit(10).snapshots()
.map(userListFromQuerySnapshot); }
..
Column(
children: [
Padding(
padding: EdgeInsets.all(10),
child: Obx(
() => TextField(
onChanged: (text) {
_.search.value = text;
},
decoration: InputDecoration(hintText: 'Search keyword'),
),
),
),
GetX<PalsViewController>(
init: Get.put<PalsViewController>(PalsViewController()),
builder: (PalsViewController palsViewController) {
return Expanded(
child: ListView.builder(
itemCount: palsViewController.viewPals.length,
itemBuilder: (_, index) {
return Column(
children: [
Padding(
padding: EdgeInsets.all(10),
child: Row(children: [
palsViewController.viewPals[index]
.profileImageUrl !=
''
? CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
palsViewController.viewPals[index]
.profileImageUrl),
)
: Icon(Icons.person, size: 30),
SizedBox(width: 10),
Text(palsViewController
.viewPals[index].firstName)
])),
const Divider(
thickness: 1,
)
],
);
}),
);
},
)
],
),
So, here's the issue.. the bind stream receives only the initial input of the search string which is empty.. and it's not changing when the text field value changes.
RxList<UserModel> viewPals = RxList<UserModel>([]);
var search = ''.obs ;
@override
void onInit() {
super.onInit();
viewPals.bindStream(UserService.instance.queryByName(search.value));
}
Try using like this. hope it will help you resolve your bindStream issue.
and in your onInit() use like this.
and use viewPals like this.
use this as model class