Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
Flutter 如何在redux中更新存储_Flutter_Dart_Redux_Store_Flutter Dependencies - Fatal编程技术网

Flutter 如何在redux中更新存储

Flutter 如何在redux中更新存储,flutter,dart,redux,store,flutter-dependencies,Flutter,Dart,Redux,Store,Flutter Dependencies,这里我创建了一个用户,这是我的应用程序的功能 当我通过填写表单创建用户时。单击注册后,它将重定向到仪表板页面,然后在该选项卡视图中显示所有注册用户的选项卡栏视图 但在这里我遇到了一个问题,我的用户已成功注册,但当我重定向到仪表板时,它将不会显示。如果我退出,然后重新登录后,它将显示在那里。您可以看到仪表板的图像 我不知道是商店更新问题还是其他什么问题。请帮助我你的小小帮助能让我开心 这是注册按钮点击事件 void _onBspSignupClick(BusinessDetailsViewM

这里我创建了一个用户,这是我的应用程序的功能

当我通过填写表单创建用户时。单击注册后,它将重定向到仪表板页面,然后在该选项卡视图中显示所有注册用户的选项卡栏视图

但在这里我遇到了一个问题,我的用户已成功注册,但当我重定向到仪表板时,它将不会显示。如果我退出,然后重新登录后,它将显示在那里。您可以看到仪表板的图像

我不知道是商店更新问题还是其他什么问题。请帮助我你的小小帮助能让我开心

这是注册按钮点击事件

  void _onBspSignupClick(BusinessDetailsViewModel bdVm) async {
    setState(() {
      _isLoading = true;
      _countryId = int.parse(bdVm.user.user.country.id);
    });

    List<BusinessProfilePicture> bspPictures =
        widget.bspSignupCommonModel.businessProfilePictures;

    Map restProfilePicturesMap = await _restFileUploadResponse(bspPictures);

    Map restDocumentsMap;
    if (widget.bspSignupCommonModel.isLicensed) {
      restDocumentsMap = await _restFileUploadResponse(
          widget.bspSignupCommonModel.licensed[0].bspLicenseImages);
    } else {
      List<BusinessProfilePicture> unRegisteredImages = [
        ...widget.bspSignupCommonModel.unlicensed[0].bspLicenseImages,
        ...widget.bspSignupCommonModel.unlicensed[1].bspLicenseImages
      ];
      restDocumentsMap = await _restFileUploadResponse(unRegisteredImages);
    }

    Map<String, dynamic> bspSignupResponse;
    BSPSignupRepository _bspSignupRepository = BSPSignupRepository();

    if (widget.bspSignupCommonModel.businessId != null) {
      // Create branch
      int businessId = widget.bspSignupCommonModel.businessId;
      print('businessId = $businessId');
      print('create the branch instead of the business');
      Map<String, dynamic> branchQueryMap =
          _createBranchQuery(restProfilePicturesMap, restDocumentsMap);
      print('branchQueryMap = $branchQueryMap');
      String token = bdVm.user.token;
      print('token = $token');
      bspSignupResponse = await _bspSignupRepository.createBranchOfBusiness(
          branchQueryMap, token);
    } else {
      // Create business
      Map<String, dynamic> bspUserSignUpMap =
          _createBusinessQuery(restProfilePicturesMap, restDocumentsMap);

      print('bspUserSignUpMap = $bspUserSignUpMap');
      String token = bdVm.user.token;
      print('token = $token');
      bspSignupResponse =
          await _bspSignupRepository.createMyBusiness(bspUserSignUpMap, token);
    }

    setState(() {
      _isLoading = false;
    });

    _postBspCreationActions(bspSignupResponse, bdVm);
  }


  _postBspCreationActions(
    Map<String, dynamic> bspSignupResponse,
    BusinessDetailsViewModel bdVm,
  ) async {
    print('bspSignupResponse');
    print(bspSignupResponse);
    if (bspSignupResponse['error'] != null) {
      var errors = bspSignupResponse['error'][0];
      print('errors $errors');
      String errorMsg = errors.message;
      print('errorMsg $errorMsg');
      var redirectTo = false;
      _showDialogOnGQLFinished(
        context,
        'Error',
        errorMsg,
        redirectTo,
      );
    } else {
      var redirectTo = true;
      _updateStoreValue(bspSignupResponse, bdVm);
      _showDialogOnGQLFinished(
        context,
        'Done',
        'Thank you for signing up',
        redirectTo,
      );
    }
  }



 _updateStoreValue(
    Map<String, dynamic> bspSignupResponse,
    BusinessDetailsViewModel bdVm,
  ) async {
    try {
      LoginRepository _loginRepository = LoginRepository();
      SharedPreferences preferences = await SharedPreferences.getInstance();
      bool rememberMe = preferences.getBool('rememberMe');
      Map<String, dynamic> dashboardItems =
          await _loginRepository.getDashboardItems(bdVm.user.token);

      if (dashboardItems['error'] != null) {
        print('Fail to fetch the dashboard items from the business details');
        print(dashboardItems['error']);
      } else {
        setState(() async {
          DashboardItems dashboardItemsModel =
              DashboardItems.fromJson(dashboardItems['data']);
          // Update the User in store
          LoginUser userModel = LoginUser(
            token: bdVm.user.token,
            user: User.fromJson(
              bspSignupResponse['data']['createBusiness']['user'],
            ),
          );
          SharedPreferences preferences = await SharedPreferences.getInstance();
          preferences.setString(
            'token',
            bdVm.user.token,
          );
          bdVm.setBspUser(context, userModel);
          bdVm.setDashboardItems(context, dashboardItemsModel);
          if (rememberMe) {
            preferences.setString('user', loginUserToJson(userModel));
            preferences.setString(
              'dashboarditems',
              dashboardItemsToJson(dashboardItemsModel),
            );
          }
        });
      }
    } catch (e) {
      print('error while loading the dashboard $e');
    }
  }
void\u onBspSignupClick(BusinessDetailsViewModel bdVm)异步{
设置状态(){
_isLoading=true;
_countryId=int.parse(bdVm.user.user.country.id);
});
列出图片=
widget.bspSignupCommonModel.businessProfilePictures;
Map restProfilePicturesMap=wait _restFileUploadResponse(bspPictures);
地图地图;
if(widget.bspSignupCommonModel.isLicensed){
restDocumentsMap=等待_restFileUploadResponse(
widget.bspSignupCommonModel.licensed[0].bspLicenseImages);
}否则{
列出未注册的图像=[
…widget.bspSignupCommonModel.unlicensed[0]。bspLicenseImages,
…widget.bspSignupCommonModel.unlicensed[1]。bspLicenseImages
];
restDocumentsMap=等待_restFileUploadResponse(注销图像);
}
映射bspSignupResponse;
bspsinguprepository_bspsinguprepository=bspsinguprepository();
if(widget.bspSignupCommonModel.businessId!=null){
//创建分支
int businessId=widget.bspSignupCommonModel.businessId;
打印('businessId=$businessId');
打印(“创建分支机构而不是业务”);
映射分支查询映射=
_createBranchQuery(restProfilePicturesMap、restDocumentsMap);
打印('branchQueryMap=$branchQueryMap');
字符串令牌=bdVm.user.token;
打印('token=$token');
bspSignupResponse=等待bspSignupRepository.createBranchOfBusiness(
branchQueryMap,令牌);
}否则{
//创业
映射bspUserSignUpMap=
_createBusinessQuery(restProfilePicturesMap、restDocumentsMap);
打印('bspUserSignUpMap=$bspUserSignUpMap');
字符串令牌=bdVm.user.token;
打印('token=$token');
bspSignupResponse=
wait bspSignupRepository.createMyBusiness(bspUserSignUpMap,令牌);
}
设置状态(){
_isLoading=false;
});
_BSP创建后操作(bspSignupResponse,bdVm);
}
_创作后活动(
映射到每个响应,
BusinessDetailsViewModel bdVm,
)异步的{
打印('bspSignupResponse');
打印(bspSignupResponse);
如果(bspSignupResponse['error']!=null){
var errors=bspSignupResponse['error'][0];
打印('errors$errors');
字符串errorMsg=errors.message;
打印('errorMsg$errorMsg');
var redirectTo=false;
_showDialogOnGQLFinished(
上下文
“错误”,
errorMsg,
重定向到,
);
}否则{
var redirectTo=true;
_更新重新评估(bspSignupResponse,bdVm);
_showDialogOnGQLFinished(
上下文
“完成”,
“感谢您的注册”,
重定向到,
);
}
}
_更新重新估价(
映射到每个响应,
BusinessDetailsViewModel bdVm,
)异步的{
试一试{
LoginRepository _LoginRepository=LoginRepository();
SharedReferences首选项=等待SharedReferences.getInstance();
bool rememberMe=preferences.getBool('rememberMe');
映射仪表板项=
wait _loginRepository.getDashboardItems(bdVm.user.token);
if(仪表板项['error']!=null){
打印(“无法从业务详细信息中获取仪表板项目”);
打印(仪表板项目['error']);
}否则{
setState(()异步{
仪表板项目仪表板项目模型=
fromJson(DashboardItems['data']);
//更新存储中的用户
LoginUser用户模型=LoginUser(
令牌:bdVm.user.token,
用户:user.fromJson(
bspSignupResponse['data']['createBusiness']['user'],
),
);
SharedReferences首选项=等待SharedReferences.getInstance();
preferences.setString(
“代币”,
bdVm.user.token,
);
setBspUser(上下文,用户模型);
setDashboardItems(上下文,dashboardItemsModel);
如果(记住){
setString('user',loginUserToJson(userModel));
preferences.setString(
“仪表板项目”,
dashboardItemsToJson(dashboardItemsModel),
);
}
});
}
}捕获(e){
打印(“加载仪表板$e时出错”);
}
}
这是仪表板屏幕

  List<Widget> _buildDashboards(BspTabViewModel bspTabViewModel) {
    List<Widget> dashboards = [];
    List<EmployeesByUserIdElement> employements =
        bspTabViewModel.employeements.employeesByUserId;
    for (int i = 0; i < employements.length; i++) {
      dashboards.add(BSPDashboardTab());
    }
    return dashboards;
  }

  List<Widget> _buildTabs(BspTabViewModel bspTabViewModel) {
    Orientation orientation = MediaQuery.of(context).orientation;
    List<Tab> tabs = [];
    List<EmployeesByUserIdElement> employements =
        bspTabViewModel.employeements.employeesByUserId;
    print("================Employements ====================");
    print(employements);
    for (int i = 0; i < employements.length; i++) {
      tabs.add(
        Tab(
          child: Text(
            employements[i].branch.name,
            style: TextStyle(
              fontSize: orientation == Orientation.portrait
                  ? MediaQuery.of(context).size.width * 0.040
                  : MediaQuery.of(context).size.width * 0.035,
            ),
          ),
        ),
      );
    }
    return tabs;
  }

  Widget content(BuildContext context, BspTabViewModel bspTabViewModel) {
    Orientation orientation = MediaQuery.of(context).orientation;
    if (bspTabViewModel.employeements != null) {
      return DefaultTabController(
        length: bspTabViewModel.employeements.employeesByUserId.length,
        child: Scaffold(
          appBar: new PlatformAdaptiveAppBar(
              backgroundColor: bspcolorStyles['primary'],
              bottom: TabBar(
                isScrollable: true,
                indicatorColor: Colors.black,
                unselectedLabelColor: Colors.black.withOpacity(0.5),
                tabs: _buildTabs(bspTabViewModel),
              ),
              title: new Text(
                "Dashboard",
                style: TextStyle(
                  color: Colors.black,
                  fontSize: orientation == Orientation.portrait
                      ? MediaQuery.of(context).size.width * 0.050
                      : MediaQuery.of(context).size.width * 0.035,
                  fontWeight: FontWeight.bold,
                ),
              ),
              platform: Theme.of(context).platform),
          body: TabBarView(
            children: _buildDashboards(bspTabViewModel),
          ),
          drawer: new BspMainDrawer(),
        ),
      );
    }
    return FadeInUi();
  }


  @override
  Widget build(BuildContext context) {
    return new StoreConnector<AppState, BspTabViewModel>(
        converter: (Store<AppState> store) => BspTabViewModel.fromStore(store),
        onInit: (Store<AppState> store) async {
          await _showEmployementDialog(store);
        },
        builder: (BuildContext context, BspTabViewModel bspTabViewModel) {
          return StreamBuilder(builder: (context, snapshot) {
            return content(context, bspTabViewModel);
          });
        });
  }
List\u构建仪表板(BspTabViewModel BspTabViewModel){
列表仪表板=[];
列出雇员名单=
bspTabViewModel.employeements.employeesByUserId;
对于(int i=0;i