main.dart
import 'package:flutter/material.dart';
void main() {runApp(const MyApp());}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.pink),
home: const MyHomePage()
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Flutter - ElevatedButton onPressed")
),
body: bodyContent()
);
}
bodyContent() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Counter $_counter",style:
const TextStyle(fontSize: 28)
),
ElevatedButton(
onPressed: () {
setState(() {
_counter++;
});
},
child: const Text("Increment")
)
],
),
);
}
}
More flutter tutorials
- flutter – Full screen display
- flutter – Container content alignment
- flutter – Container padding and margin
- flutter – Text decoration style
- flutter – How to change Text underline color
- flutter – How to draw a line through the Text
- flutter – How to set Text line height
- flutter – How to overline Text
- flutter – How to draw Text outline
- flutter – How to set Text background color
- flutter – How to set Text word spacing
- flutter – Text overflow ellipsis
- flutter – Text uppercase
- flutter – Text capitalize first letter
- flutter – How to add padding to ElevatedButton