Flutter 重置密码后保留数据

Flutter 重置密码后保留数据,flutter,dart,Flutter,Dart,我在做颤振项目。我创建了一个简单的函数来更改密码。它的作品很好,但(密码更改正确),但我不能保持我的实际屏幕后,密码更改。如你所见,我丢失了所有数据。我的问题是如何在更改密码后将数据保存在屏幕中 密码屏幕: 密码更改后的我的屏幕: 这是我的代码: Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; return SafeArea( /* minimum:

我在做颤振项目。我创建了一个简单的函数来更改密码。它的作品很好,但(密码更改正确),但我不能保持我的实际屏幕后,密码更改。如你所见,我丢失了所有数据。我的问题是如何在更改密码后将数据保存在屏幕中

密码屏幕:

密码更改后的我的屏幕:

这是我的代码:

  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    return SafeArea(
        /* minimum: const EdgeInsets.only(
            top: 20.0, right: 5.0, left: 5.0, bottom: 10.0),*/
        child: Center(
      child: Scaffold(
          resizeToAvoidBottomInset: true,
          backgroundColor: Color(0xFFF6F7F8),
          body: SingleChildScrollView(
              child: Form(
                  key: _formKey,
                  child: FutureBuilder<User>(
                      future: boxApi.getUser(),
                      builder: (context, snapshot) {
                        // ignore: missing_return
                        print(snapshot.data);
                        switch (snapshot.connectionState) {
                          case ConnectionState.none:
                            return Text('no connection');
                          case ConnectionState.active:
                          case ConnectionState.waiting:
                            return Center(
                              child: CircularProgressIndicator(),
                            );
                            break;
                          case ConnectionState.done:
                            if (snapshot.hasError) {
                              return Text('error');
                            } else if (snapshot.hasData) {
                              // String price = snapshot.data['body'].;
                              //  print("${snapshot.data}");
                              return Column(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceEvenly,
                                children: [
                                  Container(
                                    padding: EdgeInsets.only(top: 16),
                                    width: MediaQuery.of(context).size.width,
                                    height:
                                        MediaQuery.of(context).size.height / 4,
                                    decoration: BoxDecoration(
                                        boxShadow: [
                                          BoxShadow(
                                              color: Colors.white60,
                                              blurRadius: 15.0,
                                              offset: Offset(0.0, 0.75))
                                        ],
                                        gradient: LinearGradient(
                                          begin: Alignment(0.5, 0.85),
                                          end: Alignment(0.48, -1.08),
                                          colors: [
                                            const Color(0xFF0B0C3A),
                                            const Color(0xFF010611),
                                          ],
                                          stops: [
                                            0.0,
                                            0.5,
                                          ],
                                        ),
                                        //color: blue,
                                        borderRadius: BorderRadius.only(
                                            bottomRight: Radius.circular(32),
                                            bottomLeft: Radius.circular(32))),
                                    child: Column(
                                      children: [
                                        Row(
                                          children: [
                                            SizedBox(
                                              width: 30,
                                            ),
                                            Column(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                children: [
                                                  Text(
                                                    "${snapshot.data.name}",
                                                    style: TextStyle(
                                                        color: Colors.white,
                                                        fontSize: 25,
                                                        fontWeight:
                                                            FontWeight.bold),
                                                  ),
                                                  SizedBox(
                                                    height: 10,
                                                  ),
                                                  Text(
                                                    "${snapshot.data.phone}",
                                                    style: TextStyle(
                                                      color: Colors.white60,
                                                      fontSize: 18,
                                                      //fontWeight: FontWeight.w300
                                                    ),
                                                  ),
                                                ])
                                          ],
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.end,
                                          children: [
                                            Container(
                                                margin: EdgeInsets.symmetric(
                                                    vertical: 10),
                                                width: size.width * 0.4,
                                                child: ElevatedButton(
                                                  /*onPressed: () => [
                                                    modifyUserName(),
                                                    //  modifyUserEmail(),
                                                    //   modifyUserAdress()
                                                  ],*/
                                                  onPressed: () {
                                                    editUserProfile();
                                                    //   modifyUserEmail();
                                                  },
                                                  child: Text('Enregistrer'),
                                                  style:
                                                      ElevatedButton.styleFrom(
                                                    primary: Colors.transparent,
                                                    shape:
                                                        RoundedRectangleBorder(
                                                            borderRadius:
                                                                BorderRadius
                                                                    .circular(
                                                                        20),
                                                            side: BorderSide(
                                                                color: Colors
                                                                    .white)),
                                                  ),
                                                )),
                                            SizedBox(
                                              width: 20,
                                            ),
                                          ],
                                        )
                                      ],
                                    ),
                                  ),
                                  Container(
                                    height: MediaQuery.of(context).size.height /
                                        1.5,
                                    // padding: EdgeInsets.only(
                                    //   top: 32,
                                    // ),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      children: [
                                        Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Container(
                                              width: size.width * 0.94,
                                              child: Column(
                                                mainAxisAlignment:
                                                    MainAxisAlignment.start,
                                                children: [
                                                  Container(
                                                    padding: EdgeInsets.only(
                                                        left: 10,
                                                        right: 10,
                                                        bottom: 20,
                                                        top: 20),
                                                    child: Column(
                                                      mainAxisAlignment:
                                                          MainAxisAlignment
                                                              .start,
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .start,
                                                      children: [
                                                        Row(
                                                          mainAxisAlignment:
                                                              MainAxisAlignment
                                                                  .spaceBetween,
                                                          children: [
                                                            Text(
                                                              'Votre nom :',
                                                              style: TextStyle(
                                                                  color: Color(
                                                                      0xFF4053FCF),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w600),
                                                            ),
                                                            IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .pencil,
                                                                  color: Colors
                                                                      .grey,
                                                                ),
                                                                onPressed: () {
                                                                  myFocusNode
                                                                      .requestFocus();
                                                                  //    setState(() {
                                                                  enableup =
                                                                      true;
                                                                  //    });
                                                                })
                                                          ],
                                                        ),
                                                        TextFormField(
                                                          controller:
                                                              _nameController,
                                                          enabled: enableup,
                                                          focusNode:
                                                              myFocusNode,
                                                          enableInteractiveSelection:
                                                              false,
                                                          keyboardType:
                                                              TextInputType
                                                                  .text,
                                                          decoration: InputDecoration(
                                                              hintText:
                                                                  "${snapshot.data.name}",
                                                              hintStyle: TextStyle(
                                                                  color: Colors
                                                                      .grey,
                                                                  fontSize:
                                                                      14.0)),
                                                        ),
                                                        SizedBox(
                                                          height: 15,
                                                        ),
                                                        
                                                      
                                                       
                                                        Row(
                                                          mainAxisAlignment:
                                                              MainAxisAlignment
                                                                  .spaceBetween,
                                                          children: [
                                                            Text(
                                                              'Mot de passe :',
                                                              style: TextStyle(
                                                                  color: Color(
                                                                      0xFF4053FCF),
                                                                  fontSize: 16,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w600),
                                                            ),
                                                            IconButton(
                                                                icon: Icon(
                                                                  CommunityMaterialIcons
                                                                      .pencil,
                                                                  color: Colors
                                                                      .grey,
                                                                ),
                                                                onPressed:
                                                               () async {
                                                                  await cahngePwd(
                                                                      context);
                                                                })
                                                          ],
                                                        ),
                                                        TextFormField(
                                                          enabled: enablepwd,
                                                          focusNode:
                                                              passwordNode,
                                                          enableInteractiveSelection:
                                                              false,
                                                          obscureText: true,
                                                          keyboardType:
                                                              TextInputType
                                                                  .text,
                                                          decoration: InputDecoration(
                                                              hintText:
                                                                  "*************",
                                                              hintStyle: TextStyle(
                                                                  color: Colors
                                                                      .grey,
                                                                  fontSize:
                                                                      14.0)),
                                             
                            } else {
                              return Text('No Data');
                            }
                            break;
                          default:
                            return Container();
                            break;
                        }
                      }

  }
 void changePassword() async {
    setState(() {});
    String old_password = _oldController.text;
    String new_password = _newController.text;
    String confirm_password = _confirmController.text;

    try {
      await userApi.changePassword(
          old_password, new_password, confirm_password);
    } catch (err) {
      print(err.toString());
      // Todo: add Snackbar
    }

    Navigator.of(context).pop(); // Dismiss alert dialog
    setState(() {});
小部件构建(构建上下文){
Size Size=MediaQuery.of(context).Size;
返回安全区(
/*最小值:仅限常量边设置(
顶部:20.0,右侧:5.0,左侧:5.0,底部:10.0)*/
儿童:中心(
孩子:脚手架(
resizeToAvoidBottomInset:true,
背景颜色:颜色(0xFFF6F7F8),
正文:SingleChildScrollView(
孩子:表格(
键:_formKey,
孩子:未来建设者(
future:boxApi.getUser(),
生成器:(上下文,快照){
//忽略:缺少返回
打印(快照数据);
交换机(快照.连接状态){
案例连接状态。无:
返回文本(“无连接”);
案例连接状态.active:
案例连接状态。正在等待:
返回中心(
子对象:CircularProgressIndicator(),
);
打破
案例连接状态。完成:
if(snapshot.hasError){
返回文本('error');
}else if(snapshot.hasData){
//字符串price=snapshot.data['body']。;
//打印(“${snapshot.data}”);
返回列(
主轴对准:
MainAxisAlignment.space,
儿童:[
容器(
填充:仅限边缘设置(顶部:16),
宽度:MediaQuery.of(context).size.width,
高度:
MediaQuery.of(context).size.height/4,
装饰:盒子装饰(
boxShadow:[
箱形阴影(
颜色:Colors.white60,
半径:15.0,
偏移量:偏移量(0.0,0.75))
],
梯度:线性梯度(
开始:对齐(0.5,0.85),
结束:对齐(0.48,-1.08),
颜色:[
常量颜色(0xFF0B0C3A),
常量颜色(0xFF010611),
],
停止:[
0.0,
0.5,
],
),
//颜色:蓝色,
borderRadius:仅限borderRadius(
右下角:半径。圆形(32),
左下角:半径。圆形(32)),
子:列(
儿童:[
划船(
儿童:[
大小盒子(
宽度:30,
),
纵队(
横轴对齐:
CrossAxisAlignment.start,
儿童:[
正文(
“${snapshot.data.name}”,
样式:TextStyle(
颜色:颜色,白色,
尺寸:25,
容重:
字体(粗体),
),
大小盒子(
身高:10,
),
正文(
“${snapshot.data.phone}”,
样式:TextStyle(
颜色:Colors.white60,
尺码:18,
//fontWeight:fontWeight.w300
),
),
])
],
),
划船(
主轴对准:
     void changePassword() async {
        setState(() {});
        String old_password = _oldController.text;
        String new_password = _newController.text;
        String confirm_password = _confirmController.text;
    
        try {
          await userApi.changePassword(
              old_password, new_password, confirm_password);
        } catch (err) {
          print(err.toString());
          // Todo: add Snackbar
        }
//Added this:
     Navigator.pushReplacement(
                  context,
                  MaterialPageRoute(builder: (context) => YourProfilePage()),
                );
        Navigator.of(context).pop(); // Dismiss alert dialog
        setState(() {});