2024-04-09 21:15:28 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-04-09 21:39:59 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2024-04-09 21:15:28 +02:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Flutter Demo',
|
|
|
|
theme: ThemeData(
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
|
|
|
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
final String title;
|
|
|
|
|
2024-04-09 21:18:06 +02:00
|
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
|
2024-04-09 21:15:28 +02:00
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
|
|
int _counter = 0;
|
|
|
|
|
|
|
|
void _incrementCounter() {
|
|
|
|
setState(() {
|
|
|
|
_counter++;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-09 21:26:46 +02:00
|
|
|
void _decrementCounter() {
|
|
|
|
setState(() {
|
|
|
|
_counter--;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-09 21:15:28 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
title: Text(widget.title),
|
|
|
|
),
|
2024-04-09 21:39:59 +02:00
|
|
|
body: RawKeyboardListener(
|
|
|
|
focusNode: FocusNode(),
|
|
|
|
autofocus: true,
|
|
|
|
onKey: (RawKeyEvent event) {
|
|
|
|
if (event.isKeyPressed(LogicalKeyboardKey.keyD)) _decrementCounter();
|
|
|
|
if (event.isKeyPressed(LogicalKeyboardKey.keyI)) _incrementCounter();
|
|
|
|
},
|
|
|
|
child: 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,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-04-09 21:15:28 +02:00
|
|
|
),
|
|
|
|
),
|
2024-04-09 21:26:46 +02:00
|
|
|
floatingActionButton: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
2024-04-09 21:39:59 +02:00
|
|
|
padding: const EdgeInsets.only(left: 31),
|
2024-04-09 21:26:46 +02:00
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomLeft,
|
|
|
|
child: FloatingActionButton(
|
2024-04-09 21:43:15 +02:00
|
|
|
onPressed: _decrementCounter,
|
|
|
|
tooltip: 'Decrement',
|
|
|
|
child: const Icon(Icons.remove),
|
2024-04-09 21:26:46 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.bottomRight,
|
|
|
|
child: FloatingActionButton(
|
2024-04-09 21:43:15 +02:00
|
|
|
onPressed: _incrementCounter,
|
|
|
|
tooltip: 'Increment',
|
|
|
|
child: const Icon(Icons.add),
|
2024-04-09 21:26:46 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-04-09 21:18:06 +02:00
|
|
|
),
|
2024-04-09 21:15:28 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|