没有从颤动的范围滑块中获得价值

时间:2021-05-25 12:21:06

标签: flutter

我想将贷款金额请求保存到数据库。但是当我将其保存到数据库时,结果为 0(电子邮件被感知) enter image description here

这是我的贷款金额请求范围值

RangeValues loanamountrequest = const RangeValues(1000000, 50000000);

这是我的贷款金额请求小部件构建

    Text(
              "Loan Amount Request"
          ),
RangeSlider(
values: RangeValues(loanamountrequest.start,loanamountrequest.end),
min: 1000000,
max: 50000000,
divisions: 10,
labels: RangeLabels(
loanamountrequest.start.round().toString(),
loanamountrequest.end.round().toString(),
),
onChanged: (RangeValues values) {
  setState(() {
    loanamountrequest = values;
  });
}),
          Text(
              "Interest :"  + interest
          ),
          SizedBox(
            height: 20.0,
          ),
          Text(
             "DP : " +  DP
          ),
          SizedBox(
            height: 20.0,
          ),
          TextFormField(
            validator: (value) {
              if (value.isEmpty) {
                return 'Reason cannot be empty';
              }
              return null;
            },
            onSaved: (value) => reason = value,
            decoration: kTextFieldDecoration.copyWith(
              hintText: 'Reason',
            ),
          ),

          FullWidthRoundButton(
            textButton: 'Submit Form',
            getPressed: () {
              check(); //this process is save to database from API
      

这是保存在数据库中时的值 enter image description here

这是提交异步函数

 void check() {
    final form = _key.currentState;
    if (form.validate()) {
      form.save();
      submit();
    }
  }

  void submit() async {
    LoanFormModel loanFormModel;
    await LoanFormModel.submit(
        email: emailAPI,
        periodtime : periodtime,
        loanamountrequest: loanamountrequest.toString(),
        totalloanamountrequest: totalloanamountrequest,
        interest: interest,
        reason : reason,
        url: BaseURL.kInsertLoan)
        .then((value) => loanFormModel = value);
    print(loanFormModel.success);
    _scaffoldKey.currentState.showSnackBar(SnackBar(
      content: Text(loanFormModel.message),
      duration: Duration(seconds: 10),
    ));
    if (loanFormModel.success == 1) {
      Text(loanFormModel.message);
    } else {
      _scaffoldKey.currentState.showSnackBar(SnackBar(
        content: Text(loanFormModel.message),
        duration: Duration(seconds: 3),
      ));
    }
  }

这里是提交

 static Future<LoanFormModel> submit(
      {String email, String periodtime, String interest, String loanamountrequest, String totalloanamountrequest, String reason, String url}) async {
    var response;
    if (email != null && periodtime != null) {
      response = await http.post(url, body: jsonEncode(<String, String>{
        'email': email,
        'product_id': "1",
        'loan_status_id': "1",
        'AgreementDate': "2021-05-24",
        'DisbursementDate': "2021-05-24",
        'periodtime': periodtime,
        'interest': interest,
        'amount_without_interest': loanamountrequest,
        'totalamount': totalloanamountrequest,
        'LoanQuality': "Good",
        'LoanStatus': "In Process",
        'Reason': reason
      }));
      if (response.statusCode == 200) {
        print(json.decode(response.body));
      } else {
        print(response.statusCode);
      };
      return LoanFormModel.fromJson(jsonDecode(response.body));
    }
    response = await http.post(url, body: {
      'email': "${email}",
      'product_id': "1",
      'loan_status_id': "1",
      'AgreementDate': "2021-05-24",
      'DisbursementDate': "2021-05-24",
      'periodtime': "${periodtime}",
      'interest': "${interest}",
      'amount_without_interest': "${loanamountrequest}",
      'totalamount': "${totalloanamountrequest}",
      'LoanQuality': "Good",
      'LoanStatus': "In Process",
      'Reason': reason
    });
    return LoanFormModel.fromJson(jsonDecode(response.body));
  }

如何解决这个错误?这是我的模型还是什么?

0 个答案:

没有答案