I am trying to make the SearchBar for an UI and when I try to search nothing it's happening. I put some Cases like Error or nothing found or done and the UI remains with a white screen when I search.What is wrong with my code?
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flappy_search_bar/flappy_search_bar.dart';
import 'package:flutter/material.dart';
class Searchbar extends StatefulWidget {
@override
SearchBarState createState() => SearchBarState();
}
class SearchBarState extends State<Searchbar> {
TextEditingController textEditingController = TextEditingController();
final database = Firestore.instance;
String searchString;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Column(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(15.0),
child: Container(
child: TextField(
onChanged: (val) {
setState(() {
searchString = val.toLowerCase();
});
},
controller: textEditingController,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.clear),
onPressed: () => textEditingController.clear()),
hintText: " Search name here ",
hintStyle: TextStyle(
fontFamily: 'Antra', color: Colors.blueGrey)),
),
),
),
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: (searchString == null || searchString.trim() == '')
? Firestore.instance.collection('Users').snapshots()
: Firestore.instance
.collection('Users')
.where('name', arrayContains: searchString)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('We got an error ${snapshot.error}');
}
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return SizedBox(
child: Center(
// child: Lottie.asset('animations/loading2.json'),
),
);
case ConnectionState.none:
return Text('Oops no data present');
case ConnectionState.done:
return Text('We are done');
default:
return new ListView(
children: snapshot.data.documents
.map((DocumentSnapshot document) {
return new ListTile(
title: Text(document['Users']),
);
}).toList());
}
},
))
],
),
)
],
)));
}
}
and this is the Firestore : 1 I want to search users by name and I added this to my code but I don't know why it doesn't work