Skip to content

Instantly share code, notes, and snippets.

@vladnicula
Created May 29, 2021 08:39
Show Gist options
  • Save vladnicula/966a53a958eb3bbcf10934aed8b5882f to your computer and use it in GitHub Desktop.
Save vladnicula/966a53a958eb3bbcf10934aed8b5882f to your computer and use it in GitHub Desktop.
Hello Flutter 06
import 'package:flutter/material.dart';
class MyHelloWorld extends StatefulWidget {
const MyHelloWorld({Key? key}) : super(key: key);
@override
MyHelloWorldState createState() => MyHelloWorldState();
}
class MyHelloWorldState extends State<MyHelloWorld> {
String message = "Hello World";
@override
build (BuildContext context) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(message),
TextButton(
onPressed: () {
setState(() {
if ( message == "Hello World" ) {
message = "Goodbye!";
} else {
message = "Hello World";
}
});
},
child: Text("Click me")
)
]
)
);
}
}
void main() {
runApp(
MaterialApp(
title: 'Hello From Flutter', // used by the OS task switcher
home: SafeArea(
child: Scaffold(
body: MyHelloWorld()
),
),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment