Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:http/http.dart' as http;
  4.  
  5. class Home extends StatefulWidget {
  6. @override
  7. _HomeState createState() => _HomeState();
  8. }
  9.  
  10. class _HomeState extends State<Home> {
  11. String nis, nama, status;
  12. final _key = new GlobalKey<FormState>();
  13.  
  14. _check() {
  15. final form = _key.currentState;
  16. if (form.validate()) {
  17. form.save();
  18. _submit();
  19. }
  20. }
  21.  
  22. _submit() async {
  23. var urlPostman =
  24. "https://script.google.com/macros/s/AKfycbyZMw-4aNli_vfIucxNxAZvIfWOtWlQEBST8EtDh4zGcDnEHCA7/exec?action=insert&tableName=presensi&nis=1&nama=as&status=333";
  25.  
  26. var url =
  27. 'http://script.google.com/macros/s/AKfycbyZMw-4aNli_vfIucxNxAZvIfWOtWlQEBST8EtDh4zGcDnEHCA7';
  28.  
  29. var queryParameters = {
  30. 'action': 'insert',
  31. 'tableName': 'presensi',
  32. 'nis': nis,
  33. 'nama': nama,
  34. 'status': status
  35. };
  36.  
  37. var uri = Uri.https(url, '/exec?', queryParameters);
  38. var response = await http.post(uri);
  39. print(response.body.toString());
  40. }
  41.  
  42. @override
  43. Widget build(BuildContext context) {
  44. return Scaffold(
  45. appBar: AppBar(),
  46. body: Form(
  47. key: _key,
  48. child: Container(
  49. padding: EdgeInsets.all(16.0),
  50. child: ListView(
  51. children: <Widget>[
  52. EditText(
  53. errorLabel: 'Please fill your fullname',
  54. label: 'NIS',
  55. onSaved: (a) => nis = a,
  56. ),
  57. SizedBox(
  58. height: 20.0,
  59. ),
  60. EditText(
  61. errorLabel: 'Please fill your nama address',
  62. label: 'Nama',
  63. onSaved: (a) => nama = a,
  64. ),
  65. SizedBox(
  66. height: 20.0,
  67. ),
  68. EditText(
  69. errorLabel: 'Please fill your status number',
  70. label: 'Status',
  71. onSaved: (a) => status = a,
  72. ),
  73. SizedBox(
  74. height: 20.0,
  75. ),
  76. SizedBox(
  77. height: 20.0,
  78. ),
  79. CustomButton(
  80. label: 'Submit',
  81. onPressed: () {
  82. _check();
  83. },
  84. ),
  85. ],
  86. ),
  87. ),
  88. ),
  89. );
  90. }
  91. }
  92.  
  93. class EditText extends StatelessWidget {
  94. final String label;
  95. final String errorLabel;
  96. final FormFieldSetter onSaved;
  97. EditText({this.onSaved, this.errorLabel, this.label});
  98. @override
  99. Widget build(BuildContext context) {
  100. return TextFormField(
  101. onSaved: onSaved,
  102. validator: (e) {
  103. if (e.isEmpty) {
  104. return errorLabel;
  105. }
  106. },
  107. keyboardType: TextInputType.text,
  108. decoration: InputDecoration(
  109. hintText: label,
  110. labelText: label,
  111. border:
  112. OutlineInputBorder(borderRadius: BorderRadius.circular(30.0))),
  113. );
  114. }
  115. }
  116.  
  117. class CustomButton extends StatelessWidget {
  118. final VoidCallback onPressed;
  119. final String label;
  120. CustomButton({this.onPressed, this.label});
  121. @override
  122. Widget build(BuildContext context) {
  123. return Material(
  124. color: Colors.blue,
  125. borderRadius: BorderRadius.circular(30.0),
  126. child: MaterialButton(
  127. onPressed: onPressed,
  128. child: Text(
  129. label,
  130. style: TextStyle(color: Colors.white),
  131. ),
  132. ),
  133. );
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement