// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/material.dart'; import 'popup_constants.dart'; export 'popup_constants.dart'; /// A page with a popup menu, a dropdown menu, and a modal alert. class PopupControlsPage extends StatefulWidget { const PopupControlsPage({super.key}); @override State createState() => _PopupControlsPageState(); } class _PopupControlsPageState extends State { final Key popupKey = const ValueKey(popupKeyValue); final Key dropdownKey = const ValueKey(dropdownKeyValue); final Key alertKey = const ValueKey(alertKeyValue); String popupValue = popupItems.first; String dropdownValue = popupItems.first; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(leading: const BackButton(key: ValueKey('back'))), body: SafeArea( child: Center( child: Row( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ PopupMenuButton( key: const ValueKey(popupButtonKeyValue), icon: const Icon(Icons.arrow_drop_down), itemBuilder: (BuildContext context) { return popupItems.map>((String item) { return PopupMenuItem( key: ValueKey('$popupKeyValue.$item'), value: item, child: Text(item), ); }).toList(); }, onSelected: (String value) { popupValue = value; }, ), DropdownButton( key: const ValueKey(dropdownButtonKeyValue), value: dropdownValue, items: popupItems.map>((String item) { return DropdownMenuItem( key: ValueKey('$dropdownKeyValue.$item'), value: item, child: Text(item), ); }).toList(), onChanged: (String? value) { setState(() { dropdownValue = value!; }); }, ), MaterialButton( key: const ValueKey(alertButtonKeyValue), child: const Text('Alert'), onPressed: () { showDialog( context: context, barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( key: const ValueKey(alertKeyValue), title: const Text( 'Title text', key: ValueKey('$alertKeyValue.Title'), ), content: const SingleChildScrollView( child: ListBody( children: [ Text( 'Body text line 1.', key: ValueKey('$alertKeyValue.Body1'), ), Text( 'Body text line 2.', key: ValueKey('$alertKeyValue.Body2'), ), ], ), ), actions: [ TextButton( child: const Text('OK', key: ValueKey('$alertKeyValue.OK')), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }, ), ], ), ), ), ); } }