Created
April 20, 2020 22:49
-
-
Save rayliverified/7b5710b344431457753253625a596158 to your computer and use it in GitHub Desktop.
Flutter.dev Example 3 - Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
class Counter extends StatefulWidget { | |
_CounterState createState() => _CounterState(); | |
} | |
class _CounterState extends State<Counter> { | |
double val; | |
void initState() { | |
super.initState(); | |
val = 0; | |
} | |
void change() { | |
setState(() { | |
val += 1; | |
}); | |
} | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: Column( | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Center(child: Text('$val'))), | |
MaterialButton( | |
color: Theme.of(context).primaryColor, | |
child: Text( | |
'Add', | |
style: TextStyle(color: Colors.white), | |
), | |
onPressed: () => change(), | |
), | |
], | |
), | |
), | |
); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Center( | |
child: Container( | |
child: Counter(), | |
), | |
), | |
); | |
} | |
} | |
Future<void> main() async { | |
runApp(MyApp()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment