Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 2018 The Flutter team. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:http/http.dart' as http;
- import 'dart:convert' show jsonEncode;
- void main() => runApp(MyApp());
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => new _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- String _number = '';
- String _comment = '';
- String _question1 = 'true';
- String _question2 = 'true';
- String _question3 = 'true';
- String _question4 = 'true';
- void _setQuestion1(String value) => setState(() => _question1 = value);
- void _setQuestion2(String value) => setState(() => _question2 = value);
- void _setQuestion3(String value) => setState(() => _question3 = value);
- void _setQuestion4(String value) => setState(() => _question4 = value);
- final _formKey = GlobalKey<FormState>();
- Future<http.Response> sendRequest() {
- return http.post(
- 'https://web.kern-info.eu/test.cgi',
- headers: <String, String>{
- 'Content-Type': 'application/json; charset=UTF-8',
- },
- body: jsonEncode(<String, String>{
- 'number': _number,
- 'question1': _question1,
- 'question2': _question2,
- 'question3': _question3,
- 'question4': _question4,
- 'comment': _comment,
- }),
- );
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: new Scaffold(
- resizeToAvoidBottomInset: false, // set it to false
- appBar: AppBar(
- title: new Text('Survey'),
- centerTitle: true,
- backgroundColor: Colors.blue,
- ),
- body: new Form (
- key: _formKey,
- child: new Column(
- children: <Widget>[
- new TextField(
- decoration: new InputDecoration(labelText: "Enter number"),
- keyboardType: TextInputType.number,
- inputFormatters: <TextInputFormatter>[
- WhitelistingTextInputFormatter.digitsOnly
- ], // Only numbers can be entered
- onChanged: (value) { _number = value; },
- ),
- new Text('Question 1',
- style: new TextStyle(fontWeight: FontWeight.bold)),
- new Row(mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Radio(value: "true",
- groupValue: _question1,
- onChanged: _setQuestion1),
- new Text('Yes'),
- new Radio(value: "false",
- groupValue: _question1,
- onChanged: _setQuestion1),
- new Text('No'),
- ]
- ),
- new Text('Question 2',
- style: new TextStyle(fontWeight: FontWeight.bold)),
- new Row(mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Radio(value: 'true',
- groupValue: _question2,
- onChanged: _setQuestion2),
- new Text('Yes'),
- new Radio(value: 'false',
- groupValue: _question2,
- onChanged: _setQuestion2),
- new Text('No'),
- ]
- ),
- new Text('Question 3',
- style: new TextStyle(fontWeight: FontWeight.bold)),
- new Row(mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Radio(value: 'true',
- groupValue: _question3,
- onChanged: _setQuestion3),
- new Text('Yes'),
- new Radio(value: 'false',
- groupValue: _question3,
- onChanged: _setQuestion3),
- new Text('No'),
- ]
- ),
- new Text('Question 4',
- style: new TextStyle(fontWeight: FontWeight.bold)),
- new Row(mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Radio(value: 'true',
- groupValue: _question4,
- onChanged: _setQuestion4),
- new Text('Yes'),
- new Radio(value: 'false',
- groupValue: _question4,
- onChanged: _setQuestion4),
- new Text('No'),
- ]
- ),
- new Text('Free Comment',
- style: new TextStyle(fontWeight: FontWeight.bold)),
- new TextField(
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- labelText: 'Insert Comment',
- ),
- onChanged: (value) { _comment = value; },
- ),
- new Padding(
- padding: const EdgeInsets.symmetric(vertical: 16.0),
- child: new RaisedButton(
- onPressed: () {
- sendRequest();
- },
- child: Text('Submit'),
- ),
- ),
- ],
- )
- )
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement