程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Ckeckbox 不会改变状态大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Ckeckbox 不会改变状态?

开发过程中遇到Ckeckbox 不会改变状态的问题如何解决?下面主要结合日常开发的经验,给出你关于Ckeckbox 不会改变状态的解决方法建议,希望对你解决Ckeckbox 不会改变状态有所启发或帮助;

我有一个奇怪的错误。当我显示表单时,我会得到一个布尔值来填充复选框。如果数据库中的值为 0,我可以检查并取消选中它,它运行良好,但如果值为 1,则复选框显示为已选中(正常结果),但我无法取消选中它。我使用数据库中的时事通讯值来检查或不检查开头的复选框。我认为问题可能出在那里,我使用 setstate 刷新小部件和通讯变量的新值,但它使用“选中”的数据库值并删除由复选框检查事件更改的通讯的值。所以问题似乎是,当我显示表单时,我将名为 newsletter 的变量的值设置为数据库的值,但通常我只需要在页面初始化时这样做,我该怎么做?

@H_450_5@if (values.newsletter=="1") {
    newsletter=true;
}
else {
    newsletter=false;
}

这是我的代码:

@H_450_5@import 'package:Flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'menu_member.dart';
import 'globals.dart' as globals;
import 'appbar_draw.dart';
import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:Font_awesome_Flutter/Font_awesome_Flutter.dart';
import 'package:email_valIDator/email_valIDator.dart';
import 'package:awesome_page_@R_403_3721@s/awesome_page_@R_403_3721@s.dart';

// Create a Form Widget.
class Affiche_Profil extends StatefulWidget {
  @overrIDe

  _Affiche_Profil_State createState() {
    return _Affiche_Profil_State();
  }
}

// Create a corresponding State class.
// This class holds data related to the form.

class _Affiche_Profil_State extends State<Affiche_Profil> {
  @overrIDe

  final _formKey = GlobalKey<FormState>();
  bool newsletter=false;
  final _emailController=TextEdiTingController();
  Future <user> profil;

  Future <user> display_Profil () async {
    // SERVER LOGIN API URL
    var url = 'https://www.fortune-island.com/app/info_profil.php';

    var data = {
      'ID_membre': globals.ID_membre,};

    var data_encode = JsonEncode(data);
    // StarTing Web API Call.
    var response = await http.post(url,body: data_encode,headers: {'content-type': 'application/Json','accept': 'application/Json','authorization': globals.token});

    // GetTing Server responsE into variable.

    var Jsondata = Json.decode(response.body);

    user profile=user(Jsondata["pseudo"],Jsondata["email"],Jsondata["newsletter"]);
    return profile;
  }

  voID initState() {
    profil = display_Profil();
    super.initState();
  }

  @overrIDe
  Widget build(BuildContext context) {
    return Stack(
        children: <Widget>[
          Container(
            decoration: Boxdecoration(
              gradIEnt: linearGradIEnt(
                begin: Alignment.topleft,end: Alignment.bottomright,colors: <color>[
                  colors.blue[300],colors.blue[400]
                ],),Scaffold(
              appbar: drawappbar(true),BACkgroundcolor: colors.transparent,drawer: new DrawerOnly(classname: Affiche_Profil()),body:
              Container(
                  height: Mediaquery
                      .of(context)
                      .size
                      .height,wIDth: Mediaquery
                      .of(context)
                      .size
                      .wIDth,child:
                    FutureBuilder(
                        future: profil,builder: (BuildContext context,AsyncSnapshot snapshot) {
                          switch (snapshot.connectionStatE) {
                            case ConnectionState.waiTing:
                              return new Center(
                                child: new CircularProgressInDicator(),);
                            default:
                              if (snapshot.hasError) {
                                return new Center(
                                  child: new Text('Error: ${snapshot.error}'),);
                              }
                              else {
                                user values = snapshot.data;
                                if (snapshot.hasData==falsE) {
                                  return Container(
                                      child: Center(
                                          child: Text("Données inaccessible !!!",style: TextStyle(color: colors.whitE))
                                      )
                                  );
                                }
                                else {
                                  _emailController.text=values.email;
                                  if (values.newsletter=="1") {
                                    newsletter=true;
                                  }
                                  else {
                                    newsletter=false;
                                  }
                                  return Form(
                                      key: _formKey,autovalIDate: true,child:
                                    ListVIEw(
                                      children: <Widget>[
                                        Center(
                                          child: Container(
                                              margin: const EdgeInsets.only(top: 20.0),child: Text("VOS INFOS",textAlign: TextAlign.center,style: TextStyle(FontSize: 30.0,color: colors.whitE))
                                          ),padding(
                                        padding: const EdgeInsets.only(top:8.0),child:
                                        TextFormFIEld(
                                          autofocus: true,obscureText: false,controller: _emailController,decoration: inputdecoration(
                                            border: Outlineinputborder(
                                                borderRadius: borderRadius.circular(32.0)
                                            ),fillcolor: colors.white,filled: true,icon: Icon(Icons.email,color: colors.whitE),hintText: "Entrez votre email",contentpadding: EdgeInsets.fromLTRB(20.0,10.0,20.0,10.0),hintStyle: TextStyle(color: colors.grey[500],FontSize: 10),valIDator: (value) {
                                            if (value.isEmpty) {
                                              return 'Entrez votre email';
                                            }
                                            if (!EmailValIDator.valIDate(value)) {
                                              return 'Email non valIDe';
                                            }
                                            return null;
                                          },child:
                                        checkBoxListTile(
                                        title: Text("Newsletter :",style: TextStyle(color: colors.whitE)),value: newsletter,onChanged: (bool newvalue) {
                                            setState(() {
                                                newsletter = newValue;
                                            });
                                          }
                                        ),child :
                                        Center(
                                          child: Container(
                                            wIDth:Mediaquery.of(context).size.wIDth,height:45,child: Raisedbutton(
                                              color: colors.green,textcolor: colors.white,padding: EdgeInsets.fromLTRB(9,9,9),child: Text('ModifIEr'),shape: RoundedRectangleborder(
                                                  borderRadius: borderRadius.circular(25)
                                              ),onpressed: () {
                                                // ValIDate returns true if the form is valID,or false
                                                // otherwise.
                                                if (_formKey.currentState.valIDate()) {
                                                  ModifyInfos();
                                                }
                                                else {
                                                  return null;
                                                }
                                              },//    <-- label
                                      ]
                                  )
                                  );
                                }
                              }
                          }
                        }
                    )
                  )
              )
        ]
    );
  }
  Future ModifyInfos() async{
    // GetTing value from Controller
    String email = _emailController.text;

    var url = 'https://www.fortune-island.com/app/modify_profil.php';
    // Store all data with Param name.
    String etatnews="0";
    if (newsletter==truE) {
      etatnews="1";
    }
    var data = {'ID_membre':globals.ID_membre,'email': email,'news': etatnews};

    var data_encode=JsonEncode(data);
    print(data_encodE);
    // StarTing Web API Call.
    var response = await http.post(url,'authorization': globals.token});
    print(response.body);
    Map <String,dynamic> map = Json.decode(response.body);
    if(map["status"] == 1)
    {
      AwesomeDialog(context: context,useRootNavigator: true,dialogType: DialogType.succes,animType: AnimType.bottOMSLIDE,tittle: 'MODIFICATION DU PROFIL',desc: map["libelle"],btnOkOnPress: () {
            setState(() {
              profil = display_Profil();
            });
          }).show();
    }else{
      // If Email or password dID not Matched.
      // Showing Alert Dialog with Response JsON message.
      AwesomeDialog(context: context,dialogType: DialogType.INFO,tittle: 'informatIONS INCHANGEES',btnOkOnPress: () {
            setState(() {
              profil = display_Profil();
            });
          }).show();
    }
  }
}

class user {

  final String pseudo;
  final String email;
  final String newsletter;

  const user(this.pseudo,this.email,this.newsletter);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Ckeckbox 不会改变状态全部内容,希望文章能够帮你解决Ckeckbox 不会改变状态所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: