如何使用Flutter Getx更改屏幕 [英] How to Change Screen Using Flutter Getx

查看:92
本文介绍了如何使用Flutter Getx更改屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有问题.如何使用FLutter Getx更改屏幕.我从Firestore得到了GetxControll那个searchUser.这是代码.

i Got Questions here. How to change screen using FLutter Getx. I got GetxControll that searchUser from firestore. Here's the code.

class AuthenticationC extends GetxController {
final usersRef = FirebaseFirestore.instance.collection('Users');
List<QueryDocumentSnapshot> searchResultFuture;
  searchUser(String query) async {
    QuerySnapshot snapshot = await usersRef
        .where('DisplayName', isGreaterThanOrEqualTo: query)
        .get();

    searchResultFuture = snapshot.docs;   
    return snapshot.docs;
  }
}

然后我想将UI从buildNoContent()更改为With buildSearchedContent().当用户在TextField中输入文本时.然后它将自动更改用户界面.我已经有了searchUser,但UI不变.这里的UI代码.谢谢

then i want to change UI from buildNoContent() to With buildSearchedContent(). when user enter text in the TextField. then it will auto change the UI. i already got the searchUser but the UI Doesn't change. here the UI Code. Thank You

class SearchUserScreen extends StatelessWidget {
final authenticationC = AuthenticationC.to;
@override
Widget build(BuildContext context) {
    return Scaffold(
       body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            searchBox(),
            SizedBox(
              height: 20,
            ),
            authenticationC.searchResultFuture == null   // i want to change here 
                ? buildNoContent()                       // im already using GetBuilder<AuthenticationC> 
                : Expanded(child: buildSearchedContent(),// But it wont change
                  ),
          ],
        ),
      ),
  }
}

推荐答案

尝试在用户界面中放置Obx:

Try to put Obx in your UI:

class SearchUserScreen extends StatelessWidget {
final authenticationC = AuthenticationC.to;
@override
Widget build(BuildContext context) {
return Scaffold(
   body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Obx(()=>Column(
      children: [
        searchBox(),
        SizedBox(
          height: 20,
        ),
        authenticationC.searchResultFuture == null   // i want to change here 
            ? buildNoContent()                       // im already using GetBuilder<AuthenticationC> 
            : Expanded(child: buildSearchedContent(),// But it wont change
              ),
      ],
    ),),
  ),
  }
}

这篇关于如何使用Flutter Getx更改屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆