Skip to content

Instantly share code, notes, and snippets.

@Blasanka
Created March 22, 2018 12:21
Show Gist options
  • Save Blasanka/42a1d68d6868da0d02bfa8c5cb4f452c to your computer and use it in GitHub Desktop.
Save Blasanka/42a1d68d6868da0d02bfa8c5cb4f452c to your computer and use it in GitHub Desktop.
This code created for slcoder's tutorial 'Different between StatelessWidget and StatefulWidget'. you can find the gist for StatelessWidget here: https://gist.github.com/Blasanka/e637bf5a519c02a4e2b84729b27540bf.
// this example is created by slcoder to explain statefulWidget in slcoder's tutorials.
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
int _count = 0;
class MyApp extends StatefulWidget {
_HomePage createState() => new _HomePage();
}
class _HomePage extends State<MyApp> {
void _increase() {
setState(() => _count++);
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Hello World App',
home: new Scaffold(
appBar: new AppBar(
title: new Text('StatelessWidget'),
backgroundColor: new Color(0xFF8B1122),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
"Up Votes : $_count",
style: new TextStyle(
fontSize: 25.0,
color: new Color(0xFF8B1122),
fontWeight: FontWeight.w600,
),
),
new RaisedButton(
child: new Text('Vote up', style: new TextStyle(fontSize: 20.0,)),
color: new Color(0xFF8B1122),
textColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 40.0),
elevation: 10.0,
splashColor: Colors.white70,
onPressed: _increase,
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment