Get.back() getx

如何解决Get.back() getx

返回时更新数据的问题。

过渡方案:

ProfileView -> FollowPersonalView -> ProfilePublicController -> FollowPersonalView -> ProfilePublicController -> FollowPersonalView

当从 ProfilePublicController -> FollowPersonalView 开始时,我以某种方式设法更新了数据,尽管我不完全确定我做对了。

但是当你返回FollowingPersonalView -> ProfilePublicController -> FollowPersonalView时,最后阶段的数据没有更新

从逻辑上讲,它们应该从 ProfileView 中提取

配置文件控制器

class ProfileController extends GetxController
    with SingleGetTickerProviderMixin {
  var isLoading = true.obs;
  var countPage = 0.obs;
  var profileData = UserModel().obs;
  TabController tabController;

  @override
  void onInit() {
    tabController = new TabController(length: 3,vsync: this);
    Future.wait([
      _apiGetProfile(),]);
    super.onInit();
  }

  Future _apiGetProfile() async {
    try {
      isLoading(true);
      var profile = await RemoteServices.fetchProfile();
      if (profile != null) {
        profileData.value = profile;
      }
    } finally {
      isLoading(false);
    }
    update();
  }

  @override
  void onClose() {
    super.onClose();
  }
}

个人资料视图

class ProfileView extends StatelessWidget {
  final _profileController = Get.put(ProfileController());

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      if (_profileController.isLoading.value) {
        return Center(child: CircularProgressIndicator());
      } else {
        return Scaffold(
            appBar: AppBar(
              leading: Obx(
                    () =>
                    Container(
                        margin: EdgeInsets.only(left: 13,top: 15),alignment: Alignment.bottomLeft,child: IconButton(
                          icon: Icon(MyFlutterApp.favorite_active,color: Color(0xFFFE4E6A)),onPressed: () {
                            Get.toNamed('/profile/favorites',id: MainRoutesContext.Profile.index);
                          },)
                    ),),elevation: 0,backgroundColor: Color(0xFFFFFFFF),title: Row(
                mainAxisAlignment: MainAxisAlignment.center,children: [
                  Obx(
                        () =>
                        Text(
                          _profileController.profileData.value.userName
                              .toUpperCase(),style: TextStyle(
                              fontFamily: 'Gilroy',color: Color(0xFF333333),fontWeight: FontWeight.w700,fontStyle: FontStyle.normal,height: 2.9,fontSize: 18,letterSpacing: 0.82),Obx(() =>
                  _profileController.profileData.value.isConfirmed
                      ? Container(
                    margin: EdgeInsets.only(top: 17,left: 4),child: Icon(MyFlutterApp.confirmed,size: 14,color: Color(0xFF4CB3F5)),)
                      : Container()),],centerTitle: true,bottom: PreferredSize(
                  child: Container(
                    color: Color(0xFFE4E6EA),height: 1.0,preferredSize: Size.fromHeight(1.0)),body: Container());
      }
    });
  }
}

FollowingController

class FollowingController extends GetxController {
  var isLoading = true.obs;
  var username;
  var data = [].obs;

  static FollowingController get to => Get.find();

  FollowingController() {
    apiGetFollowing();
  }

  @override
  void onInit() {
    super.onInit();
  }

  void apiGetFollowing() async {
    print(Get.previousRoute);
    try {
      username = Get
          .find<ProfilePublicController>()
          .profileData
          .value
          .userName;
    } catch (e) {
      username = Get
          .find<ProfileController>()
          .profileData
          .value
          .userName;
    }
    try {
      isLoading(true);
      Request request = Request(
          url: urlPublicFollowingsList.replaceAll('{username}',username),headers: {
            'Accept': 'application/json','Content-Type': 'application/json','Authorization': 'Bearer ' + box.read('token')
          });
      request.get().then((value) {
        Map<String,dynamic> map = json.decode(value.body);
        List response = map['data'];
        data.clear();
        data.assignAll(response.map((job) => UserModel.fromJson(job)).toList());
        data.refresh();
      }).catchError((onError) {});
    } finally {
      isLoading(false);
    }
    update();
  }

  @override
  void onClose() {
    super.onClose();
  }
}

FollowingPersonalView

class FollowingPersonalView extends StatelessWidget {


  final _followingController = Get.put(FollowingController());

  @override
  Widget build(BuildContext context) {
    double width = Get.width;
    return Scaffold(
        appBar: AppBar(
          leading: IconButton(
            tooltip: 'Previous choice',icon: Icon(MyFlutterApp.left,size: 20,onPressed: () {
              Get.back(id: MainRoutesContext.Profile.index);
            },title: Obx(
                () =>
                RichText(
                    text: TextSpan(children: [
                      TextSpan(
                        text:
                        _followingController.data.length.toString() +
                            ' Following ',style: TextStyle(
                          fontFamily: 'PTRoot',color: Color(0xFF254552),letterSpacing: 0.53,TextSpan(
                        text: _followingController.username,color: Color(0xFFFE4E6A),fontWeight: FontWeight.w500,])),body:
        new GestureDetector(
          onTap: () {
            FocusScope.of(context).requestFocus(new FocusNode());
          },child: Container(
            constraints: BoxConstraints.expand(),color: Color(0xFFFFFFFF),width: width,child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,mainAxisAlignment: MainAxisAlignment.start,children: [
                Container(
                  height: 36,margin: EdgeInsets.only(left: 20,right: 20,top: 9),child: TextField(
                    controller: _followingController.searchController,onSubmitted: (value) {},decoration: InputDecoration(
                      filled: true,fillColor: Color(0xFFF2F3F4),labelText: 'Search for contests and other content',labelStyle: TextStyle(
                        fontFamily: 'PTRoot',fontSize: 16,color: Color(0xFF929292),letterSpacing: 0.13,fontWeight: FontWeight.w400,suffixIcon: Icon(
                        MyFlutterApp.search,enabledBorder: OutlineInputBorder(
                        borderSide:
                        BorderSide(color: Colors.transparent,width: 1.0),borderRadius: BorderRadius.circular(6.0),focusedBorder: OutlineInputBorder(
                        borderSide:
                        BorderSide(color: Colors.transparent,Expanded(
                    child: Obx(() =>
                        ListView.builder(
                            itemCount: _followingController.data.length,itemBuilder: (context,index) =>
                                Container(
                                    margin: EdgeInsets.only(top: 20),child: Row(
                                      children: [
                                        Container(
                                          margin: EdgeInsets.only(left: 20),width: 40,height: 40,child: CircleAvatar(
                                            backgroundImage: NetworkImage(
                                                _followingController.data[index]
                                                    .image),radius: 50,InkWell(
                                          onTap: () {
                                            _followingController.username =
                                                _followingController
                                                    .data[index].userName;
                                            Get.toNamed('/profile/public',id: MainRoutesContext.Profile
                                                    .index);
                                          },child: Column(
                                            crossAxisAlignment:
                                            CrossAxisAlignment.start,mainAxisAlignment: MainAxisAlignment
                                                .start,children: [
                                              Container(
                                                margin: EdgeInsets.only(
                                                    left: 10),child: Text(
                                                  _followingController
                                                      .data[index].userName,style: TextStyle(
                                                    fontFamily: 'PTRoot',Container(
                                                  margin: EdgeInsets.only(
                                                      left: 10),child: Text(
                                                    'Blogger',style: TextStyle(
                                                      fontFamily: 'PTRoot',fontSize: 14,color: Color(0xFF777777),fontStyle: FontStyle
                                                          .normal,letterSpacing: 0.41,fontWeight: FontWeight
                                                          .w500,)),Spacer(),Container(
                                            margin: EdgeInsets.only(right: 20),decoration: BoxDecoration(
                                              border: Border.all(
                                                  color: Color(0xFFF7537E),width: 1),borderRadius: BorderRadius
                                                  .circular(8),width: width * 0.25,height: 37,child: new Row(
                                                crossAxisAlignment:
                                                CrossAxisAlignment.center,mainAxisAlignment:
                                                MainAxisAlignment.center,children: <Widget>[
                                                  Text(
                                                    'Following',style: TextStyle(
                                                        fontFamily: 'PTRoot',fontStyle: FontStyle
                                                            .normal,fontWeight: FontWeight
                                                            .w500,color: Color(
                                                            0xFFFFFFFF)),)))))
              ],));
  }
}

ProfilePublicController

    class ProfilePublicController extends GetxController
        with SingleGetTickerProviderMixin {
      var isLoading = true.obs;
      var profileData = UserModel().obs;
      var creatorData = List<CreatorListModel>().obs;
      var blogData = List<BlogModel>().obs;
      TabController tabController;
    
      @override
      void onInit() {
        tabController = new TabController(length: 4,vsync: this);
        try {
          Future.wait([
            _apiGetPublicProfile(Get
                .find<FollowerController>()
                .username),]);
        } catch (e) {
          Future.wait([
            _apiGetPublicProfile(Get
                .find<FollowingController>()
                .username),]);
        }
        super.onInit();
      }
    
      Future _apiGetPublicProfile(username) async {
        try {
          isLoading(true);
          var profile = await RemoteServices.fetchPublicProfile(username);
          if (profile != null) {
            profileData.value = UserModel.fromJson(profile['user']);
            List responseBlog = profile['blog']['data'];
            blogData.value =
                responseBlog.map((job) => BlogModel.fromJson(job)).toList();
            List responseChallenges = [profile['challenges']];
            creatorData.value = responseChallenges
                .map((job) => CreatorListModel.fromJson(job))
                .toList();
            await Get.find<BlogCardController>().apiGetBlogList();
            // List responseParticipant = [profile['participant']];
            // List responseJudge = [profile['judge']];
          }
        } finally {
          isLoading(false);
        }
        update();
      }
    
      @override
      void onClose() {
        super.onClose();
      }
    }

**PublicProfileView**

class PublicProfileView extends StatelessWidget {
  final _profilePublicController = Get.put(ProfilePublicController());

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      if (_profilePublicController.isLoading.value) {
        return Center(child: CircularProgressIndicator());
      } else {
        return Scaffold(
            appBar: AppBar(
              leading: Container(
                margin: EdgeInsets.only(left: 13,child: IconButton(
                  icon: Icon(MyFlutterApp.left,size: 18,onPressed: () {
                    Get.back(
                        id: MainRoutesContext.Profile.index,canPop: false);
                  },children: [
                  Obx(
                        () =>
                        Text(
                          _profilePublicController.profileData.value.userName
                              .toUpperCase(),Obx(() =>
                  _profilePublicController.profileData.value.isConfirmed
                      ? Container(
                    margin: EdgeInsets.only(top: 17,body: Container());
      }
    });
  }
}

如何更新Get.back()上的数据?

附言打开FollowPersonalView页面时是否可以完全控制数据检索功能的启动?

得到:^4.1.3 颤振 2.0.4

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-