Как я могу проверить и отправить данные в базу данных из этой формы во флаттере

Я создал эту форму, используя текстовое поле, дату и раскрывающееся меню во флаттере

Я хочу проверить и отправить данные из формы в базу данных mysql, я выяснил, как войти и зарегистрироваться в mysql, но не могу найти никакой помощи, чтобы получить данные из его формы и проверить ее, я знаю, как проверить textFormField, но не Не знаю, как проверить датупикер или раскрывающееся меню, пожалуйста, помогите!!.

Не публиковать полный код из-за ограничения в 30000 символов:/

Это код FormPage:/

вы можете просмотреть полный код здесь

https://drive.google.com/file/d/1UQsbXMQGoGrofOXfkyBrtYm3ngS5HPl2/view?usp=sharing

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:zaireeen/buttons/BookButton.dart';
import 'package:zaireeen/views/Home.dart';
import 'package:zaireeen/views/Signin.dart';
import 'package:http/http.dart' as http;


class Booking extends StatefulWidget {

Booking({Key key}) : super(key: key);

  @override
  _BookingState createState() => _BookingState();
}

class _BookingState extends State<Booking> {

  MediaQueryData queryData;

  DateTime birthDate = DateTime.now();

  Future<Null> _selectBirthDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: birthDate,
        firstDate: DateTime(1950, 8),
        lastDate: DateTime(2022));
    if (picked != null && picked != birthDate)
      setState(() {
        birthDate = picked;
      });
  }

  DateTime issueDate = DateTime.now();

  Future<Null> _selectIssueDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: issueDate,
        firstDate: DateTime(2000, 8),
        lastDate: DateTime(2022));
    if (picked != null && picked != issueDate)
      setState(() {
        issueDate = picked;
      });
  }

  DateTime expiryDate = DateTime.now();

  Future<Null> _selectExpiryDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: expiryDate,
        firstDate: DateTime(2000, 8),
        lastDate: DateTime(2060));
    if (picked != null && picked != expiryDate)
      setState(() {
        expiryDate = picked;
      });
  }

  String nationalityValue1 = 'Select';
  String genderValue1 = 'Select';
  String dropdownValue2 = 'Free';
  String packageValue1 = 'Select';
  String personValue1 = 'Select';

  bool agreeVal = false;

  @override
  Widget build(BuildContext context) {

    void onSigninPressed(BuildContext context) => Navigator.push(context, MaterialPageRoute(builder: (context) => Signin()));
    void onBookPressed(BuildContext context) => Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));

    final height = MediaQuery.of(context).size.height;
    final width = MediaQuery.of(context).size.width;

    queryData = MediaQuery.of(context);
    EdgeInsets devicePadding = MediaQuery.of(context).padding;

    return Scaffold(
      //backgroundColor: Color.fromRGBO(93, 142, 155, 1.0),
      body: Container(
          decoration: BoxDecoration
            (
            image: DecorationImage(
                image: AssetImage("assets/images/back.png"),
                fit: BoxFit.cover
            ),
          ),

          child: Stack(
            children: <Widget>[

              Positioned.fill(
                child: Align(
                  alignment: Alignment.center,
                  child: SingleChildScrollView(
                    padding: EdgeInsets.only(
                        left: 20.0, right: 20.0),
                    child: Container(
                      //alignment: Alignment.center,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: <Widget>[

                          SizedBox(height: 60,),

                          Text(
                            "Application Form",
                            style: TextStyle(
                              fontFamily: "FredokaOne",
                              //fontWeight: FontWeight.normal,
                              fontSize: queryData.size.width * 0.10,
                            ),
                          ),

                          SizedBox(height: 5,),

                          Text(
                            "(Kindly fill out every field with relevant data)",
                            style: TextStyle(
                              fontFamily: "FredokaOne",
                              color: Colors.red,
                              //fontWeight: FontWeight.normal,
                              fontSize: queryData.size.width * 0.025,
                            ),
                          ),

                          SizedBox(height: 0,),

                          Container(
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(15.0))
                              ),
                              child: Padding(
                                padding: const EdgeInsets.all(20),
                                child: Form(
                                    child: Column(
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      crossAxisAlignment: CrossAxisAlignment.center,
                                      children: <Widget>[

                                        TextFormField
                                          (
                                          validator: (value) {
                                            if (value.isEmpty) {
                                              return '*Invalid Name';
                                            }
                                            return null;
                                          },
                                          decoration: InputDecoration
                                            (
                                            labelText: "Full Name",
                                            hintText: "Full Name",
                                            hintStyle: TextStyle(
                                                fontFamily: "FredokaOne",
                                                fontSize: queryData.size.width * 0.035
                                            ),
                                            labelStyle: TextStyle(
                                              fontFamily: "FredokaOne",
                                              color: Colors.blueGrey,
                                              fontSize: queryData.size.width * 0.05,
                                            ),
                                          ),
                                        ),

                                        TextFormField
                                          (
                                          validator: (value) {
                                            if (value.isEmpty) {
                                              return '*required';
                                            }
                                            return null;
                                          },
                                          decoration: InputDecoration
                                            (
                                            labelText: "Father's Name",
                                            hintText: "Father's Name",
                                            hintStyle: TextStyle(
                                                fontFamily: "FredokaOne",
                                                fontSize: queryData.size.width * 0.035
                                            ),
                                            labelStyle: TextStyle(
                                              fontFamily: "FredokaOne",
                                              color: Colors.blueGrey,
                                              fontSize: queryData.size.width * 0.05,
                                            ),
                                          ),
                                        ),

                                        SizedBox(height: 20,),

                                        Row(
                                          children: <Widget>[

                                            Text(
                                              "Gender : ",
                                              style: TextStyle(
                                                color: Colors.blueGrey,
                                                fontFamily: "FredokaOne",
                                                //fontWeight: FontWeight.normal,
                                                fontSize: queryData.size.width * 0.05,
                                              ),
                                            ),

                                            SizedBox(width: 40,),

                                            DropdownButton<String>(
                                              elevation: 10,
                                              iconSize: 35,
                                              value: genderValue1,
                                              onChanged: (String newValue) {
                                                setState(() {
                                                  genderValue1 = newValue;
                                                });
                                              },

                                              items: <String>['Select', 'Male', 'Female', 'Other']
                                              .map<DropdownMenuItem<String>>((String value) {
                                                return DropdownMenuItem<String>(
                                                    value: value,
                                                    child: Text(
                                                      value,
                                                      style: TextStyle(
                                                        fontFamily: "FredokaOne",
                                                        //color: Colors.blueGrey,
                                                        //fontWeight: FontWeight.normal,
                                                        fontSize: queryData.size.width * 0.045,
                                                      ),
                                                    )
                                                );
                                              }).toList(),
                                            ),

                                          ],
                                        ),

                                        SizedBox(height: 10,),

                                        Row(
                                            children: <Widget>[
                                              Text(
                                                "Date Of Birth : ",
                                                textAlign: TextAlign.left,
                                                style: TextStyle(
                                                  color: Colors.blueGrey,
                                                  fontFamily: "FredokaOne",
                                                  //fontWeight: FontWeight.normal,
                                                  fontSize: queryData.size.width * 0.05,
                                                ),
                                              ),

                                              SizedBox(width: 10,),

                                      

                                              RaisedButton(
                                                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                                                elevation: 5,
                                                color: Colors.white,
                                                onPressed: () => _selectBirthDate(context),

                                                child: Container(
                                                  alignment: Alignment.center,
                                                  height: 30,
                                                  child: Row(
                                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                    children: <Widget>[
                                                      Row(
                                                        children: <Widget>[
                                                          Container(
                                                              child: Row(
                                                                children: <Widget>[
                                                                  Icon(
                                                                    Icons.date_range,
                                                                    size: 18.0,
                                                                    //color: Colors.teal,
                                                                  ),

                                                                  SizedBox(width: 5,),

                                                                  Text(
                                                                    "${birthDate.toLocal()}".split(' ')[0],
                                                                    style: TextStyle(
                                                                      fontFamily: "FredokaOne",
                                                                      //fontWeight: FontWeight.normal,
                                                                      fontSize: queryData.size.width * 0.035,
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                          )
                                                        ],
                                                      ),

                                                    ],
                                                  ),

                                                ),
                                              ),

                                            ]
                                        ),

                                        TextFormField
                                          (
                                          validator: (value) {
                                            if (value.isEmpty) {
                                              return '*required';
                                            }
                                            return null;
                                          },
                                          decoration: InputDecoration
                                            (
                                            labelText: "Profession",
                                            hintText: "Profession",
                                            hintStyle: TextStyle(
                                                fontFamily: "FredokaOne",
                                                //fontWeight: FontWeight.normal,
                                                fontSize: queryData.size.width * 0.035
                                            ),
                                            labelStyle: TextStyle(
                                              fontFamily: "FredokaOne",
                                              //fontWeight: FontWeight.normal,
                                              color: Colors.blueGrey,
                                              fontSize: queryData.size.width * 0.05,
                                            ),
                                          ),
                                        ),

                                        SizedBox(height: 15,),

                                        Row(
                                          children: <Widget>[
                                            Text(
                                              "Nationality : ",
                                              style: TextStyle(
                                                color: Colors.blueGrey,
                                                fontFamily: "FredokaOne",
                                                //fontWeight: FontWeight.normal,
                                                fontSize: queryData.size.width * 0.05,
                                              ),
                                            ),

                                           SizedBox(width: 40,),

                                           DropdownButton<String>(
                                             elevation: 10,
                                             iconSize: 35,
                                             value: nationalityValue1,
                                             onChanged: (String newValue) {
                                               setState(() {
                                                 nationalityValue1 = newValue;
                                               });
                                             },

                                             items: <String>['Select', 'America', 'Brazil', 'Canada', 'India', 'Mongalia', 'Pakistan', 'Turkey', 'UAE', 'Taiwaan', 'Iran', 'Iraq', 'UK', 'USA', 'China', 'Russia', 'Germany', 'Other']
                                               //'Select', 'America', 'Brazil', 'Canada', 'India', 'Mongalia', 'Pakistan', 'Turkey', 'UAE', 'Taiwaan', 'Iran', 'Iraq', 'UK', 'USA', 'China', 'Russia', 'Germany', 'Other']
                                             .map<DropdownMenuItem<String>>((String value) {
                                               return DropdownMenuItem<String>(
                                                 value: value,
                                                 child: Text(
                                                    value,
                                                    style: TextStyle(
                                                      fontFamily: "FredokaOne",
                                                      //color: Colors.blueGrey,
                                                      //fontWeight: FontWeight.normal,
                                                      fontSize: queryData.size.width * 0.045,
                                                    ),
                                                 )
                                               );
                                             }).toList(),
                                           ),

                                          ],
                                        ),

                                        TextFormField
                                          (
                                          validator: (value) {
                                            if (value.isEmpty) {
                                              return '*required';
                                            }
                                            return null;
                                          },
                                          decoration: InputDecoration
                                            (
                                            labelText: "Passport Number",
                                            hintText: "Passport Number",
                                            hintStyle: TextStyle(
                                                fontFamily: "FredokaOne",
                                                //fontWeight: FontWeight.normal,
                                                fontSize: queryData.size.width * 0.035
                                            ),
                                            labelStyle: TextStyle(
                                              fontFamily: "FredokaOne",
                                              //fontWeight: FontWeight.normal,
                                              color: Colors.blueGrey,
                                              fontSize: queryData.size.width * 0.05,
                                            ),
                                          ),
                                        ),

                                        SizedBox(height: 20,),

                                        Row(
                                            children: <Widget>[
                                              Text(
                                                "Expiry Date : ",
                                                textAlign: TextAlign.left,
                                                style: TextStyle(
                                                  color: Colors.blueGrey,
                                                  fontFamily: "FredokaOne",
                                                  //fontWeight: FontWeight.normal,
                                                  fontSize: queryData.size.width * 0.05,
                                                ),
                                              ),

                                              SizedBox(width: 10,),


                                        TextFormField
                                          (
                                          validator: (value) {
                                            if (value.isEmpty) {
                                              return '*required';
                                            }
                                            return null;
                                          },
                                          decoration: InputDecoration
                                            (
                                            labelText: 'Email Address',
                                            hintText: 'Email Address',
                                            hintStyle: TextStyle(
                                                fontFamily: "FredokaOne",
                                                //fontWeight: FontWeight.normal,
                                                fontSize: queryData.size.width * 0.035
                                            ),
                                            labelStyle: TextStyle(
                                              fontFamily: "FredokaOne",
                                              //fontWeight: FontWeight.normal,
                                              color: Colors.blueGrey,
                                              fontSize: queryData.size.width * 0.05,
                                            ),
                                          ),
                                          keyboardType: TextInputType.emailAddress,
                                        ),
                           
                                    SizedBox(height: 30),

                                    BookButton(
                                      onPressed: () => onBookPressed(context),
                                      child: Text("Submit",
                                          style: TextStyle(
                                              fontFamily: "FredokaOne",
                                              fontSize: queryData.size.width * 0.05,
                                              color: Colors.white
                                          )
                                      ),
                                    ),

                                    SizedBox(height: 15,),

                                  ],
                                ),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            ],
          )),
    );
  }
}

0 ответов

Другие вопросы по тегам