Skip to content

Instantly share code, notes, and snippets.

@nkenna
Last active August 13, 2018 04:58
Show Gist options
  • Save nkenna/bc76e68099086a4119f840dc5a3497ed to your computer and use it in GitHub Desktop.
Save nkenna/bc76e68099086a4119f840dc5a3497ed to your computer and use it in GitHub Desktop.
include flat button
import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Blink LED',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Blink LED Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
double _sliderValue = 0.0;
String _status = "";
String _btnText = "LED-";
String url = 'http://192.168.4.1:80/steinacoz';
var response;
//function to make http requests
Future<String> ledRequest() async {
response = await http.get(url + '/led', headers: {"Accept": "plain/text"});
setState(() {
_status = response.body;
print(response.body);
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//create a text
new Text(
'My LED ',
style: Theme.of(context).textTheme.display1,
),
//create a raised button
new RaisedButton(
onPressed: ledRequest,
textColor: Colors.white,
disabledColor: Colors.black12,
disabledTextColor: Colors.brown,
splashColor: Colors.redAccent,
elevation: 2.0,
highlightElevation: 8.0,
animationDuration: kThemeChangeDuration,
child: new Text(_btnText + _status),
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment