Advertisement
Guest User

flutter

a guest
Jul 1st, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Copyright 2018 The Flutter team. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter/services.dart';
  7. import 'package:http/http.dart' as http;
  8. import 'dart:convert' show jsonEncode;
  9.  
  10. void main() => runApp(MyApp());
  11.  
  12. class MyApp extends StatefulWidget {
  13.   @override
  14.   _MyAppState createState() => new _MyAppState();
  15. }
  16.  
  17. class _MyAppState extends State<MyApp> {
  18.  
  19.  
  20.   String _number = '';
  21.   String _comment = '';
  22.   String _question1 = 'true';
  23.   String _question2 = 'true';
  24.   String _question3 = 'true';
  25.   String _question4 = 'true';
  26.  
  27.   void _setQuestion1(String value) => setState(() => _question1 = value);
  28.   void _setQuestion2(String value) => setState(() => _question2 = value);
  29.   void _setQuestion3(String value) => setState(() => _question3 = value);
  30.   void _setQuestion4(String value) => setState(() => _question4 = value);
  31.   final _formKey = GlobalKey<FormState>();
  32.  
  33.   Future<http.Response> sendRequest() {
  34.     return http.post(
  35.       'https://web.kern-info.eu/test.cgi',
  36.       headers: <String, String>{
  37.         'Content-Type': 'application/json; charset=UTF-8',
  38.       },
  39.       body: jsonEncode(<String, String>{
  40.         'number': _number,
  41.         'question1': _question1,
  42.         'question2': _question2,
  43.         'question3': _question3,
  44.         'question4': _question4,
  45.         'comment': _comment,
  46.  
  47.       }),
  48.     );
  49.   }
  50.  
  51.   @override
  52.   Widget build(BuildContext context) {
  53.     return MaterialApp(
  54.         home: new Scaffold(
  55.             resizeToAvoidBottomInset: false, // set it to false
  56.             appBar: AppBar(
  57.               title: new Text('Survey'),
  58.               centerTitle: true,
  59.               backgroundColor: Colors.blue,
  60.             ),
  61.             body: new Form (
  62.               key: _formKey,
  63.                 child: new Column(
  64.                   children: <Widget>[
  65.                     new TextField(
  66.                       decoration: new InputDecoration(labelText: "Enter number"),
  67.                       keyboardType: TextInputType.number,
  68.                       inputFormatters: <TextInputFormatter>[
  69.                         WhitelistingTextInputFormatter.digitsOnly
  70.                       ], // Only numbers can be entered
  71.                       onChanged: (value) { _number = value; },
  72.                     ),
  73.                     new Text('Question 1',
  74.                         style: new TextStyle(fontWeight: FontWeight.bold)),
  75.                     new Row(mainAxisAlignment: MainAxisAlignment.center,
  76.                         children: <Widget>[
  77.                           new Radio(value: "true",
  78.                               groupValue: _question1,
  79.                               onChanged: _setQuestion1),
  80.                           new Text('Yes'),
  81.                           new Radio(value: "false",
  82.                               groupValue: _question1,
  83.                               onChanged: _setQuestion1),
  84.                           new Text('No'),
  85.                         ]
  86.                     ),
  87.                     new Text('Question 2',
  88.                         style: new TextStyle(fontWeight: FontWeight.bold)),
  89.                     new Row(mainAxisAlignment: MainAxisAlignment.center,
  90.                         children: <Widget>[
  91.                           new Radio(value: 'true',
  92.                               groupValue: _question2,
  93.                               onChanged: _setQuestion2),
  94.                           new Text('Yes'),
  95.                           new Radio(value: 'false',
  96.                               groupValue: _question2,
  97.                               onChanged: _setQuestion2),
  98.                           new Text('No'),
  99.                         ]
  100.                     ),
  101.                     new Text('Question 3',
  102.                         style: new TextStyle(fontWeight: FontWeight.bold)),
  103.                     new Row(mainAxisAlignment: MainAxisAlignment.center,
  104.                         children: <Widget>[
  105.                           new Radio(value: 'true',
  106.                               groupValue: _question3,
  107.                               onChanged: _setQuestion3),
  108.                           new Text('Yes'),
  109.                           new Radio(value: 'false',
  110.                               groupValue: _question3,
  111.                               onChanged: _setQuestion3),
  112.                           new Text('No'),
  113.                         ]
  114.                     ),
  115.                     new Text('Question 4',
  116.                         style: new TextStyle(fontWeight: FontWeight.bold)),
  117.                     new Row(mainAxisAlignment: MainAxisAlignment.center,
  118.                         children: <Widget>[
  119.                           new Radio(value: 'true',
  120.                               groupValue: _question4,
  121.                               onChanged: _setQuestion4),
  122.                           new Text('Yes'),
  123.                           new Radio(value: 'false',
  124.                               groupValue: _question4,
  125.                               onChanged: _setQuestion4),
  126.                           new Text('No'),
  127.                         ]
  128.                     ),
  129.                     new Text('Free Comment',
  130.                         style: new TextStyle(fontWeight: FontWeight.bold)),
  131.                     new TextField(
  132.                         decoration: InputDecoration(
  133.                             border: OutlineInputBorder(),
  134.                             labelText: 'Insert Comment',
  135.                         ),
  136.                         onChanged: (value) { _comment = value; },
  137.                     ),
  138.                     new Padding(
  139.                       padding: const EdgeInsets.symmetric(vertical: 16.0),
  140.                       child: new RaisedButton(
  141.                         onPressed: () {
  142.                           sendRequest();
  143.                         },
  144.                         child: Text('Submit'),
  145.                       ),
  146.                     ),
  147.                   ],
  148.                 )
  149.             )
  150.             )
  151.         );
  152.   }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement