Skip to content

Instantly share code, notes, and snippets.

@mphuie
Created August 2, 2018 17:29
Show Gist options
  • Save mphuie/e3360efa4aece3c5ddeb15d3317771cc to your computer and use it in GitHub Desktop.
Save mphuie/e3360efa4aece3c5ddeb15d3317771cc to your computer and use it in GitHub Desktop.
Hello world in flutter
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home 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> {
String displayname='Stranger';
String inputname='';
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text(widget.title),
),
body:Container(
margin: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: 'Enter your name',
),
onChanged: (newValue) {
inputname=newValue;
},
),
Divider(),
RaisedButton(
child: Icon(Icons.account_circle),
onPressed: (){setState(() {
displayname=inputname;
});},
),
Divider(),
Text("Hello $displayname, how are you?")
],
),
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment