Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:http/http.dart' as http;
- class Home extends StatefulWidget {
- @override
- _HomeState createState() => _HomeState();
- }
- class _HomeState extends State<Home> {
- String nis, nama, status;
- final _key = new GlobalKey<FormState>();
- _check() {
- final form = _key.currentState;
- if (form.validate()) {
- form.save();
- _submit();
- }
- }
- _submit() async {
- var urlPostman =
- "https://script.google.com/macros/s/AKfycbyZMw-4aNli_vfIucxNxAZvIfWOtWlQEBST8EtDh4zGcDnEHCA7/exec?action=insert&tableName=presensi&nis=1&nama=as&status=333";
- var url =
- 'http://script.google.com/macros/s/AKfycbyZMw-4aNli_vfIucxNxAZvIfWOtWlQEBST8EtDh4zGcDnEHCA7';
- var queryParameters = {
- 'action': 'insert',
- 'tableName': 'presensi',
- 'nis': nis,
- 'nama': nama,
- 'status': status
- };
- var uri = Uri.https(url, '/exec?', queryParameters);
- var response = await http.post(uri);
- print(response.body.toString());
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(),
- body: Form(
- key: _key,
- child: Container(
- padding: EdgeInsets.all(16.0),
- child: ListView(
- children: <Widget>[
- EditText(
- errorLabel: 'Please fill your fullname',
- label: 'NIS',
- onSaved: (a) => nis = a,
- ),
- SizedBox(
- height: 20.0,
- ),
- EditText(
- errorLabel: 'Please fill your nama address',
- label: 'Nama',
- onSaved: (a) => nama = a,
- ),
- SizedBox(
- height: 20.0,
- ),
- EditText(
- errorLabel: 'Please fill your status number',
- label: 'Status',
- onSaved: (a) => status = a,
- ),
- SizedBox(
- height: 20.0,
- ),
- SizedBox(
- height: 20.0,
- ),
- CustomButton(
- label: 'Submit',
- onPressed: () {
- _check();
- },
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
- class EditText extends StatelessWidget {
- final String label;
- final String errorLabel;
- final FormFieldSetter onSaved;
- EditText({this.onSaved, this.errorLabel, this.label});
- @override
- Widget build(BuildContext context) {
- return TextFormField(
- onSaved: onSaved,
- validator: (e) {
- if (e.isEmpty) {
- return errorLabel;
- }
- },
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- hintText: label,
- labelText: label,
- border:
- OutlineInputBorder(borderRadius: BorderRadius.circular(30.0))),
- );
- }
- }
- class CustomButton extends StatelessWidget {
- final VoidCallback onPressed;
- final String label;
- CustomButton({this.onPressed, this.label});
- @override
- Widget build(BuildContext context) {
- return Material(
- color: Colors.blue,
- borderRadius: BorderRadius.circular(30.0),
- child: MaterialButton(
- onPressed: onPressed,
- child: Text(
- label,
- style: TextStyle(color: Colors.white),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement