cpd_2023_hello/lib/main.dart

67 lines
1.4 KiB
Dart
Raw Normal View History

2023-03-31 17:02:41 +02:00
import 'package:flutter/material.dart';
void main() {
2023-03-31 17:04:59 +02:00
runApp(const DemoApp());
2023-03-31 17:02:41 +02:00
}
2023-03-31 17:04:59 +02:00
class DemoApp extends StatelessWidget {
const DemoApp({super.key});
2023-03-31 17:02:41 +02:00
@override
Widget build(BuildContext context) {
return MaterialApp(
2023-03-31 17:04:59 +02:00
title: 'Flutter Demo for CPD',
2023-03-31 17:02:41 +02:00
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
2023-03-31 17:04:59 +02:00
),
2023-03-31 17:02:41 +02:00
);
}
}