Я пытаюсь создать веб-приложение Flutter. Но проблема возникает всякий раз, когда я обновляю sh страницу или выхожу на экран в первый раз, когда отображается ошибка, а затем через некоторое время на экране появляется полученное значение и ошибка исчезает.
следующее:
NoSuchMethodError был сгенерирован при построении StreamBuilder (грязный, состояние: _StreamBuilderBaseState> # 6203e):
'документы'
метод не найден
Получатель : null
Аргументы: []
Я хочу знать, почему на странице происходит такое поведение? В чем проблема?
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fulltext_search/study.dart';
import 'package:fulltext_search/study_search.dart';
import 'package:fulltext_search/visitor.dart';
void main() {
runApp(StudentSearchData());
}
class StudentSearchData extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var queryResultSet = [];
var tempSearchStore = [];
initiateSearch(value) {
if (value.length == 0) {
setState(() {
queryResultSet = [];
tempSearchStore = [];
});
}
var capitalizedValue = value.substring(0, 1).toUpperCase() + value.substring(1);
var lowerValue = value.substring(0, 1).toLowerCase() + value.substring(1);
if (queryResultSet.length == 0 && value.length == 1) {
SearchService().searchByName(value).then((QuerySnapshot docs) {
for (int i = 0; i < docs.documents.length; ++i) {
queryResultSet.add(docs.documents[i].data);
}
});
} else {
tempSearchStore = [];
queryResultSet.forEach((element) {
if (element['fname'].startsWith(capitalizedValue)) {
setState(() {
tempSearchStore.add(element);
});
}
if (element['fname'].startsWith(lowerValue)) {
setState(() {
tempSearchStore.add(element);
});
}
});
}
}
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
/*24 is for notification bar on Android*/
final double itemHeight = (size.height - kToolbarHeight-24)/3;
final double itemWidth = size.width / 2;
return new Scaffold(
appBar: new AppBar(
title: Text('Student data search'),
actions: <Widget>[
FlatButton(
textColor: Colors.white,
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => Student()),);
},
child: Text("Student",),
),
FlatButton(
textColor: Colors.white,
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => Visitor()),);
},
child: Text("Visitor",),
),
FlatButton(
color: Colors.grey[400],
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.white,width: 1),
borderRadius: BorderRadius.circular(10),
),
textColor: Colors.black87,
onPressed: () {},
child: Text("History",style: TextStyle(fontSize: 15,fontWeight: FontWeight.bold),),
),
FlatButton(
textColor: Colors.white,
onPressed: () {
//Navigator.push(context, MaterialPageRoute(builder: (context) => VisitorHistory()),);
},
child: Text("Logout",),
),
],
),
body: ListView(children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: TextField(
onChanged: (val) {
initiateSearch(val);
},
decoration: InputDecoration(
prefixIcon: IconButton(
color: Colors.black,
icon: Icon(Icons.arrow_back),
iconSize: 20.0,
onPressed: () {
Navigator.of(context).pop();
},
),
contentPadding: EdgeInsets.only(left: 25.0),
hintText: 'Search by name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4.0))),
),
),
SizedBox(height: 10.0),
GridView.count(
childAspectRatio: (itemWidth / itemHeight),
padding: EdgeInsets.only(left: 10.0, right: 10.0),
crossAxisCount: 2,
//scrollDirection: Axis.horizontal,
crossAxisSpacing: 4.0,
mainAxisSpacing: 4.0,
primary: false,
shrinkWrap: true,
children: tempSearchStore.map((element) {
return buildResultCard(element);
}).toList())
]));
}
}
Widget buildResultCard(data) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.blue,width: 2),
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width:120,
child: Row(children: <Widget>[
Image.network(data['image'], width:120,height: 120,fit: BoxFit.cover,),
Spacer(),
]),
),
SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Name:- ${data['fname']}\n', style: new TextStyle(fontSize: 12.0,color: Colors.black),),
Text('Year:- ${data['year']}\n', style: new TextStyle(fontSize: 12.0,color: Colors.black),),
Text('Contact no:- ${data['contact']}\n', style: new TextStyle(fontSize: 12.0,color: Colors.black),),
Text('Vehicle no:- ${data['vehicleno']}\n', style: new TextStyle(fontSize: 12.0,color: Colors.black),),
Row(
children: <Widget>[
Expanded(
child: Text('purpose of visiting:- ${data['purpose']}\n', style: new TextStyle(fontSize: 12.0,),),
),
],
),
Text('Entry-time:- ${data['Entry-time']}\n', style: new TextStyle(fontSize: 12.0,),),
Text('Exit-time:- ${data['Exit-time']}\n', style: new TextStyle(fontSize: 12.0,),),
],
),
)
],
),
),
),
),
),
);
}
![enter image description here](https://i.stack.imgur.com/lJYKQ.jpg)
![enter image description here](https://i.stack.imgur.com/KGotx.jpg)