Skip to content

Instantly share code, notes, and snippets.

@marcel-ploch
Last active November 28, 2022 07:37
Show Gist options
  • Save marcel-ploch/39e6495b207c8e96bcc78269c3ff9d31 to your computer and use it in GitHub Desktop.
Save marcel-ploch/39e6495b207c8e96bcc78269c3ff9d31 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
/// Erstellen der Liste alle Auswahlmöglichkeiten für das DropDown Menü
final List<String> choices = const ['Add', 'Remove'];
const MyHomePage({super.key, required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
/// Führendes Aktions Icon
leading: IconButton(icon: Icon(Icons.adb), onPressed: () {}),
/// Die ausführenden Aktionen
actions: [
/// Auswählen für das 3 Dot Menü mit Dropdown
PopupMenuButton<String>(
onSelected: (choosen) {
var text = choosen ?? 'Empty';
var snackBar = SnackBar(
content: Text('Sie haben $text gewählt'),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
/// Erstellen der Einträge über eine Map mit Popup Menu Items
itemBuilder: (BuildContext context) {
return choices.map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
)
],
title: Text(title),
),
body: const Center(child: Text("Einfach einen Text darstellen")),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment