Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created September 29, 2019 07:07
Show Gist options
  • Save emisjerry/67ff01020645b15c48822af0385ef499 to your computer and use it in GitHub Desktop.
Save emisjerry/67ff01020645b15c48822af0385ef499 to your computer and use it in GitHub Desktop.
Flutter demo #3, simple samples.
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(new MyAppWidget());
class MyAppWidget extends StatefulWidget {
@override
_MyAppWidgetState createState() => _MyAppWidgetState();
}
class _MyAppWidgetState extends State<MyAppWidget> {
Color stringColor = Colors.red;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "My first Flutter App",
home: Scaffold(
appBar: AppBar(title: Text("My first Flutter App")),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
padding:
EdgeInsets.only(left: 20, right: 20, top: 40, bottom: 40),
color: stringColor,
child: Text("My first Flutter App",
style: TextStyle(color: Colors.white, fontSize: 30),
textDirection: TextDirection.ltr),
),
Padding(
padding: EdgeInsets.all(30),
),
RaisedButton(
onPressed: changeIt,
textColor: Colors.white,
color: Colors.blue,
child: Text("Change!"),
),
],
),
),
),
);
}
void changeIt() {
setState(() {
stringColor = Color.fromARGB(255, Random().nextInt(255),
Random().nextInt(255), Random().nextInt(255));
// stringColor = (stringColor == Colors.red) ? Colors.green : Colors.red;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment