Я пытаюсь создать модуль поиска для своего приложения, посвященного флаттеру, и хочу найти такие предметы, как математика, физика и т. Д. c. Но проблема в том, что я добавил 3 предмета для каждого учителя, и учитель мог бы добавить такой предмет, как физика, в предмет 1 или в предмет 2 или в предмет 3, поэтому я понятия не имею, как искать во всех них и отображать всех учителей, которые преподают физику , Есть ли сложный запрос, потому что я не смог его найти. Я был бы очень признателен за любую помощь. Вот мой код до сих пор.
import 'package:etutor/ReusableMaterial/Constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:getflutter/components/avatar/gf_avatar.dart';
import 'package:getflutter/shape/gf_avatar_shape.dart';
import 'package:line_icons/line_icons.dart';
class Search extends StatefulWidget {
@override
_SearchState createState() => _SearchState();
}
class _SearchState extends State<Search> with SingleTickerProviderStateMixin {
Firestore fireStore = Firestore.instance;
AnimationController _animationController;
final TextEditingController _textController = new TextEditingController();
bool isPlaying = false;
String lists;
double value = 40;
var enableBorder = Color(0xFFdcd6f7);
var focusBorder = Color(0xFFa6b1e1);
var actualEnableBorder = Color(0xFFdcd6f7);
var actualFocusBorder = Color(0xFFa6b1e1);
@override
void initState() {
super.initState();
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 300));
}
Future<QuerySnapshot> getAllDocuments() {
return fireStore.collection('userData').getDocuments();
}
@override
void dispose() {
super.dispose();
_animationController.dispose();
}
void _handleOnPressed() {
setState(() {
isPlaying = !isPlaying;
isPlaying
? _animationController.forward()
: _animationController.reverse();
isPlaying ? value = 300 : value = 40;
isPlaying
? focusBorder = actualFocusBorder
: focusBorder = Colors.transparent;
isPlaying
? enableBorder = actualEnableBorder
: enableBorder = Colors.transparent;
_textController.clear();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
Center(child: Text('Search', style: kHeadingStyle)),
SizedBox(height: 50),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 45.0),
child: AnimatedContainer(
curve: Curves.easeInCirc,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.transparent,
// color: Color(0xFFeaeaea),
),
height: 50,
width: value,
duration: Duration(seconds: 1),
child: TextFormField(
controller: _textController,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: AnimatedIcon(
color: kBlueColor,
icon: AnimatedIcons.ellipsis_search,
size: 30,
progress: _animationController),
onPressed: () {
_handleOnPressed();
}),
hintText: 'Search...',
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: enableBorder, width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: focusBorder, width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
),
keyboardType: TextInputType.text,
onChanged: (value) {},
),
),
),
],
),
SizedBox(height: 30),
StreamBuilder<QuerySnapshot>(
stream: fireStore
.collection('userData')
.where('subject1', isEqualTo: 'Mathematics')
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final doc = snapshot.data.documents;
List<SearchMaterial> newTemp = [];
for (var t in doc) {
final userName = t.data['Name'];
final userEmail = t.data['Email'];
final userImageURL = t.data['imageURl'];
final subject1 = t.data['subject1'];
final subject2 = t.data['subject2'];
final subject3 = t.data['subject3'];
final rating = t.data['rating'];
final newTemp3 = SearchMaterial(
userName: userName,
email: userEmail,
imageUrl: userImageURL,
subject1: subject1,
subject2: subject2,
subject3: subject3,
rating: rating,
);
newTemp.add(newTemp3);
}
return Expanded(
child: ListView(
// reverse: true,
children: newTemp,
),
);
}
return Center(child: Image.asset('images/book.gif'));
},
)
],
),
),
);
}
}
class SearchMaterial extends StatelessWidget {
final String userName;
final String email;
final String imageUrl;
final String subject1;
final String subject2;
final String subject3;
final String rating;
const SearchMaterial(
{this.userName,
this.email,
this.imageUrl,
this.subject1,
this.subject2,
this.subject3,
this.rating});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 40.0, right: 40, bottom: 30),
child: Container(
height: 115,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(84, 104, 255, .15),
blurRadius: 10,
offset: Offset(1, 5),
)
],
),
child: Stack(
children: <Widget>[
Align(
alignment: Alignment(-1, 0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GFAvatar(
backgroundColor: Colors.white,
size: 60,
shape: GFAvatarShape.standard,
backgroundImage: NetworkImage(
'$imageUrl',
scale: 1.0,
),
),
),
),
Align(
alignment: Alignment(0.95, -.85),
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(LineIcons.star),
Text('$rating'),
],
),
height: 25,
width: 70,
decoration: BoxDecoration(
color: Color(0xFFffd868),
borderRadius: BorderRadius.circular(15),
),
),
),
Container(
child: Padding(
padding: EdgeInsets.only(left: 112.0, top: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('$userName'),
SizedBox(height: 15),
Text('$subject1'),
Text('$subject2'),
Text('$subject3'),
],
),
))
],
),
),
);
}
}