flutter/examples/widgets/http_post.dart
Adam Barth 870894fc68 Switch Material Design icons to using the iconfont
Rather than managing all the Material Design icons manually, we now
manage them using an icon font. The icon font contains glyphs for each
icon in an efficient vector format.

This patch updates the FLX tooling to include the MaterialIcons font and
updates the Icon widget to use the font instead of asset images.

Fixes #2313
Fixes #2218
Fixes #2009
Fixes #994
2016-03-02 09:32:02 -08:00

74 lines
1.6 KiB
Dart

// Copyright 2015, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:flutter/http.dart' as http;
import 'package:flutter/material.dart';
void main() {
runApp(
new MaterialApp(
title: "HTTP POST Example",
routes: {
'/': (RouteArguments args) => const PostDemo()
}
)
);
}
class PostDemo extends StatefulComponent {
const PostDemo();
PostDemoState createState() => new PostDemoState();
}
class PostDemoState extends State<PostDemo> {
String _response = null;
void initState() {
_refresh();
super.initState();
}
Future _refresh() async {
setState(() {
_response = null;
});
http.Response response = await http.post(
"http://httpbin.org/post",
body: '{"foo": "bar"}',
headers: { "Content-Type": "application/json", "baz": "qux" }
);
setState(() {
_response = response.body;
});
}
Widget build(BuildContext context) {
return new Scaffold(
toolBar: new ToolBar(
center: new Text("HTTP POST example")
),
body: new Material(
child: new Block(
children: <Widget>[
new Text(
"${_response ?? 'Loading...'}",
style: Typography.black.body1
)
]
)
),
floatingActionButton: new FloatingActionButton(
tooltip: 'Refresh',
child: new Icon(
icon: Icons.refresh
),
onPressed: _refresh
)
);
}
}