Advertisement
Guest User

main.dart

a guest
May 6th, 2018
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.86 KB | None | 0 0
  1. import 'dart:async';
  2. import 'dart:convert' show utf8, json;
  3. import 'dart:io';
  4. import 'package:flutter/material.dart';
  5. import 'package:http/http.dart' as http;
  6.  
  7. void main() => runApp(new MaterialApp(home: new MTextInput()));
  8.  
  9. class MTextInput extends StatefulWidget {
  10.   @override
  11.   MTextInputState createState() => new MTextInputState();
  12. }
  13.  
  14. Future<Map<String, dynamic>> getInstitutes(HttpClient client) async {
  15.   final String url = "https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute";
  16.  
  17.   final HttpClientRequest request = await client.getUrl(Uri.parse(url))
  18.     ..headers.add("Accept", "application/json")
  19.     ..headers.add("HOST", "kretaglobalmobileapi.ekreta.hu")
  20.     ..headers.add("apiKey", "7856d350-1fda-45f5-822d-e1a2f3f1acf0")
  21.     ..headers.add("Connection", "keep-alive");
  22.  
  23.   final HttpClientResponse response = await request.close();
  24.   print(json.decode(await response.join()));
  25.  
  26.   return json.decode(await response.transform(utf8.decoder).join());
  27. }
  28.  
  29.  
  30. Future<http.Response> fetchPost() {
  31.   return http.get(
  32.     "https://kretaglobalmobileapi.ekreta.hu/api/v1/Institute",
  33.     // Send authorization headers to your backend
  34.       headers : {"apiKey": "7856d350-1fda-45f5-822d-e1a2f3f1acf0", "Connection": "keep-alive",
  35.         "Accept": "application/json", "HOST": "kretaglobalmobileapi.ekreta.hu"}
  36.   );
  37. }
  38.  
  39.  
  40.  
  41. void login() async {
  42.  
  43.   print((await fetchPost()).body);
  44.   print((await fetchPost()).body.length);
  45. }
  46.  
  47. class MTextInputState extends State<MTextInput> {
  48.   @override
  49.   Widget build(BuildContext context) {
  50.     return new Scaffold(
  51.         appBar: new AppBar(title: new Text("E-napló"),),
  52.         body: new Container(
  53.             child: new Center(
  54.               child: new IconButton(
  55.                   icon: new Icon(Icons.add),
  56.                   onPressed: login
  57.                   ),
  58.             )
  59.         )
  60.     );
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement