如何解决“ SocketException:操作系统错误:连接超时错误编号110,地址= 000.000.0.00,端口= 44935”的问题

时间:2019-08-28 10:51:25

标签: php mysql flutter dart

我正在创建一个页面,供用户输入详细信息,然后在用户输入详细信息后,将其插入MySQL数据库,当我使用PHP表单进行检查时,代码工作正常,但是在主文件,出现此错误。

未处理的异常:SocketException:操作系统错误:连接超时,errno = 110,地址= 000..000.0.000,端口= 44935

我正在使用系统的IP地址代替本地主机。

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'Design.dart';
import 'dart:async';
//import 'dart:io';


class UsersProfile extends StatefulWidget {
  @override
  _UsersProfileState createState() => _UsersProfileState();
}

class _UsersProfileState extends State<UsersProfile> {

  //textediting controllers name, this is the name of textfield to pick up the data from each field.

  TextEditingController nameController = TextEditingController();  
  TextEditingController genderController = TextEditingController();
  TextEditingController ageController = TextEditingController();


  var isLoading = false;   // loader should be false in starting.

  String url = "http://LocalHost/flutter_include/insert.php";   // location of the query file

//this is the onpress function for raised button,
// where first we set the loading to true.

  _passValues(){ 
  setState(() {


    isLoading = true;
    sendform();

  });
}


Future<String> sendform() async{

  Map data = {

    "first": nameController.text,
    "gender": genderController.text,
    "age": ageController.text
  };
print(data);
  var result= json.encode(data);

   var resp = await http.post(url,
   headers: {"content-type": "application/json; charset=utf-8"},
   body: result);

   var finalResult = json.decode(resp.body);
  print(finalResult);
   setState(() {
    isLoading = false; 
   });
}



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        flexibleSpace: gradientAppBar(),
        title: Icon(Icons.book,
        color: Colors.white,
        ),
      ),
      body: Stack(
        children: <Widget>[
         //MyClipper(),

          Column(
            //mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(30.0),
                child: TextField(
                  keyboardType: TextInputType.text,
                  controller: nameController,
                  decoration: InputDecoration(
                    hintText: 'Full Name',


                  ),
                ),
              ),
                Padding(
                padding: const EdgeInsets.all(30.0),
                child: TextField(
                  keyboardType: TextInputType.number,
                  controller: ageController,
                  decoration: InputDecoration(
                    hintText: 'Age',


                  ),
                ),
              ),
                Padding(
                padding: const EdgeInsets.all(30.0),
                child: TextField(
                  keyboardType: TextInputType.text,
                  controller: genderController,
                  decoration: InputDecoration(
                    hintText: 'Gender',


                  ),
                ),
              ),
              RaisedButton(
                onPressed: _passValues,
                child: Text('Save',
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
                ),
                color: Colors.indigo,
              )
            ],
          )
        ],
      )
    );
  }
}

0 个答案:

没有答案