Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android NoSuchMethodError:getter';文件';被调用为空?_Android_Flutter_Google Cloud Firestore - Fatal编程技术网

Android NoSuchMethodError:getter';文件';被调用为空?

Android NoSuchMethodError:getter';文件';被调用为空?,android,flutter,google-cloud-firestore,Android,Flutter,Google Cloud Firestore,**您好,我在我的代码和文档中使用了flifter和querySnapshot,但我不知道有什么错误,有人帮我修复代码下面的错误吗** 省道 class SearchPage extends StatefulWidget { @override _SearchPageState createState() => _SearchPageState(); } class _SearchPageState extends State<SearchPage> with

**您好,我在我的代码和文档中使用了flifter和querySnapshot,但我不知道有什么错误,有人帮我修复代码下面的错误吗**

省道

class SearchPage extends StatefulWidget {
  @override
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage>
    with AutomaticKeepAliveClientMixin<SearchPage> {
  TextEditingController searchTextEditingController = TextEditingController();
  Future<QuerySnapshot> futureSearchResults;
  emptyTheTextFormField() {
    searchTextEditingController.clear();
  }

  controllSearching(String str) {
    Future<QuerySnapshot> allUsers = userRefrence
        .where("profileName", isGreaterThanOrEqualTo: str)
        .getDocuments();
    setState(() {
      futureSearchResults = allUsers;
    });
  }

  Container displayNoSearchResult() {
    final Orientation orientation = MediaQuery.of(context).orientation;
    return Container(
      child: Center(
        child: ListView(
          shrinkWrap: true,
          children: <Widget>[
            Icon(
              Icons.group,
              color: Colors.grey,
              size: 200.0,
            ),
            Icon(
              Icons.search,
              color: Colors.grey,
              size: 20.0,
            ),
            Text(
              "Search Users",
              textAlign: TextAlign.center,
              style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.w500,
                  fontSize: 65.0),
            ),
          ],
        ),
      ),
    );
  }

  displayUsersFoundScreen() {
    return FutureBuilder(
      future: futureSearchResults,
      builder: (context, dataSnapshot) {
        if (dataSnapshot.hasData) {
          return circularProgress();
        }
        List<UserResult> searchUserResult = [];
        dataSnapshot.data.document.forEach((document) {
          User eachuser = User.fromDocument(document);
          UserResult userResult = UserResult(eachuser);
          searchUserResult.add(userResult);
        });
        return ListView(children: searchUserResult);
      },
    );
  }

  AppBar searchPageHeader() {
    return AppBar(
      backgroundColor: Colors.black,
      title: TextFormField(
        style: TextStyle(fontSize: 18.0, color: Colors.white),
        controller: searchTextEditingController,
        decoration: InputDecoration(
          hintText: "Search Here....",
          hintStyle: TextStyle(color: Colors.grey),
          enabledBorder: UnderlineInputBorder(
            borderSide: BorderSide(color: Colors.grey),
          ),
          focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(color: Colors.white),
          ),
          filled: true,
          prefixIcon: Icon(Icons.person_pin, color: Colors.white, size: 30.0),
          suffixIcon: IconButton(
              icon: Icon(
                Icons.clear,
                color: Colors.white,
              ),
              onPressed: emptyTheTextFormField),
        ),
        onFieldSubmitted: controllSearching,
      ),
    );
  }

  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: searchPageHeader(),
      body: futureSearchResults == null
          ? displayNoSearchResult()
          : displayUsersFoundScreen(),
    );
  }
}

class UserResult extends StatelessWidget {
  final User eachuser;

  UserResult(this.eachuser);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(3.0),
      child: Container(
          color: Colors.white54,
          child: Column(
            children: <Widget>[
              GestureDetector(
                onTap: () => print("tapped"),
                child: ListTile(
                  leading: CircleAvatar(
                    backgroundColor: Colors.black,
                    backgroundImage: CachedNetworkImageProvider(eachuser.url),
                  ),
                  title: Text(
                    eachuser.profileName,
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 16.0,
                        fontWeight: FontWeight.bold),
                  ),
                  subtitle: Text(
                    eachuser.username,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 13.0,
                    ),
                  ),
                ),
              )
            ],
          )),
    );
  }
}
class SearchPage扩展StatefulWidget{
@凌驾
_SearchPageState createState()=>\u SearchPageState();
}
类_SearchPageState扩展状态
使用AutomaticEpaLiveClientMixin{
TextEditingController搜索TextEditingController=TextEditingController();
未来的搜索结果;
emptyTheTextFormField(){
searchTextEditingController.clear();
}
控制搜索(字符串str){
未来用户=用户引用
。其中(“profileName”,大于或等于:str)
.getDocuments();
设置状态(){
未来搜索结果=诱惑者;
});
}
容器displayNoSearchResult(){
最终方向=MediaQuery.of(context.Orientation);
返回容器(
儿童:中心(
子:ListView(
收缩膜:对,
儿童:[
图标(
图标组,
颜色:颜色。灰色,
尺寸:200.0,
),
图标(
Icons.search,
颜色:颜色。灰色,
尺寸:20.0,
),
正文(
“搜索用户”,
textAlign:textAlign.center,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.w500,
字体大小:65.0),
),
],
),
),
);
}
displayUsersFoundScreen(){
回归未来建设者(
未来:未来搜索结果,
生成器:(上下文,数据快照){
if(dataSnapshot.hasData){
返回循环进程();
}
列出searchUserResult=[];
dataSnapshot.data.document.forEach((文档){
User eachuser=User.fromDocument(document);
UserResult UserResult=UserResult(eachuser);
searchUserResult.add(userResult);
});
返回ListView(子项:searchUserResult);
},
);
}
AppBar searchPageHeader(){
返回AppBar(
背景颜色:Colors.black,
标题:TextFormField(
样式:TextStyle(字体大小:18.0,颜色:Colors.white),
控制器:searchTextEditingController,
装饰:输入装饰(
hintText:“在此处搜索…”,
hintStyle:TextStyle(颜色:Colors.grey),
enabledBorder:UnderlineInputBorder(
borderSide:borderSide(颜色:Colors.grey),
),
FocusedOrder:下划线输入边框(
borderSide:borderSide(颜色:Colors.white),
),
是的,
前缀:图标(Icons.person\u pin,颜色:Colors.white,大小:30.0),
后缀:图标按钮(
图标:图标(
图标。清除,
颜色:颜色,白色,
),
按下:清空etextformfield),
),
onFieldSubmitted:ControlSearching,
),
);
}
bool get wantKeepAlive=>true;
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.black,
appBar:searchPageHeader(),
正文:futureSearchResults==null
?displayNoSearchResult()
:displayUsersFoundScreen(),
);
}
}
类UserResult扩展了无状态小部件{
最终用户;
UserResult(this.eachuser);
@凌驾
小部件构建(构建上下文){
返回填充(
填充:所有边缘设置(3.0),
子:容器(
颜色:颜色。白色54,
子:列(
儿童:[
手势检测器(
onTap:()=>打印(“点击”),
孩子:ListTile(
领先:CircleAvatar(
背景颜色:Colors.black,
背景图片:CachedNetworkImageProvider(eachuser.url),
),
标题:正文(
eachuser.profileName,
样式:TextStyle(
颜色:颜色,黑色,
字体大小:16.0,
fontWeight:fontWeight.bold),
),
字幕:文本(
eacchuser.username,
样式:TextStyle(
颜色:颜色,黑色,
字体大小:13.0,
),
),
),
)
],
)),
);
}
}

由于您的
if
条件,您得到的错误应该是
if(!dataSnapshot.hasData){…}

替换:

if(dataSnapshot.hasData){…}

如果(!dataSnapshot.hasData){…}

我使用您的代码添加了一个修复程序:

displayUsersFoundScreen(){
回归未来建设者(
未来:未来搜索结果,
生成器:(上下文,数据快照){
如果(!dataSnapshot.hasData){//应该是!dataSnapshot.hasData
返回循环进程();
}
列出searchUserResult=[];
dataSnapshot.data.document.forEach((文档){
User eachuser=User.fromDocument(document);
UserResult UserResult=UserResult(eachuser);
searchUserResult.add(userResult);
});
返回ListView(子项:searchUserResult);
},
);
}

由于您的
if
条件,您得到的错误应该是
if(!dataSnapshot.hasData){…}

替换:

if(dataSnapshot.hasData){…}

如果(!dataSnapshot.hasData){…}

我使用你添加了一个补丁